def restore_autonomous_data_warehouse(db_client, module): result = dict(changed=True, autonomous_data_warehouse="") autonomous_data_warehouse_id = module.params.get( "autonomous_data_warehouse_id") restore_autonomous_data_warehouse_details = RestoreAutonomousDataWarehouseDetails( ) for attribute in restore_autonomous_data_warehouse_details.attribute_map: restore_autonomous_data_warehouse_details.__setattr__( attribute, module.params.get(attribute)) result = oci_db_utils.execute_function_and_wait( resource_type="autonomous_data_warehouse", function=db_client.restore_autonomous_data_warehouse, kwargs_function={ "autonomous_data_warehouse_id": autonomous_data_warehouse_id, "restore_autonomous_data_warehouse_details": restore_autonomous_data_warehouse_details, }, client=db_client, get_fn=db_client.get_autonomous_data_warehouse, get_param="autonomous_data_warehouse_id", module=module, states=["AVAILABLE", "FAILED"], ) return result
def perform_start_or_stop(db_client, autonomous_data_warehouse, autonomous_data_warehouse_id, module): result = dict() idempotent_lifecycle_state = [] target_state = [] lifecycle_func = None state = module.params.get("state") if state == "start": idempotent_lifecycle_state = ["AVAILABLE", "STARTING"] target_state = ["AVAILABLE"] lifecycle_func = db_client.start_autonomous_data_warehouse elif state == "stop": idempotent_lifecycle_state = ["STOPPED", "STOPPING"] target_state = ["STOPPED"] lifecycle_func = db_client.stop_autonomous_data_warehouse if autonomous_data_warehouse.lifecycle_state not in idempotent_lifecycle_state: result = oci_db_utils.execute_function_and_wait( resource_type="autonomous_data_warehouse", function=lifecycle_func, kwargs_function={ "autonomous_data_warehouse_id": autonomous_data_warehouse_id }, client=db_client, get_fn=db_client.get_autonomous_data_warehouse, get_param="autonomous_data_warehouse_id", module=module, states=target_state, ) else: result["autonomous_data_warehouse"] = to_dict( autonomous_data_warehouse) result["changed"] = False return result
def perform_start_or_stop(db_client, autonomous_database, autonomous_database_id, module): result = dict() idempotent_lifecycle_state = [] target_state = [] lifecycle_func = None state = module.params.get('state') if state == 'start': idempotent_lifecycle_state = ['AVAILABLE', 'STARTING'] target_state = ['AVAILABLE'] lifecycle_func = db_client.start_autonomous_database elif state == 'stop': idempotent_lifecycle_state = ['STOPPED', 'STOPPING'] target_state = ['STOPPED'] lifecycle_func = db_client.stop_autonomous_database if autonomous_database.lifecycle_state not in idempotent_lifecycle_state: result = oci_db_utils.execute_function_and_wait( resource_type='autonomous_database', function=lifecycle_func, kwargs_function={'autonomous_database_id': autonomous_database_id}, client=db_client, get_fn=db_client.get_autonomous_database, get_param='autonomous_database_id', module=module, states=target_state) else: result['autonomous_database'] = to_dict(autonomous_database) result['changed'] = False return result
def db_node_action(db_client, module, existing_db_node): result = dict() input_action = module.params.get("state") action_map = { "stop": "STOP", "start": "START", "reset": "RESET", "softreset": "SOFTRESET", } desired_lifecycle_states = { "stop": "STOPPED", "start": "AVAILABLE", "reset": "AVAILABLE", "softreset": "AVAILABLE", } intermediate_states = { "stop": "STOPPING", "start": "STARTING", "reset": "STOPPING", "softreset": "STOPPING", } logger.debug( "Attempting to change the state of DB Node %s from %s to %s", existing_db_node.id, existing_db_node.lifecycle_state, desired_lifecycle_states[input_action], ) logger.debug( "Current state of the DB Node %s is %s", existing_db_node.id, existing_db_node.lifecycle_state, ) if (existing_db_node.lifecycle_state != desired_lifecycle_states[input_action] and existing_db_node.lifecycle_state != intermediate_states[input_action]) or (input_action in ("reset", "softreset")): logger.info( "Changing state of DB Node %s from %s to %s", existing_db_node.id, existing_db_node.lifecycle_state, desired_lifecycle_states[input_action], ) result = oci_db_utils.execute_function_and_wait( resource_type="db_node", function=db_client.db_node_action, kwargs_function={ "db_node_id": existing_db_node.id, "action": action_map[input_action], }, client=db_client, get_fn=db_client.get_db_node, get_param="db_node_id", module=module, ) else: result["db_node"] = to_dict(existing_db_node) result["changed"] = False return result
def db_node_action(db_client, module, existing_db_node): result = dict() input_action = module.params.get('state') action_map = { "stop": "STOP", "start": "START", "reset": "RESET", "softreset": "SOFTRESET" } desired_lifecycle_states = { "stop": "STOPPED", "start": "AVAILABLE", "reset": "AVAILABLE", "softreset": "AVAILABLE" } intermediate_states = { "stop": "STOPPING", "start": "STARTING", "reset": "STOPPING", "softreset": "STOPPING" } logger.debug("Attempting to change the state of DB Node %s from %s to %s", existing_db_node.id, existing_db_node.lifecycle_state, desired_lifecycle_states[input_action]) logger.debug("Current state of the DB Node %s is %s", existing_db_node.id, existing_db_node.lifecycle_state) if (existing_db_node.lifecycle_state != desired_lifecycle_states[input_action] and existing_db_node.lifecycle_state != intermediate_states[input_action]) or ( input_action == 'reset' or input_action == 'softreset'): logger.info("Changing state of DB Node %s from %s to %s", existing_db_node.id, existing_db_node.lifecycle_state, desired_lifecycle_states[input_action]) result = oci_db_utils.execute_function_and_wait( resource_type='db_node', function=db_client.db_node_action, kwargs_function={ 'db_node_id': existing_db_node.id, 'action': action_map[input_action] }, client=db_client, get_fn=db_client.get_db_node, get_param='db_node_id', module=module) else: result['db_node'] = to_dict(existing_db_node) result['changed'] = False return result
def perform_data_guard_operations(db_client, module): changed = False result = dict(changed=False, data_guard_association="") data_guard_association_id = module.params.get("data_guard_association_id") database_id = module.params.get("database_id") if data_guard_association_id is None or database_id is None: module.fail_json( msg= "Data Guard Association related operation must contain valid database_id and data_guard_association_id" ) data_guard_association = oci_utils.get_existing_resource( db_client.get_data_guard_association, module, database_id=database_id, data_guard_association_id=data_guard_association_id, ) changed, target_fn, kwargs = get_operation_details(db_client, module, data_guard_association) if changed: kwargs.update(database_id=database_id, data_guard_association_id=data_guard_association_id) try: result = oci_db_utils.execute_function_and_wait( resource_type="data_guard_association", function=target_fn, kwargs_function=kwargs, client=db_client, get_fn=db_client.get_data_guard_association, get_param=None, kwargs_get={ "database_id": database_id, "data_guard_association_id": data_guard_association_id, }, module=module, ) except ServiceError as ex: get_logger().error( "Unable to perform operation on Data Guard Association due to: %s", ex.message, ) module.fail_json(msg=ex.message) result["changed"] = changed result["data_guard_association"] = to_dict(data_guard_association) return result
def restore_database(db_client, module): result = dict(changed=True, database="") database_id = module.params.get("database_id") restore_database_details = RestoreDatabaseDetails() for attribute in restore_database_details.attribute_map: restore_database_details.__setattr__(attribute, module.params.get(attribute)) result = oci_db_utils.execute_function_and_wait( resource_type="database", function=db_client.restore_database, kwargs_function={ "database_id": database_id, "restore_database_details": restore_database_details, }, client=db_client, get_fn=db_client.get_database, get_param="database_id", module=module, ) return result
def restore_database(db_client, module): result = dict(changed=True, database='') database_id = module.params.get('database_id') restore_database_details = RestoreDatabaseDetails() for attribute in restore_database_details.attribute_map: restore_database_details.__setattr__(attribute, module.params.get(attribute)) result = oci_db_utils.execute_function_and_wait( resource_type='database', function=db_client.restore_database, kwargs_function={ 'database_id': database_id, 'restore_database_details': restore_database_details }, client=db_client, get_fn=db_client.get_database, get_param='database_id', module=module) return result
def restore_autonomous_database(db_client, module): result = dict(changed=True, autonomous_database='') autonomous_database_id = module.params.get('autonomous_database_id') restore_autonomous_database_details = RestoreAutonomousDatabaseDetails() for attribute in restore_autonomous_database_details.attribute_map: restore_autonomous_database_details.__setattr__( attribute, module.params.get(attribute)) result = oci_db_utils.execute_function_and_wait( resource_type='autonomous_database', function=db_client.restore_autonomous_database, kwargs_function={ 'autonomous_database_id': autonomous_database_id, 'restore_autonomous_database_details': restore_autonomous_database_details }, client=db_client, get_fn=db_client.get_autonomous_database, get_param='autonomous_database_id', module=module, states=['AVAILABLE', 'FAILED']) return result