<s> import logging <EOL> from dbaas_cloudstack . models import HostAttr <EOL> from util import check_ssh <EOL> from workflow . exceptions . error_codes import DBAAS_0015 <EOL> from util import full_stack <EOL> from dbaas_cloudstack . provider import CloudStackProvider <EOL> from dbaas_credentials . models import CredentialType <EOL> from util import get_credentials_for <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def start_vm ( workflow_dict ) : <EOL> try : <EOL> environment = workflow_dict [ '<STR_LIT>' ] <EOL> cs_credentials = get_credentials_for ( <EOL> environment = environment , credential_type = CredentialType . CLOUDSTACK ) <EOL> cs_provider = CloudStackProvider ( credentials = cs_credentials ) <EOL> host = workflow_dict [ '<STR_LIT:host>' ] <EOL> host_csattr = HostAttr . objects . get ( host = host ) <EOL> started = cs_provider . start_virtual_machine ( vm_id = host_csattr . vm_id ) <EOL> if not started : <EOL> raise Exception ( "<STR_LIT>" . format ( host ) ) <EOL> host_ready = check_ssh ( server = host . address , <EOL> username = host_csattr . vm_user , <EOL> password = host_csattr . vm_password , <EOL> retries = <NUM_LIT:50> , <EOL> wait = <NUM_LIT:20> , <EOL> interval = <NUM_LIT:30> ) <EOL> if not host_ready : <EOL> error = "<STR_LIT>" % host <EOL> LOG . warn ( error ) <EOL> raise Exception ( error ) <EOL> return True <EOL> except Exception : <EOL> traceback = full_stack ( ) <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( DBAAS_0015 ) <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( traceback ) <EOL> return False <EOL> def stop_vm ( workflow_dict ) : <EOL> try : <EOL> environment = workflow_dict [ '<STR_LIT>' ] <EOL> cs_credentials = get_credentials_for ( <EOL> environment = environment , credential_type = CredentialType . CLOUDSTACK ) <EOL> cs_provider = CloudStackProvider ( credentials = cs_credentials ) <EOL> host = workflow_dict [ '<STR_LIT:host>' ] <EOL> host_csattr = HostAttr . objects . get ( host = host ) <EOL> stoped = cs_provider . stop_virtual_machine ( vm_id = host_csattr . vm_id ) <EOL> if not stoped : <EOL> raise Exception ( "<STR_LIT>" . format ( host ) ) <EOL> return True <EOL> except Exception : <EOL> traceback = full_stack ( ) <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( DBAAS_0015 ) <EOL> workflow_dict [ '<STR_LIT>' ] [ '<STR_LIT>' ] . append ( traceback ) <EOL> return False </s>
