本文整理汇总了Python中util.exec_remote_command函数的典型用法代码示例。如果您正苦于以下问题:Python exec_remote_command函数的具体用法?Python exec_remote_command怎么用?Python exec_remote_command使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exec_remote_command函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: undo
def undo(self, workflow_dict):
LOG.info("Running undo...")
try:
script = build_clean_database_dir_script()
script = build_context_script({}, script)
for source_host in workflow_dict['source_hosts']:
target_host = source_host.future_host
target_cs_host_attr = CS_HostAttr.objects.get(host=target_host)
output = {}
exec_remote_command(server=target_host.address,
username=target_cs_host_attr.vm_user,
password=target_cs_host_attr.vm_password,
command=script,
output=output)
LOG.info(output)
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例2: undo
def undo(self, workflow_dict):
try:
LOG.info("Remove all backup log files")
backup_log_dict = get_backup_log_configuration_dict(environment=workflow_dict['environment'],
databaseinfra=workflow_dict['databaseinfra'])
if backup_log_dict is None:
return True
instance = workflow_dict['instances'][0]
host = instance.hostname
host_csattr = CsHostAttr.objects.get(host=host)
exec_remote_command(server=host.address,
username=host_csattr.vm_user,
password=host_csattr.vm_password,
command=backup_log_dict['CLEAN_BACKUP_LOG_SCRIPT'])
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0014)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例3: mysql_binlog_save
def mysql_binlog_save(client, instance, cloudstack_hostattr):
try:
client.query('show master status')
r = client.store_result()
row = r.fetch_row(maxrows=0, how=1)
binlog_file = row[0]['File']
binlog_pos = row[0]['Position']
client.query("show variables like 'datadir'")
r = client.store_result()
row = r.fetch_row(maxrows=0, how=1)
datadir = row[0]['Value']
output = {}
command = 'echo "master=%s;position=%s" > %smysql_binlog_master_file_pos' % (
binlog_file, binlog_pos, datadir)
exec_remote_command(server=instance.hostname.address,
username=cloudstack_hostattr.vm_user,
password=cloudstack_hostattr.vm_password,
command=command,
output=output)
except Exception as e:
LOG.error(
"Error saving mysql master binlog file and position: %s" % (e))
示例4: undo
def undo(self, workflow_dict):
LOG.info("Running undo...")
try:
script = build_stop_database_script()
script = build_context_script({}, script)
for target_instance in workflow_dict['target_instances']:
target_host = target_instance.hostname
target_cs_host_attr = CS_HostAttr.objects.get(host=target_host)
output = {}
exec_remote_command(server=target_host.address,
username=target_cs_host_attr.vm_user,
password=target_cs_host_attr.vm_password,
command=script,
output=output)
LOG.info(output)
try:
if 'region_migration_dir_infra_name' in workflow_dict:
shutil.rmtree(workflow_dict['region_migration_dir_infra_name'])
except Exception:
pass
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例5: do
def do(self, workflow_dict):
try:
for host in workflow_dict['source_hosts']:
LOG.info("Removing database files on host %s" % host)
host_csattr = CsHostAttr.objects.get(host=host)
output = {}
exec_remote_command(server=host.address,
username=host_csattr.vm_user,
password=host_csattr.vm_password,
command="/opt/dbaas/scripts/dbaas_deletedatabasefiles.sh",
output=output)
LOG.info(output)
LOG.info("Removing disks on host %s" % host)
NfsaasProvider().destroy_disk(environment=workflow_dict['source_environment'],
host=host)
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例6: run_vm_script
def run_vm_script(workflow_dict, context_dict, script):
try:
final_context_dict = dict(context_dict.items())
instance = workflow_dict['instance']
host = workflow_dict['host']
host_csattr = HostAttr.objects.get(host=host)
final_context_dict['HOSTADDRESS'] = instance.address
final_context_dict['PORT'] = instance.port
final_context_dict['DBPASSWORD'] = workflow_dict['databaseinfra'].password
command = build_context_script(final_context_dict, script)
output = {}
return_code = exec_remote_command(server=host.address,
username=host_csattr.vm_user,
password=host_csattr.vm_password,
command=command,
output=output)
if return_code:
raise Exception("Could not run script. Output: {}".format(output))
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0015)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例7: do
def do(self, workflow_dict):
try:
sleep(60)
databaseinfra = workflow_dict['databaseinfra']
driver = databaseinfra.get_driver()
files_to_remove = driver.remove_deprectaed_files()
command = files_to_remove + " && cp -rp /data/* /data2"
host = workflow_dict['host']
cs_host_attr = CsHostAttr.objects.get(host=host)
output = {}
return_code = exec_remote_command(server=host.address,
username=cs_host_attr.vm_user,
password=cs_host_attr.vm_password,
command=command,
output=output)
if return_code != 0:
raise Exception(str(output))
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0022)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例8: do
def do(self, workflow_dict):
try:
databaseinfra = workflow_dict['databaseinfra']
driver = databaseinfra.get_driver()
host = workflow_dict['host']
host_attr = HostAttr.objects.get(host=host)
sleep(30)
for agent in driver.get_database_agents():
script = '/etc/init.d/{} start'.format(agent)
output = {}
return_code = exec_remote_command(server=host.address,
username=host_attr.vm_user,
password=host_attr.vm_password,
command=script,
output=output)
LOG.info('Running {} - Return Code: {}. Output scrit: {}'.format(
script, return_code, output))
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0022)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例9: do
def do(self, workflow_dict):
try:
for source_host in workflow_dict['source_hosts']:
future_host = source_host.future_host
hosts_option = [(future_host, 'stop')]
for host, option in hosts_option:
LOG.info("{} td_agent on host {}".format(option, host))
cs_host_attr = CS_HostAttr.objects.get(host=host)
script = test_bash_script_error()
script += monit_script(option)
script += td_agent_script(option)
LOG.info(script)
output = {}
return_code = exec_remote_command(server=host.address,
username=cs_host_attr.vm_user,
password=cs_host_attr.vm_password,
command=script,
output=output)
LOG.info(output)
if return_code != 0:
LOG.error("Error stopping td_agent")
LOG.error(str(output))
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例10: do
def do(self, workflow_dict):
try:
host = workflow_dict['source_hosts'][0]
databaseinfra = workflow_dict['databaseinfra']
cs_host_attr = CS_HostAttr.objects.get(host=host)
context_dict = {
'MASTERPAIRNAME': databaseinfra.name,
}
script = test_bash_script_error()
script += build_turn_flipper_ip_down_script()
script = build_context_script(context_dict, script)
output = {}
return_code = exec_remote_command(
server=host.address,
username=cs_host_attr.vm_user,
password=cs_host_attr.vm_password,
command=script,
output=output)
LOG.info(output)
if return_code != 0:
raise Exception(str(output))
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例11: run_vm_script
def run_vm_script(workflow_dict, context_dict, script):
try:
instances_detail = workflow_dict['instances_detail']
final_context_dict = dict(context_dict.items() + workflow_dict['initial_context_dict'].items())
for instance_detail in instances_detail:
instance = instance_detail['instance']
host = instance.hostname
host_csattr = HostAttr.objects.get(host=host)
final_context_dict['HOSTADDRESS'] = instance.address
final_context_dict['PORT'] = instance.port
command = build_context_script(final_context_dict, script)
output = {}
return_code = exec_remote_command(server = host.address,
username = host_csattr.vm_user,
password = host_csattr.vm_password,
command = command,
output = output)
if return_code:
raise Exception, "Could not run script. Output: {}".format(output)
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0015)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例12: switch_master
def switch_master(self):
master = self.get_master_instance()
slave = self.get_slave_instances()[0]
host = master.hostname
host_attr = HostAttr.objects.get(host=host)
script = """
sudo -u flipper /usr/bin/flipper {{MASTERPAIRNAME}} set write {{HOST01.address}}
sudo -u flipper /usr/bin/flipper {{MASTERPAIRNAME}} set read {{HOST02.address}}
"""
context_dict = {
'MASTERPAIRNAME': self.databaseinfra.name,
'HOST01': slave.hostname,
'HOST02': master.hostname,
}
script = build_context_script(context_dict, script)
output = {}
return_code = exec_remote_command(server=host.address,
username=host_attr.vm_user,
password=host_attr.vm_password,
command=script,
output=output)
LOG.info(output)
if return_code != 0:
raise Exception(str(output))
示例13: do
def do(self, workflow_dict):
try:
option = 'restart'
for host in workflow_dict['hosts']:
LOG.info("{} monit on host {}".format(option, host))
cs_host_attr = CS_HostAttr.objects.get(host=host)
script = test_bash_script_error()
script += td_agent_script(option)
LOG.info(script)
output = {}
sleep(30)
return_code = exec_remote_command(server=host.address,
username=cs_host_attr.vm_user,
password=cs_host_attr.vm_password,
command=script,
output=output)
LOG.info(output)
if return_code != 0:
LOG.error("Error monit")
LOG.error(str(output))
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0002)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例14: undo
def undo(self, workflow_dict):
LOG.info("Running undo...")
try:
command = 'mount /data'
for host_and_export in workflow_dict['hosts_and_exports']:
host = host_and_export['host']
LOG.info('mount data volume on host {}'.format(host))
cs_host_attr = CsHostAttr.objects.get(host=host)
output = {}
return_code = exec_remote_command(server=host.address,
username=cs_host_attr.vm_user,
password=cs_host_attr.vm_password,
command=command,
output=output)
if return_code != 0:
LOG.info(str(output))
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0021)
workflow_dict['exceptions']['traceback'].append(traceback)
return False
示例15: undo
def undo(self, workflow_dict):
LOG.info("Running undo...")
try:
databaseinfra = workflow_dict['databaseinfra']
host = workflow_dict['host']
return_code, output = use_database_initialization_script(databaseinfra=databaseinfra,
host=host,
option='stop')
if return_code != 0:
LOG.info(str(output))
cs_host_attr = CsHostAttr.objects.get(host=host)
output = {}
return_code = exec_remote_command(server=host.address,
username=cs_host_attr.vm_user,
password=cs_host_attr.vm_password,
command='umount /data',
output=output)
if return_code != 0:
raise Exception(str(output))
return True
except Exception:
traceback = full_stack()
workflow_dict['exceptions']['error_codes'].append(DBAAS_0022)
workflow_dict['exceptions']['traceback'].append(traceback)
return False