in footmark/rds/connection.py [0:0]
def _modify_rds_instance(self, instance_id, current_connection_string, connection_string_prefix, port,
connection_mode, db_instance_class, db_instance_storage, pay_type, instance_description,
security_ip_list, instance_network_type, vpc_id, vswitch_id, maint_window,
preferred_backup_time, preferred_backup_period, backup_retention_period):
"""
Modify RDS Instance
:type instance_id: string
:param instance_id: Id of the Instance to modify
:type current_connection_string: string
:param current_connection_string: Current connection string of an instance.
:type connection_string_prefix: string
:param connection_string_prefix: Target connection string
:type port: integer
:param port: Target port
:type connection_mode: string
:param connection_mode: Connection mode of the RDS Instance
:type db_instance_class: string
:param db_instance_class: The instance type of the database
:type db_instance_storage: integer
:param db_instance_storage: Size in gigabytes of the DB instance to change
:type pay_type: string
:param pay_type: The pay type of the DB instance.
:type instance_description: string
:param instance_description: Instance description or remarks, no more than 256 bytes
:type security_ip_list: string
:param security_ip_list: List of IP addresses allowed to access all databases of an instance
:type instance_network_type: string
:param instance_network_type: The network type of the instance.
:type vpc_id: string
:param vpc_id: The ID of the VPC.
:type vswitch_id: string
:param vswitch_id: ID of VSwitch
:type maint_window: string
:param maint_window: Maintenance window in format of ddd:hh24:mi-ddd:hh24:mi.
:type preferred_backup_time: string
:param preferred_backup_time: Backup time, in the format ofHH:mmZ- HH:mm Z.
:type preferred_backup_period: string
:param preferred_backup_period: Backup period
:type backup_retention_period: integer
:param backup_retention_period: Retention days of the backup
:return:
changed: If instance is modified successfully. the changed para will be set to True else False
result: detailed server response
"""
params = {}
results = []
changed = False
perform_flag = True
try:
instance_status = "Stopped"
while instance_status == "Stopped":
try:
instance_info = self.get_rds_instances_info(instance_id)
if instance_info:
if int(instance_info[1]['TotalRecordCount']) == 1:
instance_status = "Present"
break
else:
perform_flag = False
results.append({"Error Message": "Instance not found in specified region"})
break
except Exception as ex:
instance_status = "Stopped"
if perform_flag:
if self.check_instance_status(instance_id):
changed_inst_type, result_inst_type = self.change_rds_instance_type(instance_id, db_instance_class,
db_instance_storage, pay_type)
if result_inst_type:
results.append(result_inst_type)
if 'error' not in (''.join(str(result_inst_type))).lower():
changed = True
time.sleep(60)
if self.check_instance_status(instance_id):
changed_security_ip, result_security_ip =\
self.modify_rds_instance_security_ip_list(instance_id, security_ip_list)
if 'error' in (''.join(str(result_security_ip))).lower():
results.append(result_security_ip)
else:
changed = True
if preferred_backup_time and preferred_backup_period:
if self.check_instance_status(instance_id):
changed_backup_policy, result_backup_policy = \
self.modify_backup_policy(instance_id, preferred_backup_time, preferred_backup_period,
backup_retention_period)
if 'error' in (''.join(str(result_backup_policy))).lower():
results.append(result_backup_policy)
else:
changed = True
if maint_window:
if self.check_instance_status(instance_id):
changed_maint_time, result_maint_time = self.modify_db_instance_maint_time(instance_id,
maint_window)
if 'error' in (''.join(str(result_maint_time))).lower():
results.append(result_maint_time)
else:
changed = True
if connection_mode:
if self.check_instance_status(instance_id):
changed_conn_mode, result_conn_mode = self.modify_rds_instance_access_mode(instance_id,
connection_mode)
if 'error' in (''.join(str(result_conn_mode))).lower():
results.append(result_conn_mode)
else:
changed = True
time.sleep(5)
if instance_description:
if self.check_instance_status(instance_id):
changed_inst_desc, result_inst_desc = self.modify_rds_instance_description(instance_id,
instance_description)
if 'error' in (''.join(str(result_inst_desc))).lower():
results.append(result_inst_desc)
else:
changed = True
if current_connection_string:
if self.check_instance_status(instance_id) and connection_string_prefix and port:
changed_public_conn, result_public_conn = \
self.modify_instance_public_connection(instance_id, current_connection_string,
connection_string_prefix, port)
if 'error' in (''.join(str(result_public_conn))).lower():
results.append(result_public_conn)
else:
changed = True
time.sleep(5)
if instance_network_type and self.check_instance_status(instance_id):
changed_net_type, result_net_type = self.modify_rds_instance_network_type(instance_id,
instance_network_type,
vpc_id, vswitch_id)
if 'error' in (''.join(str(result_net_type))).lower():
results.append(result_net_type)
else:
changed = True
except Exception as ex:
error_code = str(ex.error_code)
error_msg = str(ex.message)
results.append({"Error Code": error_code, "Error Message": error_msg})
return changed, results