def create_template_from_snapshot(self, apiclient, services, snapshotid=None, volumeid=None): """Create template from Volume""" # Create template from Virtual machine and Volume ID cmd = createTemplate.createTemplateCmd() cmd.displaytext = "StorPool_Template" cmd.name = "-".join(["StorPool-", random_gen()]) if "ostypeid" in services: cmd.ostypeid = services["ostypeid"] elif "ostype" in services: # Find OSTypeId from Os type sub_cmd = listOsTypes.listOsTypesCmd() sub_cmd.description = services["ostype"] ostypes = apiclient.listOsTypes(sub_cmd) if not isinstance(ostypes, list): raise Exception("Unable to find Ostype id with desc: %s" % services["ostype"]) cmd.ostypeid = ostypes[0].id else: raise Exception( "Unable to find Ostype is required for creating template") cmd.isfeatured = True cmd.ispublic = True cmd.isextractable = False if snapshotid: cmd.snapshotid = snapshotid if volumeid: cmd.volumeid = volumeid return Template(apiclient.createTemplate(cmd).__dict__)
def getKubernetesTemplate(cls, cks_templates=None): if cks_templates is None: cks_templates = cls.services["cks_templates"] hypervisor = cls.hypervisor.lower() if hypervisor not in cks_templates.keys(): cls.debug("Provided hypervisor has no CKS template") return FAILED, False cks_template = cks_templates[hypervisor] cmd = listTemplates.listTemplatesCmd() cmd.name = cks_template['name'] cmd.templatefilter = 'all' cmd.zoneid = cls.zone.id cmd.hypervisor = hypervisor templates = cls.apiclient.listTemplates(cmd) if validateList(templates)[0] != PASS: details = None if hypervisor in ["vmware"]: details = [{"keyboard": "us"}] template = Template.register(cls.apiclient, cks_template, zoneid=cls.zone.id, hypervisor=hypervisor.lower(), randomize_name=False, details=details) template.download(cls.apiclient) return template, False for template in templates: if template.isready and template.ispublic: return Template(template.__dict__), True return FAILED, False
print "zone name={}, id={}".format(zone.name, zone.id) if zone.allocationstate == 'Enabled': services = {} services["displaytext"] = "Debian" services["name"] = "deb" if options.upload_tmpl is not None: services["hypervisor"] = "KVM" services["format"] = "QCOW2" services["url"] = options.upload_tmpl if options.upload_iso is not None: services["url"] = options.upload_iso services["ostype"] = "Debian GNU/Linux 7(64-bit)" services["zoneid"] = zone.id tmp_dict = {} if options.upload_tmpl is not None: my_templ = Template(tmp_dict) if my_templ.register(apiClient, services) == FAILED: print "Uploading template failed" tc_run_logger.debug( "\n=== Uploading template failed ===") exit(1) if options.upload_iso is not None: my_templ = Iso(tmp_dict) if my_templ.create(apiClient, services) == FAILED: print "Uploading template failed" tc_run_logger.debug( "\n=== Uploading template failed ===") exit(1) else: print "Zone is not ready" else: