in footmark/rds/connection.py [0:0]
def switch_between_primary_standby_database(self, instance_id, node_id, force):
"""
Switch between primary and standby databases in rds instance
:type instance_id: str
:param instance_id: Id of instances to modify
:type node_id: str
:param node_id: Unique ID of a node
:type force: str
:param force: Yes: forced; No: unforced; default value: unforced
:return: Result dict of operation
"""
params = {}
results = []
changed = False
try:
self.build_list_params(params, instance_id, 'DBInstanceId')
describe_response = self.get_status('DescribeDBInstanceHAConfig', params)
if describe_response:
for describe_config in describe_response['HostInstanceInfos']['NodeInfo']:
if describe_config['NodeType'] == 'Slave':
node = describe_config['NodeId']
break
if node == node_id:
if node_id:
self.build_list_params(params, node_id, 'NodeId')
if force:
self.build_list_params(params, force, 'Force')
response = self.get_status('SwitchDBInstanceHA', params)
results.append(response)
changed = True
time.sleep(7)
else:
results.append({"Error Message": "The specified node_id is not found"})
except Exception as ex:
if (ex.args is None) or (ex.args == "need more than 2 values to unpack") \
or (ex.message == "need more than 2 values to unpack"):
results.append({"Error Message": "The API is showing None error code and error message"})
else:
error_code = ex.error_code
error_msg = ex.message
results.append({"Error Code": error_code, "Error Message": error_msg})
return changed, results