#NEWLINE# def do( self , workflow_dict ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# LOG . info ( 'Getting cloudstack credentials...' ) #NEWLINE# statsd_credentials = get_credentials_for ( environment = workflow_dict [ 'environment' ] , credential_type = CredentialType . STATSD ) #NEWLINE# ( statsd_host , statsd_port ) = statsd_credentials . endpoint . split ( ':' ) #NEWLINE# for ( index , host ) in enumerate ( workflow_dict [ 'hosts' ] ) : #NEWLINE# #INDENT# LOG . info ( 'Getting vm credentials...' ) #NEWLINE# host_csattr = CsHostAttr . objects . get ( host = host ) #NEWLINE# LOG . info ( 'Cheking host ssh...' ) #NEWLINE# host_ready = check_ssh ( server = host . address , username = host_csattr . vm_user , password = host_csattr . vm_password , wait = 5 , interval = 10 ) #NEWLINE# if ( not host_ready ) : #NEWLINE# #INDENT# LOG . warn ( ( 'Host %s is not ready...' % host ) ) #NEWLINE# return False #NEWLINE# #UNINDENT# instances_redis = Instance . objects . filter ( hostname = host , instance_type = Instance . REDIS ) #NEWLINE# instances_sentinel = Instance . objects . filter ( hostname = host , instance_type = Instance . REDIS_SENTINEL ) #NEWLINE# if instances_redis : #NEWLINE# #INDENT# host_nfsattr = HostAttr . objects . get ( host = host ) #NEWLINE# nfsaas_path = host_nfsattr . nfsaas_path #NEWLINE# only_sentinel = False #NEWLINE# instance_redis_address = instances_redis [ 0 ] . address #NEWLINE# instance_redis_port = instances_redis [ 0 ] . port #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# nfsaas_path = '' #NEWLINE# only_sentinel = True #NEWLINE# instance_redis_address = '' #NEWLINE# instance_redis_port = '' #NEWLINE# #UNINDENT# if instances_sentinel : #NEWLINE# #INDENT# instance_sentinel_address = instances_sentinel [ 0 ] . address #NEWLINE# instance_sentinel_port = instances_sentinel [ 0 ] . port #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# instance_sentinel_address = '' #NEWLINE# instance_sentinel_port = '' #NEWLINE# #UNINDENT# if ( index == 0 ) : #NEWLINE# #INDENT# master_host = instance_redis_address #NEWLINE# master_port = instance_redis_port #NEWLINE# #UNINDENT# contextdict = { #NEWLINE# #INDENT# 'EXPORTPATH' : nfsaas_path , #NEWLINE# 'DATABASENAME' : workflow_dict [ 'name' ] , #NEWLINE# 'DBPASSWORD' : workflow_dict [ 'databaseinfra' ] . password , #NEWLINE# 'HOSTADDRESS' : instance_redis_address , #NEWLINE# 'PORT' : instance_redis_port , #NEWLINE# 'ENGINE' : 'redis' , #NEWLINE# 'HOST' : host . hostname . split ( '.' ) [ 0 ] , #NEWLINE# 'STATSD_HOST' : statsd_host , #NEWLINE# 'STATSD_PORT' : statsd_port , #NEWLINE# 'IS_HA' : workflow_dict [ 'databaseinfra' ] . plan . is_ha , #NEWLINE# 'SENTINELMASTER' : master_host , #NEWLINE# 'SENTINELMASTERPORT' : master_port , #NEWLINE# 'SENTINELADDRESS' : instance_sentinel_address , #NEWLINE# 'SENTINELPORT' : instance_sentinel_port , #NEWLINE# 'MASTERNAME' : workflow_dict [ 'databaseinfra' ] . name , #NEWLINE# 'ONLY_SENTINEL' : only_sentinel , #NEWLINE# #UNINDENT# } #NEWLINE# LOG . info ( contextdict ) #NEWLINE# planattr = PlanAttr . objects . get ( plan = workflow_dict [ 'plan' ] ) #NEWLINE# scripts = ( planattr . initialization_script , planattr . configuration_script , planattr . start_database_script , planattr . start_replication_script ) #NEWLINE# for script in scripts : #NEWLINE# #INDENT# LOG . info ( ( 'Executing script on %s' % statsd_credentials ) ) #NEWLINE# script = build_context_script ( contextdict , script ) #NEWLINE# return_code = exec_remote_command ( server = host . address , username = host_csattr . vm_user , password = host_csattr . vm_password , command = script ) #NEWLINE# if ( return_code != 0 ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# if ( ( index > 0 ) and instances_redis ) : #NEWLINE# #INDENT# client = instances_redis [ 0 ] . databaseinfra . get_driver ( ) . get_client ( instances_redis [ 0 ] ) #NEWLINE# client . slaveof ( master_host , master_port ) #NEWLINE# #UNINDENT# #UNINDENT# return True #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# traceback = full_stack ( ) #NEWLINE# workflow_dict [ 'exceptions' ] [ 'error_codes' ] . append ( DBAAS_0016 ) #NEWLINE# workflow_dict [ 'exceptions' ] [ 'traceback' ] . append ( traceback ) #NEWLINE# return False