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 get_template(apiclient, zoneid, ostype, services=None, templatefilter='featured', templatetype='BUILTIN'): "Returns a template" cmd = listOsTypes.listOsTypesCmd() cmd.description = ostype ostypes = apiclient.listOsTypes(cmd) if isinstance(ostypes, list): ostypeid = ostypes[0].id else: raise Exception( "Failed to find OS type with description: %s" % ostype) cmd = listTemplates.listTemplatesCmd() cmd.templatefilter = templatefilter cmd.zoneid = zoneid if services: if "template" in services: cmd.id = services["template"] list_templates = apiclient.listTemplates(cmd) if isinstance(list_templates, list): assert len(list_templates) > 0, "received empty response on template of type %s"%ostype for template in list_templates: if template.ostypeid == ostypeid and template.isready and template.templatetype == templatetype: return template raise Exception("Exception: Failed to find template of type %s with OSTypeID and which is in " "ready state: %s" %(templatetype, ostypeid)) return
def list_os_types(apiclient, **kwargs): """List all os types matching criteria""" cmd = listOsTypes.listOsTypesCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] if "account" in kwargs.keys() and "domainid" in kwargs.keys(): cmd.listall = True return apiclient.listOsTypes(cmd)
def list_os_types(apiclient, **kwargs): """List all os types matching criteria""" cmd = listOsTypes.listOsTypesCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] if 'account' in kwargs.keys() and 'domainid' in kwargs.keys(): cmd.listall = True return (apiclient.listOsTypes(cmd))
def create(apiclient, services, volumeid=None, account=None, domainid=None, projectid=None): cmd = createTemplate.createTemplateCmd() cmd.displaytext = services["displaytext"] cmd.name = services["name"] if "ostypeid" in services: cmd.ostypeid = services["ostypeid"] elif "ostype" in services: 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 = services[ "isfeatured"] if "isfeatured" in services else False cmd.ispublic = services["ispublic"] if "ispublic" in services else False cmd.isextractable = services[ "isextractable"] if "isextractable" in services else False cmd.passwordenabled = services[ "passwordenabled"] if "passwordenabled" in services else False if volumeid: cmd.volumeid = volumeid if account: cmd.account = account if domainid: cmd.domainid = domainid if projectid: cmd.projectid = projectid return apiclient.createTemplate(cmd)
def create(apiclient, services, volumeid=None, account=None, domainid=None, projectid=None): cmd = createTemplate.createTemplateCmd() cmd.displaytext = services["displaytext"] cmd.name = services["name"] if "ostypeid" in services: cmd.ostypeid = services["ostypeid"] elif "ostype" in services: 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 = services[ "isfeatured"] if "isfeatured" in services else False cmd.ispublic = services[ "ispublic"] if "ispublic" in services else False cmd.isextractable = services[ "isextractable"] if "isextractable" in services else False cmd.passwordenabled = services[ "passwordenabled"] if "passwordenabled" in services else False if volumeid: cmd.volumeid = volumeid if account: cmd.account = account if domainid: cmd.domainid = domainid if projectid: cmd.projectid = projectid return apiclient.createTemplate(cmd)
def get_template(apiclient, zoneid, ostype, services=None, templatefilter='featured', templatetype='BUILTIN'): "Returns a template" cmd = listOsTypes.listOsTypesCmd() cmd.description = ostype ostypes = apiclient.listOsTypes(cmd) if isinstance(ostypes, list): ostypeid = ostypes[0].id else: raise Exception("Failed to find OS type with description: %s" % ostype) cmd = listTemplates.listTemplatesCmd() cmd.templatefilter = templatefilter cmd.zoneid = zoneid if services: if "template" in services: cmd.id = services["template"] list_templates = apiclient.listTemplates(cmd) if isinstance(list_templates, list): assert len( list_templates ) > 0, "received empty response on template of type %s" % ostype for template in list_templates: if template.ostypeid == ostypeid and template.isready and template.templatetype == templatetype: return template raise Exception( "Exception: Failed to find template of type %s with OSTypeID and which is in " "ready state: %s" % (templatetype, ostypeid)) return
def create_Template_from_Snapshot(self, snapshot): try: self.debug("Creating template from snapshot: %s" % snapshot.name) cmd = createTemplate.createTemplateCmd() cmd.displaytext = self.services["template"]["displaytext"] cmd.name = "-".join([self.services["template"]["name"], random_gen()]) ncmd = listOsTypes.listOsTypesCmd() ncmd.description = self.services["template"]["ostype"] ostypes = self.apiclient.listOsTypes(ncmd) if not isinstance(ostypes, list): raise Exception( "Unable to find Ostype id with desc: %s" % self.services["template"]["ostype"]) cmd.ostypeid = ostypes[0].id cmd.snapshotid = snapshot.id return cmd except Exception as e: self.fail("Failed to create template from snapshot: %s - %s" % (snapshot.name, e))
def create_Template_from_Snapshot(self, snapshot): try: self.debug("Creating template from snapshot: %s" % snapshot.name) cmd = createTemplate.createTemplateCmd() cmd.displaytext = self.services["template"]["displaytext"] cmd.name = "-".join( [self.services["template"]["name"], random_gen()]) ncmd = listOsTypes.listOsTypesCmd() ncmd.description = self.services["template"]["ostype"] ostypes = self.apiclient.listOsTypes(ncmd) if not isinstance(ostypes, list): raise Exception("Unable to find Ostype id with desc: %s" % self.services["template"]["ostype"]) cmd.ostypeid = ostypes[0].id cmd.snapshotid = snapshot.id return cmd except Exception as e: self.fail("Failed to create template from snapshot: %s - %s" % (snapshot.name, e))
def getOsType(self, param): cmd = listOsTypes.listOsTypesCmd() cmd.description = param return self.apiclient.listOsTypes(cmd)[0].id
def list_os_types(apiclient, **kwargs): """List all os types matching criteria""" cmd = listOsTypes.listOsTypesCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.listOsTypes(cmd))
def getOsType(self, param): cmd = listOsTypes.listOsTypesCmd() cmd.description = param return self.apiclient.listOsTypes(cmd)[0].id
def list_os_types(apiclient, **kwargs): """List all os types matching criteria""" cmd = listOsTypes.listOsTypesCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] return (apiclient.listOsTypes(cmd))