<s> import logging <EOL> from util import full_stack <EOL> from workflow . steps . util . base import BaseStep <EOL> from workflow . exceptions . error_codes import DBAAS_0020 <EOL> from workflow . steps . mysql . util import get_replication_info <EOL> from workflow . steps . mysql . util import change_master_to <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class ChangeMaster ( BaseStep ) : <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" <EOL> def do ( self , workflow_dict ) : <EOL> try : <EOL> target_instances = workflow_dict [ <EOL> '<STR_LIT>' ] . instances . filter ( future_instance = None ) <EOL> target_instance_one = target_instances [ <NUM_LIT:1> ] <EOL> target_instance_zero = target_instances [ <NUM_LIT:0> ] <EOL> source_instance_zero = workflow_dict [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> master_log_file , master_log_pos = get_replication_info ( <EOL> target_instance_one ) <EOL> change_master_to ( instance = target_instance_zero , <EOL> master_host = target_instance_one . address , <EOL> bin_log_file = master_log_file , <EOL> bin_log_position = master_log_pos ) <EOL> master_log_file , master_log_pos = get_replication_info ( <EOL> target_instance_zero ) <EOL> change_master_to ( instance = source_instance_zero , <EOL> master_host = target_instance_zero . address , <EOL> bin_log_file = master_log_file , <EOL> bin_log_position = master_log_pos ) <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> target_instances = workflow_dict [ <EOL> '<STR_LIT>' ] . instances . filter ( future_instance = None ) <EOL> target_instance_zero = target_instances [ <NUM_LIT:0> ] <EOL> source_instance_zero = workflow_dict [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> source_instance_one = workflow_dict [ '<STR_LIT>' ] [ <NUM_LIT:1> ] <EOL> master_log_file , master_log_pos = get_replication_info ( <EOL> source_instance_one ) <EOL> change_master_to ( instance = source_instance_zero , <EOL> master_host = source_instance_one . address , <EOL> bin_log_file = master_log_file , <EOL> bin_log_position = master_log_pos ) <EOL> master_log_file , master_log_pos = get_replication_info ( <EOL> source_instance_zero ) <EOL> change_master_to ( instance = target_instance_zero , <EOL> master_host = source_instance_zero . address , <EOL> bin_log_file = master_log_file , <EOL> bin_log_position = master_log_pos ) <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>
