def register(cls, apiclient, services, zoneid=None, account=None, domainid=None): """Create template from URL""" #Create template from Virtual machine and Volume ID cmd = registerTemplate.registerTemplateCmd() cmd.displaytext = services["displaytext"] cmd.name = "-".join([services["name"], random_gen()]) cmd.format = services["format"] cmd.hypervisor = services["hypervisor"] cmd.ostypeid = services["ostypeid"] cmd.url = services["url"] if zoneid: cmd.zoneid = zoneid else: cmd.zoneid = services["zoneid"] 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 if account: cmd.account = account if domainid: cmd.domainid = domainid # Register Template template = apiclient.registerTemplate(cmd) if isinstance(template, list): return Template(template[0].__dict__)
def create_from_snapshot(cls, apiclient, snapshot, services, random_name=True): """Create Template from snapshot""" #Create template from Virtual machine and Snapshot ID cmd = createTemplate.createTemplateCmd() cmd.displaytext = services["displaytext"] cmd.name = "-".join([ services["name"], random_gen() ]) if random_name else services["name"] cmd.ostypeid = services["ostypeid"] cmd.snapshotid = snapshot.id return Template(apiclient.createTemplate(cmd).__dict__)
def create(cls, apiclient, services, name=None, networkdomain=None, parentdomainid=None): """Creates an domain""" cmd = createDomain.createDomainCmd() if name: cmd.name = "-".join([name, random_gen()]) elif "name" in services: cmd.name = "-".join([services["name"], random_gen()]) if networkdomain: cmd.networkdomain = networkdomain elif "networkdomain" in services: cmd.networkdomain = services["networkdomain"] if parentdomainid: cmd.parentdomainid = parentdomainid elif "parentdomainid" in services: cmd.parentdomainid = services["parentdomainid"] return Domain(apiclient.createDomain(cmd).__dict__)
def create_from_snapshot(cls, apiclient, snapshot_id, services, account=None, domainid=None): """Create Volume from snapshot""" cmd = createVolume.createVolumeCmd() cmd.name = "-".join([services["diskname"], random_gen()]) cmd.snapshotid = snapshot_id cmd.zoneid = services["zoneid"] cmd.size = services["size"] if account: cmd.account = account else: cmd.account = services["account"] if domainid: cmd.domainid = domainid else: cmd.domainid = services["domainid"] return Volume(apiclient.createVolume(cmd).__dict__)
def create(cls, apiclient, services, account, domainid): cmd = createUser.createUserCmd() """Creates an user""" cmd.account = account cmd.domainid = domainid cmd.email = services["email"] cmd.firstname = services["firstname"] cmd.lastname = services["lastname"] # Password Encoding mdf = hashlib.md5() mdf.update(services["password"]) cmd.password = mdf.hexdigest() cmd.username = "******".join([services["username"], random_gen()]) user = apiclient.createUser(cmd) return User(user.__dict__)
def create(cls, apiclient, services, admin=False, domainid=None): """Creates an account""" cmd = createAccount.createAccountCmd() #0 - User, 1 - Root Admin, 2 - Domain Admin cmd.accounttype = 2 if (admin and domainid) else int(admin) cmd.email = services["email"] cmd.firstname = services["firstname"] cmd.lastname = services["lastname"] # Password Encoding mdf = hashlib.md5() mdf.update(services["password"]) cmd.password = mdf.hexdigest() cmd.username = "******".join([services["username"], random_gen()]) if domainid: cmd.domainid = domainid account = apiclient.createAccount(cmd) return Account(account.__dict__)
def create(cls, apiclient, services, volumeid=None, account=None, domainid=None): """Create template from Volume""" #Create template from Virtual machine and Volume ID cmd = createTemplate.createTemplateCmd() cmd.displaytext = services["displaytext"] cmd.name = "-".join([services["name"], random_gen()]) cmd.ostypeid = services["ostypeid"] 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 return Template(apiclient.createTemplate(cmd).__dict__)