本文整理汇总了Python中dbaas_cloudstack.provider.CloudStackProvider.update_userdata方法的典型用法代码示例。如果您正苦于以下问题:Python CloudStackProvider.update_userdata方法的具体用法?Python CloudStackProvider.update_userdata怎么用?Python CloudStackProvider.update_userdata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dbaas_cloudstack.provider.CloudStackProvider
的用法示例。
在下文中一共展示了CloudStackProvider.update_userdata方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do
# 需要导入模块: from dbaas_cloudstack.provider import CloudStackProvider [as 别名]
# 或者: from dbaas_cloudstack.provider.CloudStackProvider import update_userdata [as 别名]
def do(self, workflow_dict):
try:
LOG.info("Getting cloudstack credentials...")
cs_credentials = get_credentials_for(
environment=workflow_dict['environment'],
credential_type=CredentialType.CLOUDSTACK)
cs_provider = CloudStackProvider(credentials=cs_credentials)
statsd_credentials = get_credentials_for(
environment=workflow_dict['environment'],
credential_type=CredentialType.STATSD)
statsd_host, statsd_port = statsd_credentials.endpoint.split(':')
for index, hosts in enumerate(permutations(workflow_dict['hosts'])):
LOG.info("Getting vm credentials...")
host_csattr = CsHostAttr.objects.get(host=hosts[0])
LOG.info("Cheking host ssh...")
host_ready = check_ssh(
server=hosts[0].address, username=host_csattr.vm_user, password=host_csattr.vm_password, wait=5,
interval=10)
if not host_ready:
LOG.warn("Host %s is not ready..." % hosts[0])
return False
host_nfsattr = HostAttr.objects.get(host=hosts[0])
planattr = PlanAttr.objects.get(plan=workflow_dict['plan'])
contextdict = {
'EXPORTPATH': host_nfsattr.nfsaas_path,
'DATABASENAME': workflow_dict['name'],
'DBPASSWORD': get_credentials_for(environment=workflow_dict['environment'],
credential_type=CredentialType.MYSQL).password,
'HOST': workflow_dict['hosts'][index].hostname.split('.')[0],
'ENGINE': 'mysql',
'STATSD_HOST': statsd_host,
'STATSD_PORT': statsd_port,
}
if len(workflow_dict['hosts']) > 1:
LOG.info("Updating contexdict for %s" % hosts[0])
contextdict.update({
'SERVERID': index + 1,
'IPMASTER': hosts[1].address,
'IPWRITE': workflow_dict['databaseinfraattr'][0].ip,
'IPREAD': workflow_dict['databaseinfraattr'][1].ip,
'MASTERPAIRNAME': workflow_dict['databaseinfra'].name,
'HOST01': workflow_dict['hosts'][0],
'HOST02': workflow_dict['hosts'][1],
'INSTANCE01': workflow_dict['instances'][0],
'INSTANCE02': workflow_dict['instances'][1],
'SECOND_SCRIPT_FILE': '/opt/dbaas/scripts/dbaas_second_script.sh'
})
LOG.info("Updating userdata for %s" % hosts[0])
cs_provider.update_userdata(
vm_id=host_csattr.vm_id, contextdict=contextdict, userdata=planattr.userdata)
LOG.info("Executing script on %s" % hosts[0])
return_code = exec_remote_command(server=hosts[0].address,
username=host_csattr.vm_user,
password=host_csattr.vm_password,
command='/opt/dbaas/scripts/dbaas_userdata_script.sh')
if return_code != 0:
return False
if len(workflow_dict['hosts']) > 1:
for host in workflow_dict['hosts']:
LOG.info("Executing script on %s" % hosts[0])
return_code = exec_remote_command(server=host.address,
username=host_csattr.vm_user,
password=host_csattr.vm_password,
command=contextdict['SECOND_SCRIPT_FILE'])
if return_code != 0:
return False
return True
except Exception, e:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0013)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例2: do
# 需要导入模块: from dbaas_cloudstack.provider import CloudStackProvider [as 别名]
# 或者: from dbaas_cloudstack.provider.CloudStackProvider import update_userdata [as 别名]
def do(self, workflow_dict):
try:
LOG.info("Getting cloudstack credentials...")
cs_credentials = get_credentials_for(
environment=workflow_dict['environment'],
credential_type=CredentialType.CLOUDSTACK)
cs_provider = CloudStackProvider(credentials=cs_credentials)
mongodbkey = ''.join(random.choice(string.hexdigits) for i in range(50))
workflow_dict['replicasetname'] = 'RepicaSet_' + workflow_dict['databaseinfra'].name
statsd_credentials = get_credentials_for(
environment=workflow_dict['environment'],
credential_type=CredentialType.STATSD)
statsd_host, statsd_port = statsd_credentials.endpoint.split(':')
for index, instance in enumerate(workflow_dict['instances']):
host = instance.hostname
LOG.info("Getting vm credentials...")
host_csattr = CsHostAttr.objects.get(host=host)
LOG.info("Cheking host ssh...")
host_ready = check_ssh(
server=host.address, username=host_csattr.vm_user, password=host_csattr.vm_password, wait=5,
interval=10)
if not host_ready:
LOG.warn("Host %s is not ready..." % host)
return False
if instance.is_arbiter:
contextdict = {
'HOST': workflow_dict['hosts'][index].hostname.split('.')[0],
'DATABASENAME': workflow_dict['name'],
'ENGINE': 'mongodb',
'STATSD_HOST': statsd_host,
'STATSD_PORT': statsd_port,
}
databaserule = 'ARBITER'
else:
host_nfsattr = HostAttr.objects.get(host=host)
contextdict = {
'EXPORTPATH': host_nfsattr.nfsaas_path,
'HOST': workflow_dict['hosts'][index].hostname.split('.')[0],
'DATABASENAME': workflow_dict['name'],
'ENGINE': 'mongodb',
'DBPASSWORD': get_credentials_for(environment=workflow_dict['environment'],
credential_type=CredentialType.MONGODB).password,
'STATSD_HOST': statsd_host,
'STATSD_PORT': statsd_port,
}
if index == 0:
databaserule = 'PRIMARY'
else:
databaserule = 'SECONDARY'
if len(workflow_dict['hosts']) > 1:
LOG.info("Updating contexdict for %s" % host)
contextdict.update({
'REPLICASETNAME': workflow_dict['replicasetname'],
'HOST01': workflow_dict['hosts'][0],
'HOST02': workflow_dict['hosts'][1],
'HOST03': workflow_dict['hosts'][2],
'MONGODBKEY': mongodbkey,
'DATABASERULE': databaserule,
'SECOND_SCRIPT_FILE': '/opt/dbaas/scripts/dbaas_second_script.sh',
'HOST': workflow_dict['hosts'][index].hostname.split('.')[0],
})
LOG.info("Updating userdata for %s" % host)
planattr = PlanAttr.objects.get(plan=workflow_dict['plan'])
cs_provider.update_userdata(
vm_id=host_csattr.vm_id, contextdict=contextdict, userdata=planattr.userdata)
LOG.info("Executing script on %s" % host)
return_code = exec_remote_command(server=host.address,
username=host_csattr.vm_user,
password=host_csattr.vm_password,
command='/opt/dbaas/scripts/dbaas_userdata_script.sh')
if return_code != 0:
return False
if len(workflow_dict['hosts']) > 1:
for host in workflow_dict['hosts']:
LOG.info("Executing script on %s" % host)
return_code = exec_remote_command(server=host.address,
username=host_csattr.vm_user,
password=host_csattr.vm_password,
#.........这里部分代码省略.........