<s> import logging <EOL> from util import full_stack <EOL> from util import exec_remote_command <EOL> from dbaas_cloudstack . models import HostAttr as CS_HostAttr <EOL> from workflow . steps . util . base import BaseStep <EOL> from workflow . steps . util import test_bash_script_error <EOL> from workflow . steps . util import td_agent_script <EOL> from workflow . steps . util import monit_script <EOL> from workflow . exceptions . error_codes import DBAAS_0020 <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class StartTDAgent ( BaseStep ) : <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" <EOL> def do ( self , workflow_dict ) : <EOL> try : <EOL> for source_host in workflow_dict [ '<STR_LIT>' ] : <EOL> future_host = source_host . future_host <EOL> hosts_option = [ ( source_host , '<STR_LIT>' ) , ( future_host , '<STR_LIT:start>' ) ] <EOL> for host , option in hosts_option : <EOL> LOG . info ( "<STR_LIT>" . format ( option , host ) ) <EOL> cs_host_attr = CS_HostAttr . objects . get ( host = host ) <EOL> script = test_bash_script_error ( ) <EOL> script += monit_script ( option ) <EOL> script += td_agent_script ( option ) <EOL> LOG . info ( script ) <EOL> output = { } <EOL> return_code = exec_remote_command ( server = host . address , <EOL> username = cs_host_attr . vm_user , <EOL> password = cs_host_attr . vm_password , <EOL> command = script , <EOL> output = output ) <EOL> LOG . info ( output ) <EOL> if return_code != <NUM_LIT:0> : <EOL> LOG . error ( "<STR_LIT>" ) <EOL> LOG . error ( str ( output ) ) <EOL> return True <EOL> except Exception : <EOL> traceback = full_stack ( ) <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( DBAAS_0020 ) <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( traceback ) <EOL> return False <EOL> def undo ( self , workflow_dict ) : <EOL> LOG . info ( "<STR_LIT>" ) <EOL> try : <EOL> for source_host in workflow_dict [ '<STR_LIT>' ] : <EOL> future_host = source_host . future_host <EOL> hosts_option = [ ( future_host , '<STR_LIT>' ) , ( source_host , '<STR_LIT:start>' ) ] <EOL> for host , option in hosts_option : <EOL> LOG . info ( "<STR_LIT>" . format ( option , host ) ) <EOL> cs_host_attr = CS_HostAttr . objects . get ( host = host ) <EOL> script = test_bash_script_error ( ) <EOL> script += monit_script ( option ) <EOL> script += td_agent_script ( option ) <EOL> LOG . info ( script ) <EOL> output = { } <EOL> return_code = exec_remote_command ( server = host . address , <EOL> username = cs_host_attr . vm_user , <EOL> password = cs_host_attr . vm_password , <EOL> command = script , <EOL> output = output ) <EOL> LOG . info ( output ) <EOL> if return_code != <NUM_LIT:0> : <EOL> LOG . error ( "<STR_LIT>" ) <EOL> LOG . error ( str ( output ) ) <EOL> return True <EOL> except Exception : <EOL> traceback = full_stack ( ) <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( DBAAS_0020 ) <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( traceback ) <EOL> return False <EOL> class StopTDAgent ( BaseStep ) : <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" <EOL> def do ( self , workflow_dict ) : <EOL> try : <EOL> for source_host in workflow_dict [ '<STR_LIT>' ] : <EOL> future_host = source_host . future_host <EOL> hosts_option = [ ( future_host , '<STR_LIT>' ) ] <EOL> for host , option in hosts_option : <EOL> LOG . info ( "<STR_LIT>" . format ( option , host ) ) <EOL> cs_host_attr = CS_HostAttr . objects . get ( host = host ) <EOL> script = test_bash_script_error ( ) <EOL> script += monit_script ( option ) <EOL> script += td_agent_script ( option ) <EOL> LOG . info ( script ) <EOL> output = { } <EOL> return_code = exec_remote_command ( server = host . address , <EOL> username = cs_host_attr . vm_user , <EOL> password = cs_host_attr . vm_password , <EOL> command = script , <EOL> output = output ) <EOL> LOG . info ( output ) <EOL> if return_code != <NUM_LIT:0> : <EOL> LOG . error ( "<STR_LIT>" ) <EOL> LOG . error ( str ( output ) ) <EOL> return True <EOL> except Exception : <EOL> traceback = full_stack ( ) <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( DBAAS_0020 ) <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( traceback ) <EOL> return False <EOL> def undo ( self , workflow_dict ) : <EOL> try : <EOL> return True <EOL> except Exception : <EOL> traceback = full_stack ( ) <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( DBAAS_0020 ) <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( traceback ) <EOL> return False </s>
