def __init__(self, mgtSvr=None, port=8096, apiKey = None, securityKey = None, asyncTimeout=3600, defaultWorkerThreads=10, logging=None): self.connection = cloudstackConnection.cloudConnection(mgtSvr, port, apiKey, securityKey, asyncTimeout, logging) self.apiClient = cloudstackAPIClient.CloudStackAPIClient(self.connection) self.dbConnection = None self.asyncJobMgr = None self.ssh = None self.defaultWorkerThreads = defaultWorkerThreads
def createNewApiClient(self, UserName, DomainName, acctType=0): if not self.isAdminContext(): return self.apiClient listDomain = listDomains.listDomainsCmd() listDomain.listall = True listDomain.name = DomainName try: domains = self.apiClient.listDomains(listDomain) domId = domains[0].id except: cdomain = createDomain.createDomainCmd() cdomain.name = DomainName domain = self.apiClient.createDomain(cdomain) domId = domain.id mdf = hashlib.md5() mdf.update("password") mdf_pass = mdf.hexdigest() cmd = listAccounts.listAccountsCmd() cmd.name = UserName cmd.domainid = domId try: accounts = self.apiClient.listAccounts(cmd) acctId = accounts[0].id except: createAcctCmd = createAccount.createAccountCmd() createAcctCmd.accounttype = acctType createAcctCmd.domainid = domId createAcctCmd.email = "test-" + self.random_gen() + "@citrix.com" createAcctCmd.firstname = UserName createAcctCmd.lastname = UserName createAcctCmd.password = mdf_pass createAcctCmd.username = UserName acct = self.apiClient.createAccount(createAcctCmd) acctId = acct.id listuser = listUsers.listUsersCmd() listuser.username = UserName listuserRes = self.apiClient.listUsers(listuser) userId = listuserRes[0].id apiKey = listuserRes[0].apikey securityKey = listuserRes[0].secretkey if apiKey is None: registerUser = registerUserKeys.registerUserKeysCmd() registerUser.id = userId registerUserRes = self.apiClient.registerUserKeys(registerUser) apiKey = registerUserRes.apikey securityKey = registerUserRes.secretkey nConnection = cloudstackConnection.cloudConnection( self.connection.mgtSvr, self.connection.port, apiKey, securityKey, self.connection.asyncTimeout, self.connection.logging) self.connection.close() self.connection = nConnection self.apiClient = cloudstackAPIClient.CloudStackAPIClient( self.connection)
def __init__(self, mgmtDetails, dbSvrDetails, asyncTimeout=3600, defaultWorkerThreads=10, logger=None): self.mgmtDetails = mgmtDetails self.connection = \ cloudstackConnection.cloudConnection(self.mgmtDetails, asyncTimeout, logger) self.apiClient =\ cloudstackAPIClient.CloudStackAPIClient(self.connection) self.dbConnection = None if dbSvrDetails is not None: self.createDbConnection(dbSvrDetails.dbSvr, dbSvrDetails.port, dbSvrDetails.user, dbSvrDetails.passwd, dbSvrDetails.db) ''' Provides the Configuration Object to users through getConfigParser The purpose of this object is to parse the config and provide dictionary of the config so users can use that configuration.Users can later call getConfig on this object and it will return the default parsed config dictionary from default configuration file, they can overwrite it with providing their own configuration file as well. ''' self.configObj = ConfigManager() self.asyncJobMgr = None self.id = None self.defaultWorkerThreads = defaultWorkerThreads
def __init__(self, mgmtDetails, dbSvrDetails, asyncTimeout=3600, defaultWorkerThreads=10, logging=None): self.mgmtDetails = mgmtDetails self.connection = \ cloudstackConnection.cloudConnection(self.mgmtDetails, asyncTimeout, logging) self.apiClient =\ cloudstackAPIClient.CloudStackAPIClient(self.connection) self.dbConnection = None if dbSvrDetails is not None: self.createDbConnection(dbSvrDetails.dbSvr, dbSvrDetails.port, dbSvrDetails.user, dbSvrDetails.passwd, dbSvrDetails.db) ''' Provides the Configuration Object to users through getConfigParser The purpose of this object is to parse the config and provide dictionary of the config so users can use that configuration.Users can later call getConfig on this object and it will return the default parsed config dictionary from default configuration file, they can overwrite it with providing their own configuration file as well. ''' self.configObj = ConfigManager() self.asyncJobMgr = None self.id = None self.defaultWorkerThreads = defaultWorkerThreads
def createUserApiClient(self, UserName, DomainName, acctType=0): if not self.isAdminContext(): return self.apiClient listDomain = listDomains.listDomainsCmd() listDomain.listall = True listDomain.name = DomainName try: domains = self.apiClient.listDomains(listDomain) domId = domains[0].id except: cdomain = createDomain.createDomainCmd() cdomain.name = DomainName domain = self.apiClient.createDomain(cdomain) domId = domain.id mdf = hashlib.md5() mdf.update("password") mdf_pass = mdf.hexdigest() cmd = listAccounts.listAccountsCmd() cmd.name = UserName cmd.domainid = domId try: accounts = self.apiClient.listAccounts(cmd) acctId = accounts[0].id except: createAcctCmd = createAccount.createAccountCmd() createAcctCmd.accounttype = acctType createAcctCmd.domainid = domId createAcctCmd.email = "test-" + self.random_gen() + "@cloudstack.org" createAcctCmd.firstname = UserName createAcctCmd.lastname = UserName createAcctCmd.password = mdf_pass createAcctCmd.username = UserName acct = self.apiClient.createAccount(createAcctCmd) acctId = acct.id listuser = listUsers.listUsersCmd() listuser.username = UserName listuserRes = self.apiClient.listUsers(listuser) userId = listuserRes[0].id apiKey = listuserRes[0].apikey securityKey = listuserRes[0].secretkey if apiKey is None: registerUser = registerUserKeys.registerUserKeysCmd() registerUser.id = userId registerUserRes = self.apiClient.registerUserKeys(registerUser) apiKey = registerUserRes.apikey securityKey = registerUserRes.secretkey newUserConnection = cloudstackConnection.cloudConnection(self.connection.mgtSvr, self.connection.port, self.connection.user, self.connection.passwd, apiKey, securityKey, self.connection.asyncTimeout, self.connection.logging) self.userApiClient = cloudstackAPIClient.CloudStackAPIClient(newUserConnection) self.userApiClient.connection = newUserConnection self.userApiClient.hypervisor = self.apiClient.hypervisor return self.userApiClient
def createUserApiClient(self, UserName, DomainName, acctType=0): if not self.isAdminContext(): return self.apiClient listDomain = listDomains.listDomainsCmd() listDomain.listall = True listDomain.name = DomainName try: domains = self.apiClient.listDomains(listDomain) domId = domains[0].id except: cdomain = createDomain.createDomainCmd() cdomain.name = DomainName domain = self.apiClient.createDomain(cdomain) domId = domain.id cmd = listAccounts.listAccountsCmd() cmd.name = UserName cmd.domainid = domId try: accounts = self.apiClient.listAccounts(cmd) acctId = accounts[0].id except: createAcctCmd = createAccount.createAccountCmd() createAcctCmd.accounttype = acctType createAcctCmd.domainid = domId createAcctCmd.email = "test-" + self.random_gen()\ + "@cloudstack.org" createAcctCmd.firstname = UserName createAcctCmd.lastname = UserName createAcctCmd.password = '******' createAcctCmd.username = UserName acct = self.apiClient.createAccount(createAcctCmd) acctId = acct.id listuser = listUsers.listUsersCmd() listuser.username = UserName listuserRes = self.apiClient.listUsers(listuser) userId = listuserRes[0].id apiKey = listuserRes[0].apikey securityKey = listuserRes[0].secretkey if apiKey is None: registerUser = registerUserKeys.registerUserKeysCmd() registerUser.id = userId registerUserRes = self.apiClient.registerUserKeys(registerUser) apiKey = registerUserRes.apikey securityKey = registerUserRes.secretkey newUserConnection =\ cloudstackConnection.cloudConnection(self.connection.mgtSvr, self.connection.port, self.connection.user, self.connection.passwd, apiKey, securityKey, self.connection.asyncTimeout, self.connection.logging) self.userApiClient =\ cloudstackAPIClient.CloudStackAPIClient(newUserConnection) self.userApiClient.connection = newUserConnection self.userApiClient.hypervisor = self.apiClient.hypervisor return self.userApiClient
def createUserApiClient(self, UserName, DomainName, acctType=0): if not self.isAdminContext(): return self.apiClient listDomain = listDomains.listDomainsCmd() listDomain.listall = True listDomain.name = DomainName try: domains = self.apiClient.listDomains(listDomain) domId = domains[0].id except: cdomain = createDomain.createDomainCmd() cdomain.name = DomainName domain = self.apiClient.createDomain(cdomain) domId = domain.id cmd = listAccounts.listAccountsCmd() cmd.name = UserName cmd.domainid = domId try: accounts = self.apiClient.listAccounts(cmd) acctId = accounts[0].id except: createAcctCmd = createAccount.createAccountCmd() createAcctCmd.accounttype = acctType createAcctCmd.domainid = domId createAcctCmd.email = "test-" + random_gen()\ + "@cloudstack.org" createAcctCmd.firstname = UserName createAcctCmd.lastname = UserName createAcctCmd.password = '******' createAcctCmd.username = UserName acct = self.apiClient.createAccount(createAcctCmd) acctId = acct.id listuser = listUsers.listUsersCmd() listuser.username = UserName listuserRes = self.apiClient.listUsers(listuser) userId = listuserRes[0].id apiKey = listuserRes[0].apikey securityKey = listuserRes[0].secretkey if apiKey is None: registerUser = registerUserKeys.registerUserKeysCmd() registerUser.id = userId registerUserRes = self.apiClient.registerUserKeys(registerUser) apiKey = registerUserRes.apikey securityKey = registerUserRes.secretkey mgtDetails = self.mgmtDetails mgtDetails.apiKey = apiKey mgtDetails.securityKey = securityKey newUserConnection =\ cloudstackConnection.cloudConnection(mgtDetails, self.connection.asyncTimeout, self.connection.logger) self.userApiClient =\ cloudstackAPIClient.CloudStackAPIClient(newUserConnection) self.userApiClient.connection = newUserConnection self.userApiClient.hypervisor = self.apiClient.hypervisor return self.userApiClient