def update_user_description_and_tags(identity_client, existing_user, module): changed = False attributes_to_compare = ["description", "defined_tags", "freeform_tags"] update_user_details = UpdateUserDetails() for attribute in attributes_to_compare: changed = oci_utils.check_and_update_attributes( update_user_details, attribute, module.params.get(attribute), getattr(existing_user, attribute), changed, ) if changed: result = oci_utils.update_and_wait( resource_type="user", update_fn=identity_client.update_user, kwargs_update={ "user_id": existing_user.id, "update_user_details": update_user_details, }, client=identity_client, get_fn=identity_client.get_user, get_param="user_id", module=module, ) existing_user = result["user"] changed = result["changed"] return existing_user, changed
def update_backend(lb_client, module, backend, lb_id, backend_set_name): changed = False result = dict(changed=changed, backend=to_dict(backend)) backend_name = oci_lb_utils.get_backend_name(module) get_logger().info("Updating backend %s for backendset %s in load balancer %s", backend_name, backend_set_name, lb_id) update_backend_details = UpdateBackendDetails() for attribute in update_backend_details.attribute_map: changed = oci_utils.check_and_update_attributes( update_backend_details, attribute, module.params.get( attribute, None), getattr(backend, attribute), changed) get_logger().debug("Existing backend property values: %s, input property values: %s", backend, update_backend_details) if changed: result = oci_lb_utils.create_or_update_lb_resources_and_wait(resource_type="backend", function=lb_client.update_backend, kwargs_function={ 'update_backend_details': update_backend_details, 'load_balancer_id': lb_id, 'backend_set_name': backend_set_name, 'backend_name': backend_name}, lb_client=lb_client, get_fn=lb_client.get_backend, kwargs_get={'load_balancer_id': lb_id, 'backend_set_name': backend_set_name, 'backend_name': backend_name}, module=module ) get_logger().info("Successfully updated backend %s for backendset %s in load balancer %s", backend_name, backend_set_name, lb_id) else: get_logger().info("No update to the backend %s for backendset %s in load balancer %s as no " + "attribute changed", backend_name, backend_set_name, lb_id) return result
def update_hostname(lb_client, module, lb_id, hostname, name): result = dict(hostname=to_dict(hostname), changed=False) update_hostname_details = UpdateHostnameDetails() get_logger().info("Updating hostname %s in the load balancer %s", name, lb_id) changed = False changed = oci_utils.check_and_update_attributes( update_hostname_details, 'hostname', module.params.get('hostname'), hostname.hostname, changed) if changed: result = oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type="hostname", function=lb_client.update_hostname, kwargs_function={ 'update_hostname_details': update_hostname_details, 'load_balancer_id': lb_id, 'name': name }, lb_client=lb_client, get_fn=lb_client.get_hostname, kwargs_get={ 'load_balancer_id': lb_id, 'name': name }, module=module) get_logger().info( "Successfully updated hostname %s in load balancer %s", hostname, lb_id) return result
def update_route_table(virtual_network_client, existing_route_table, module): if existing_route_table is None: raise ClientError( Exception( "No Route Table with id " + module.params.get("rt_id") + " is found for update" ) ) result = dict(route_table=to_dict(existing_route_table), changed=False) input_route_rules = module.params.get("route_rules") purge_route_rules = module.params["purge_route_rules"] delete_route_rules = module.params["delete_route_rules"] name_tag_changed = False route_rules_changed = False existing_route_rules = existing_route_table.route_rules update_route_table_details = UpdateRouteTableDetails() attributes_to_compare = ["display_name", "freeform_tags", "defined_tags"] for attribute in attributes_to_compare: name_tag_changed = oci_utils.check_and_update_attributes( update_route_table_details, attribute, module.params.get(attribute), getattr(existing_route_table, attribute), name_tag_changed, ) if input_route_rules is not None: if input_route_rules: route_rules_object_list = get_route_rules(input_route_rules) route_rules, route_rules_changed = oci_utils.get_component_list_difference( get_hashed_route_rules(route_rules_object_list), get_hashed_route_rules(existing_route_rules), purge_route_rules, delete_route_rules, ) else: route_rules = [] route_rules_changed = True if route_rules_changed: update_route_table_details.route_rules = route_rules else: update_route_table_details.route_rules = existing_route_rules if name_tag_changed or route_rules_changed: result = oci_utils.update_and_wait( resource_type="route_table", update_fn=virtual_network_client.update_route_table, kwargs_update={ "rt_id": existing_route_table.id, "update_route_table_details": update_route_table_details, }, client=virtual_network_client, get_fn=virtual_network_client.get_route_table, get_param="rt_id", module=module, ) return result
def update_database(db_client, module): database_id = module.params.get("database_id") input_auto_backup_enabled = False existing_database = oci_utils.get_existing_resource( db_client.get_database, module, database_id=module.params.get("database_id") ) if existing_database is None: module.fail_json( msg="No Database with id " + database_id + "is found for update." ) result = dict(database=to_dict(existing_database), changed=False) update_database_details = UpdateDatabaseDetails() changed = False db_backup_config_changed = False attributes_to_compare = ["freeform_tags", "defined_tags"] for attribute in attributes_to_compare: changed = oci_utils.check_and_update_attributes( update_database_details, attribute, module.params.get(attribute), getattr(existing_database, attribute), changed, ) input_db_backup_config = module.params.get("db_backup_config") if input_db_backup_config is not None: input_auto_backup_enabled = input_db_backup_config.get( "auto_backup_enabled", False ) if ( existing_database.db_backup_config is None or existing_database.db_backup_config.auto_backup_enabled != input_auto_backup_enabled ): db_backup_config = DbBackupConfig() db_backup_config.auto_backup_enabled = input_auto_backup_enabled update_database_details.db_backup_config = db_backup_config db_backup_config_changed = True if changed or db_backup_config_changed: db_backup_config = DbBackupConfig() db_backup_config.auto_backup_enabled = input_auto_backup_enabled update_database_details.db_backup_config = db_backup_config result = oci_utils.update_and_wait( resource_type="database", update_fn=db_client.update_database, kwargs_update={ "database_id": database_id, "update_database_details": update_database_details, }, client=db_client, get_fn=db_client.get_database, get_param="database_id", module=module, ) return result
def update_health_checker(lb_client, module): health_checker = None result = dict(changed=False, health_checker='') lb_id = module.params.get('load_balancer_id') backend_set_name = module.params.get('backend_set_name') health_checker = oci_utils.get_existing_resource( lb_client.get_health_checker, module, load_balancer_id=lb_id, backend_set_name=backend_set_name) if health_checker: changed = False result = dict(health_checker=to_dict(health_checker), changed=changed) get_logger().info( "Updating healtch checker details for backendset %s in load balancer %s", backend_set_name, lb_id) input_health_checker = UpdateHealthCheckerDetails() for attribute in input_health_checker.attribute_map: input_attribute_value = module.params.get(attribute) changed = oci_utils.check_and_update_attributes( input_health_checker, attribute, input_attribute_value, getattr(health_checker, attribute), changed) get_logger().debug( "Existing health checker property values: %s, input property values: %s", health_checker, input_health_checker) if changed: result = oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type="health_checker", function=lb_client.update_health_checker, kwargs_function={ 'health_checker': input_health_checker, 'load_balancer_id': lb_id, 'backend_set_name': backend_set_name }, lb_client=lb_client, get_fn=lb_client.get_health_checker, kwargs_get={ 'load_balancer_id': lb_id, 'backend_set_name': backend_set_name }, module=module) get_logger().info( "Updating health checker details for backendset %s in load balancer %s", backend_set_name, lb_id) else: get_logger().info( "No update to the health checker details for backendset %s in load balancer %s as " + "no attribute changed", backend_set_name, lb_id) return result
def update_dhcp_options(virtual_network_client, existing_dhcp_options, module): if existing_dhcp_options is None: raise ClientError( Exception("No Dhcp Options with id " + module.params.get("dhcp_id") + " is found for update")) result = dict(dhcp_options=to_dict(existing_dhcp_options), changed=False) name_tag_changed = False options_changed = False input_options = module.params.get("options") update_dhcp_details = UpdateDhcpDetails() existing_options = existing_dhcp_options.options attributes_to_compare = ["display_name", "freeform_tags", "defined_tags"] for attribute in attributes_to_compare: name_tag_changed = oci_utils.check_and_update_attributes( update_dhcp_details, attribute, module.params.get(attribute), getattr(existing_dhcp_options, attribute), name_tag_changed, ) if input_options is not None: if input_options: options, options_changed = oci_utils.get_component_list_difference( get_options_objects(input_options), get_hashed_options(existing_options), module.params.get("purge_dhcp_options"), module.params.get("delete_dhcp_options"), ) if options_changed: update_dhcp_details.options = options else: update_dhcp_details.options = existing_options if name_tag_changed or options_changed: result = oci_utils.update_and_wait( resource_type="dhcp_options", update_fn=virtual_network_client.update_dhcp_options, kwargs_update={ "dhcp_id": existing_dhcp_options.id, "update_dhcp_details": update_dhcp_details, }, client=virtual_network_client, get_fn=virtual_network_client.get_dhcp_options, get_param="dhcp_id", module=module, ) return result
def update_route_table(virtual_network_client, existing_route_table, module): if existing_route_table is None: raise ClientError( Exception("No Route Table with id " + module.params.get('rt_id') + " is found for update")) result = dict(route_table=to_dict(existing_route_table), changed=False) input_route_rules = module.params.get('route_rules') purge_route_rules = module.params['purge_route_rules'] name_tag_changed = False route_rules_changed = False existing_route_rules = existing_route_table.route_rules update_route_table_details = UpdateRouteTableDetails() attributes_to_compare = ['display_name', 'freeform_tags', 'defined_tags'] for attribute in attributes_to_compare: name_tag_changed = oci_utils.check_and_update_attributes( update_route_table_details, attribute, module.params.get(attribute), getattr(existing_route_table, attribute), name_tag_changed) if input_route_rules is not None: if input_route_rules: route_rules_object_list = get_route_rules(input_route_rules) route_rules, route_rules_changed = get_route_rules_difference( route_rules_object_list, existing_route_rules, purge_route_rules) else: route_rules = [] route_rules_changed = True if route_rules_changed: update_route_table_details.route_rules = route_rules else: update_route_table_details.route_rules = existing_route_rules if name_tag_changed or route_rules_changed: result = oci_utils.update_and_wait( resource_type='route_table', update_fn=virtual_network_client.update_route_table, kwargs_update={ 'rt_id': existing_route_table.id, 'update_route_table_details': update_route_table_details }, client=virtual_network_client, get_fn=virtual_network_client.get_route_table, get_param='rt_id', module=module) return result
def update_database(db_client, module): database_id = module.params.get('database_id') input_auto_backup_enabled = False existing_database = oci_utils.get_existing_resource( db_client.get_database, module, database_id=module.params.get('database_id')) if existing_database is None: module.fail_json(msg='No Database with id ' + database_id + 'is found for update.') result = dict(database=to_dict(existing_database), changed=False) update_database_details = UpdateDatabaseDetails() changed = False db_backup_config_changed = False attributes_to_compare = ['freeform_tags', 'defined_tags'] for attribute in attributes_to_compare: changed = oci_utils.check_and_update_attributes( update_database_details, attribute, module.params.get(attribute), getattr(existing_database, attribute), changed) input_db_backup_config = module.params.get('db_backup_config') if input_db_backup_config is not None: input_auto_backup_enabled = input_db_backup_config.get( 'auto_backup_enabled', False) if existing_database.db_backup_config.auto_backup_enabled != input_auto_backup_enabled: db_backup_config = DbBackupConfig() db_backup_config.auto_backup_enabled = input_auto_backup_enabled update_database_details.db_backup_config = db_backup_config db_backup_config_changed = True if changed or db_backup_config_changed: db_backup_config = DbBackupConfig() db_backup_config.auto_backup_enabled = input_auto_backup_enabled update_database_details.db_backup_config = db_backup_config result = oci_utils.update_and_wait(resource_type='database', update_fn=db_client.update_database, kwargs_update={ 'database_id': database_id, 'update_database_details': update_database_details }, client=db_client, get_fn=db_client.get_database, get_param='database_id', module=module) return result
def update_health_checker(lb_client, module): health_checker = None result = dict( changed=False, health_checker='' ) load_balancer_id = module.params.get('load_balancer_id') backend_set_name = module.params.get('backend_set_name') health_checker = get_existing_health_checker( lb_client, module, load_balancer_id, backend_set_name) try: if health_checker: changed = False get_logger().info("Updating healtch checker details for backendset %s in load balancer %s", backend_set_name, load_balancer_id) input_health_checker = UpdateHealthCheckerDetails() for attribute in input_health_checker.attribute_map.keys(): input_attribute_value = module.params.get(attribute) changed = oci_utils.check_and_update_attributes( input_health_checker, attribute, input_attribute_value, getattr(health_checker, attribute), changed) get_logger().debug("Existing health checker property values: %s, input property values: %s", health_checker, input_health_checker) if changed: response = oci_utils.call_with_backoff(lb_client.update_health_checker, health_checker=input_health_checker, load_balancer_id=load_balancer_id, backend_set_name=backend_set_name) oci_lb_utils.verify_work_request(lb_client, response) health_checker = get_existing_health_checker( lb_client, module, load_balancer_id, backend_set_name) get_logger().info("Successfully updated health checker for backendset %s \ in load balancer %s", backend_set_name, load_balancer_id) except ServiceError as ex: get_logger().error("Unable to create/update listener due to: %s", ex.message) module.fail_json(msg=ex.message) except ClientError as ex: get_logger().error("Unable to create/update listener due to: %s", str(ex)) module.fail_json(msg=str(ex)) result['changed'] = changed result['health_checker'] = to_dict(health_checker) return result
def update_dhcp_options(virtual_network_client, existing_dhcp_options, module): if existing_dhcp_options is None: raise ClientError( Exception("No Dhcp Options with id " + module.params.get('dhcp_id') + " is found for update")) result = dict(dhcp_options=to_dict(existing_dhcp_options), changed=False) name_tag_changed = False options_changed = False input_options = module.params.get('options') update_dhcp_details = UpdateDhcpDetails() existing_options = existing_dhcp_options.options attributes_to_compare = ['display_name', 'freeform_tags', 'defined_tags'] for attribute in attributes_to_compare: name_tag_changed = oci_utils.check_and_update_attributes( update_dhcp_details, attribute, module.params.get(attribute), getattr(existing_dhcp_options, attribute), name_tag_changed) if input_options is not None: if input_options: options, options_changed = get_options_difference( get_options_objects(input_options), existing_options, module.params.get('purge_dhcp_options')) if options_changed: update_dhcp_details.options = options else: update_dhcp_details.options = existing_options if name_tag_changed or options_changed: result = oci_utils.update_and_wait( resource_type='dhcp_options', update_fn=virtual_network_client.update_dhcp_options, kwargs_update={ 'dhcp_id': existing_dhcp_options.id, 'update_dhcp_details': update_dhcp_details }, client=virtual_network_client, get_fn=virtual_network_client.get_dhcp_options, get_param='dhcp_id', module=module) return result
def update_user_description_and_tags(identity_client, existing_user, module): changed = False attributes_to_compare = ['description', 'defined_tags', 'freeform_tags'] update_user_details = UpdateUserDetails() for attribute in attributes_to_compare: changed = oci_utils.check_and_update_attributes(update_user_details, attribute, module.params.get( attribute), getattr(existing_user, attribute), changed) if changed: result = oci_utils.update_and_wait(resource_type='user', update_fn=identity_client.update_user, kwargs_update={ 'user_id': existing_user.id, 'update_user_details': update_user_details}, client=identity_client, get_fn=identity_client.get_user, get_param='user_id', module=module ) existing_user = result['user'] changed = result['changed'] return existing_user, changed
def update_hostname(lb_client, module, lb_id, hostname, name): result = dict(hostname=to_dict(hostname), changed=False) update_hostname_details = UpdateHostnameDetails() get_logger().info("Updating hostname %s in the load balancer %s", name, lb_id) changed = False changed = oci_utils.check_and_update_attributes( update_hostname_details, "hostname", module.params.get("hostname"), hostname.hostname, changed, ) if changed: result = oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type="hostname", function=lb_client.update_hostname, kwargs_function={ "update_hostname_details": update_hostname_details, "load_balancer_id": lb_id, "name": name, }, lb_client=lb_client, get_fn=lb_client.get_hostname, kwargs_get={"load_balancer_id": lb_id, "name": name}, module=module, ) get_logger().info( "Successfully updated hostname %s in load balancer %s", hostname, lb_id ) else: get_logger().info( "No update to the hostname %s in load balancer %s as no attribute changed", hostname, lb_id, ) return result
def update_security_list(virtual_network_client, existing_security_list, module): if existing_security_list is None: raise ClientError( Exception("No Security List with id " + module.params.get('security_list_id') + " is found for update")) result = dict(security_list=to_dict(existing_security_list), changed=False) input_ingress_security_rules = module.params.get('ingress_security_rules') input_egress_security_rules = module.params.get('egress_security_rules') purge_security_rules = module.params.get('purge_security_rules') name_tag_changed = False egress_security_rules_changed = False ingress_security_rules_changed = False update_security_list_details = UpdateSecurityListDetails() existing_egress_security_rule = existing_security_list.egress_security_rules existing_ingress_security_rule = existing_security_list.ingress_security_rules attributes_to_compare = ['display_name', 'freeform_tags', 'defined_tags'] for attribute in attributes_to_compare: name_tag_changed = oci_utils.check_and_update_attributes( update_security_list_details, attribute, module.params.get(attribute), getattr(existing_security_list, attribute), name_tag_changed) if input_egress_security_rules is not None: input_egress_security_rules = get_security_rules( 'egress_security_rules', input_egress_security_rules) egress_security_rules, egress_security_rules_changed = oci_utils.check_and_return_component_list_difference( input_egress_security_rules, get_hashed_security_rules('egress_security_rules', existing_egress_security_rule), purge_security_rules) if input_ingress_security_rules is not None: input_ingress_security_rules = get_security_rules( 'ingress_security_rules', input_ingress_security_rules) ingress_security_rules, ingress_security_rules_changed = oci_utils.check_and_return_component_list_difference( input_ingress_security_rules, get_hashed_security_rules('ingress_security_rules', existing_ingress_security_rule), purge_security_rules) if egress_security_rules_changed: update_security_list_details.egress_security_rules = egress_security_rules else: update_security_list_details.egress_security_rules = existing_egress_security_rule if ingress_security_rules_changed: update_security_list_details.ingress_security_rules = ingress_security_rules else: update_security_list_details.ingress_security_rules = existing_ingress_security_rule if name_tag_changed or (egress_security_rules_changed or ingress_security_rules_changed): result = oci_utils.update_and_wait( resource_type='security_list', update_fn=virtual_network_client.update_security_list, kwargs_update={ 'security_list_id': existing_security_list.id, 'update_security_list_details': update_security_list_details }, client=virtual_network_client, get_fn=virtual_network_client.get_security_list, get_param='security_list_id', module=module) return result
def update_virtual_circuit(virtual_network_client, existing_virtual_circuit, module): result = dict(virtual_circuit=to_dict(existing_virtual_circuit), changed=False) attributes_changed = False cross_connect_mappings_changed = False update_virtual_circuit_details = UpdateVirtualCircuitDetails() for attribute in update_virtual_circuit_details.attribute_map: if attribute != "cross_connect_mappings": attributes_changed = oci_utils.check_and_update_attributes( update_virtual_circuit_details, attribute, module.params.get(attribute), getattr(existing_virtual_circuit, attribute), attributes_changed, ) purge_cross_connect_mappings = module.params.get( "purge_cross_connect_mappings", True) delete_cross_connect_mappings = module.params.get( "delete_cross_connect_mappings") input_cross_connect_mappings = get_cross_connect_mappings(module) existing_cross_connect_mappings = oci_utils.get_hashed_object_list( CrossConnectMapping, existing_virtual_circuit.cross_connect_mappings) if existing_virtual_circuit.type == "PUBLIC": remove_assigned_bgp_peering_ips(existing_cross_connect_mappings) if input_cross_connect_mappings is not None: cross_connect_mappings, cross_connect_mappings_changed = oci_utils.check_and_return_component_list_difference( input_cross_connect_mappings, existing_cross_connect_mappings, purge_cross_connect_mappings, delete_cross_connect_mappings, ) if cross_connect_mappings_changed: update_virtual_circuit_details.cross_connect_mappings = cross_connect_mappings else: update_virtual_circuit_details.cross_connect_mappings = ( existing_cross_connect_mappings) if attributes_changed or cross_connect_mappings_changed: result = oci_utils.update_and_wait( resource_type="virtual_circuit", update_fn=virtual_network_client.update_virtual_circuit, kwargs_update={ "update_virtual_circuit_details": update_virtual_circuit_details, "virtual_circuit_id": existing_virtual_circuit.id, }, client=virtual_network_client, get_fn=virtual_network_client.get_virtual_circuit, get_param="virtual_circuit_id", module=module, ) if module.params.get("public_prefixes") is not None: result = bulk_add_or_delete_public_prefixes( get_public_prefixes(module), virtual_network_client, existing_virtual_circuit.id, module, ) return result
def update_security_list(virtual_network_client, existing_security_list, module): if existing_security_list is None: raise ClientError( Exception( "No Security List with id " + module.params.get("security_list_id") + " is found for update" ) ) result = dict(security_list=to_dict(existing_security_list), changed=False) input_ingress_security_rules = module.params.get("ingress_security_rules") input_egress_security_rules = module.params.get("egress_security_rules") purge_security_rules = module.params.get("purge_security_rules") delete_security_rules = module.params.get("delete_security_rules") name_tag_changed = False egress_security_rules_changed = False ingress_security_rules_changed = False update_security_list_details = UpdateSecurityListDetails() existing_egress_security_rule = existing_security_list.egress_security_rules existing_ingress_security_rule = existing_security_list.ingress_security_rules attributes_to_compare = ["display_name", "freeform_tags", "defined_tags"] for attribute in attributes_to_compare: name_tag_changed = oci_utils.check_and_update_attributes( update_security_list_details, attribute, module.params.get(attribute), getattr(existing_security_list, attribute), name_tag_changed, ) if input_egress_security_rules is not None: input_egress_security_rules = get_security_rules( "egress_security_rules", input_egress_security_rules ) ( egress_security_rules, egress_security_rules_changed, ) = oci_utils.check_and_return_component_list_difference( input_egress_security_rules, get_hashed_security_rules( "egress_security_rules", existing_egress_security_rule ), purge_security_rules, delete_security_rules, ) if input_ingress_security_rules is not None: input_ingress_security_rules = get_security_rules( "ingress_security_rules", input_ingress_security_rules ) ( ingress_security_rules, ingress_security_rules_changed, ) = oci_utils.check_and_return_component_list_difference( input_ingress_security_rules, get_hashed_security_rules( "ingress_security_rules", existing_ingress_security_rule ), purge_security_rules, delete_security_rules, ) if egress_security_rules_changed: update_security_list_details.egress_security_rules = egress_security_rules else: update_security_list_details.egress_security_rules = ( existing_egress_security_rule ) if ingress_security_rules_changed: update_security_list_details.ingress_security_rules = ingress_security_rules else: update_security_list_details.ingress_security_rules = ( existing_ingress_security_rule ) if name_tag_changed or ( egress_security_rules_changed or ingress_security_rules_changed ): result = oci_utils.update_and_wait( resource_type="security_list", update_fn=virtual_network_client.update_security_list, kwargs_update={ "security_list_id": existing_security_list.id, "update_security_list_details": update_security_list_details, }, client=virtual_network_client, get_fn=virtual_network_client.get_security_list, get_param="security_list_id", module=module, ) return result
def update_db_system(db_client, module, db_system_id): result = dict() changed = False db_system = oci_utils.get_existing_resource( db_client.get_db_system, module, db_system_id=module.params.get('db_system_id')) if db_system is None: raise ClientError( Exception("No DB System with id " + db_system_id + " is found for update")) primitive_attributes = [ 'cpu_core_count', 'data_storage_size_in_gbs', 'freeform_tags', 'defined_tags' ] existing_ssh_public_keys = db_system.ssh_public_keys last_patch_history_entry_id = db_system.last_patch_history_entry_id purge_ssh_public_keys = module.params.get('purge_ssh_public_keys') update_db_system_details = UpdateDbSystemDetails() for attribute in primitive_attributes: changed = oci_utils.check_and_update_attributes( update_db_system_details, attribute, module.params.get(attribute, None), getattr(db_system, attribute), changed) input_ssh_public_keys = create_ssh_public_keys( module.params.get('ssh_public_keys', None)) ssh_public_keys_changed = False if input_ssh_public_keys is not None: ssh_public_keys, ssh_public_keys_changed = oci_utils.get_component_list_difference( input_ssh_public_keys, existing_ssh_public_keys, purge_ssh_public_keys) if ssh_public_keys_changed: update_db_system_details.ssh_public_keys = ssh_public_keys else: update_db_system_details.ssh_public_keys = existing_ssh_public_keys input_version_dict = module.params.get('version', None) version_changed, patch_details = oci_db_utils.is_version_changed( db_client.get_db_system_patch_history_entry, db_client.get_db_system_patch, db_system.version, input_version_dict, last_patch_history_entry_id, db_system_id=db_system_id) if version_changed: update_db_system_details.version = patch_details changed = changed or ssh_public_keys_changed or version_changed if changed: result = oci_utils.update_and_wait( resource_type='db_system', update_fn=db_client.update_db_system, kwargs_update={ 'db_system_id': db_system_id, 'update_db_system_details': update_db_system_details }, client=db_client, get_fn=db_client.get_db_system, get_param='db_system_id', module=module) else: result['db_system'] = to_dict(db_system) result['changed'] = False return result
def update_backend_set(lb_client, module, lb_id, backend_set, name): result = dict(backend_set=to_dict(backend_set), changed=False) update_backend_set_details = UpdateBackendSetDetails() purge_backends = module.params.get('purge_backends') input_backends = oci_lb_utils.create_backends( module.params.get('backends', None)) existing_backends = oci_utils.get_hashed_object_list( BackendDetails, backend_set.backends) get_logger().info("Updating backend set %s in the load balancer %s", name, lb_id) backends_changed = False if input_backends is not None: backends, backends_changed = oci_utils.check_and_return_component_list_difference( input_backends, existing_backends, purge_backends) if backends_changed: update_backend_set_details.backends = backends else: update_backend_set_details.backends = existing_backends input_health_checker = oci_lb_utils.create_health_checker( module.params.get('health_checker')) health_checker_changed = oci_utils.update_class_type_attr_difference( update_backend_set_details, backend_set, 'health_checker', HealthCheckerDetails, input_health_checker) policy_changed = oci_utils.check_and_update_attributes( update_backend_set_details, 'policy', module.params.get('policy'), backend_set.policy, False) input_session_persistence_configuration = oci_lb_utils.create_session_persistence_configuration( module.params.get('session_persistence_configuration', None)) session_persistence_configuration_changed = oci_utils.update_class_type_attr_difference( update_backend_set_details, backend_set, 'session_persistence_configuration', SessionPersistenceConfigurationDetails, input_session_persistence_configuration) input_ssl_configuration = oci_lb_utils.create_ssl_configuration( module.params.get('ssl_configuration', None)) ssl_configuration_changed = oci_utils.update_class_type_attr_difference( update_backend_set_details, backend_set, 'ssl_configuration', SSLConfigurationDetails, input_ssl_configuration) changed = backends_changed or health_checker_changed or policy_changed or \ session_persistence_configuration_changed or ssl_configuration_changed if changed: result = oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type="backend_set", function=lb_client.update_backend_set, kwargs_function={ 'update_backend_set_details': update_backend_set_details, 'load_balancer_id': lb_id, 'backend_set_name': name }, lb_client=lb_client, get_fn=lb_client.get_backend_set, kwargs_get={ 'load_balancer_id': lb_id, 'backend_set_name': name }, module=module) get_logger().info( "Successfully updated backend set %s in the load balancer %s", name, lb_id) else: get_logger().info( "No update on backend set %s in the load balancer %s as no attribute changed", name, lb_id) return result
def update_listener(lb_client, module, listener, lb_id, name): result = dict(listener=to_dict(listener), changed=False) update_listener_details = UpdateListenerDetails() changed = False get_logger().info("Updating listener %s in load balancer %s", name, lb_id) for attribute in update_listener_details.attribute_map.keys(): if attribute not in [ 'ssl_configuration', 'connection_configuration', 'hostname_names' ]: changed = oci_utils.check_and_update_attributes( update_listener_details, attribute, module.params.get(attribute, None), getattr(listener, attribute), changed) input_ssl_configuration = oci_lb_utils.create_ssl_configuration( module.params.get('ssl_configuration', None)) existing_ssl_configuration = oci_utils.get_hashed_object( SSLConfigurationDetails, listener.ssl_configuration) ssl_configuration_changed = oci_utils.check_and_update_attributes( update_listener_details, 'ssl_configuration', input_ssl_configuration, existing_ssl_configuration, False) input_connection_configuration = oci_lb_utils.create_connection_configuration( module.params.get('connection_configuration', None)) existing_connection_configuration = oci_utils.get_hashed_object( ConnectionConfiguration, listener.connection_configuration) connection_configuration_changed = oci_utils.check_and_update_attributes( update_listener_details, 'connection_configuration', input_connection_configuration, existing_connection_configuration, False) input_hostname_names = module.params.get('hostname_names', None) update_listener_details.hostname_names = listener.hostname_names hostname_names_changed = False if input_hostname_names is not None: changed_hostname_names, hostname_names_changed = oci_lb_utils.check_and_return_component_list_difference( input_hostname_names, listener.hostname_names, module.params.get('purge_hostname_names')) if hostname_names_changed: update_listener_details.hostname_names = changed_hostname_names changed = changed or ssl_configuration_changed or connection_configuration_changed or hostname_names_changed get_logger().debug( "Existing listener property values: %s, input property values: %s", listener, update_listener_details) if changed: result = oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type='listener', function=lb_client.update_listener, kwargs_function={ 'update_listener_details': update_listener_details, 'load_balancer_id': lb_id, 'listener_name': name }, lb_client=lb_client, get_sub_resource_fn=oci_lb_utils.get_listener, kwargs_get={ 'lb_client': lb_client, 'module': module, 'load_balancer_id': lb_id, 'name': name }, module=module) return result
def update_db_system(db_client, module, db_system_id): result = dict() changed = False db_system = oci_utils.get_existing_resource( db_client.get_db_system, module, db_system_id=module.params.get("db_system_id")) if db_system is None: raise ClientError( Exception("No DB System with id " + db_system_id + " is found for update")) primitive_attributes = [ "cpu_core_count", "data_storage_size_in_gbs", "freeform_tags", "defined_tags", ] existing_ssh_public_keys = db_system.ssh_public_keys last_patch_history_entry_id = db_system.last_patch_history_entry_id purge_ssh_public_keys = module.params.get("purge_ssh_public_keys") delete_ssh_public_keys = module.params.get("delete_ssh_public_keys") update_db_system_details = UpdateDbSystemDetails() for attribute in primitive_attributes: changed = oci_utils.check_and_update_attributes( update_db_system_details, attribute, module.params.get(attribute, None), getattr(db_system, attribute), changed, ) input_ssh_public_keys = create_ssh_public_keys( module.params.get("ssh_public_keys", None)) ssh_public_keys_changed = False if input_ssh_public_keys is not None: ( ssh_public_keys, ssh_public_keys_changed, ) = oci_utils.get_component_list_difference( input_ssh_public_keys, existing_ssh_public_keys, purge_ssh_public_keys, delete_ssh_public_keys, ) if ssh_public_keys_changed: update_db_system_details.ssh_public_keys = ssh_public_keys else: update_db_system_details.ssh_public_keys = existing_ssh_public_keys input_version_dict = module.params.get("version", None) version_changed, patch_details = oci_db_utils.is_version_changed( db_client.get_db_system_patch_history_entry, db_client.get_db_system_patch, db_system.version, input_version_dict, last_patch_history_entry_id, db_system_id=db_system_id, ) if version_changed: update_db_system_details.version = patch_details changed = changed or ssh_public_keys_changed or version_changed if changed: result = oci_utils.update_and_wait( resource_type="db_system", update_fn=db_client.update_db_system, kwargs_update={ "db_system_id": db_system_id, "update_db_system_details": update_db_system_details, }, client=db_client, get_fn=db_client.get_db_system, get_param="db_system_id", module=module, ) else: result["db_system"] = to_dict(db_system) result["changed"] = False return result
def update_backend_set(lb_client, module, lb_id, backend_set, name): result = dict(backend_set=to_dict(backend_set), changed=False) update_backend_set_details = UpdateBackendSetDetails() purge_backends = module.params.get("purge_backends") delete_backends = module.params.get("delete_backends") input_backends = oci_lb_utils.create_backends(module.params.get("backends", None)) existing_backends = oci_utils.get_hashed_object_list( BackendDetails, backend_set.backends ) get_logger().info("Updating backend set %s in the load balancer %s", name, lb_id) backends_changed = False if input_backends is not None: ( backends, backends_changed, ) = oci_utils.check_and_return_component_list_difference( input_backends, existing_backends, purge_backends, delete_backends ) if backends_changed: update_backend_set_details.backends = backends else: update_backend_set_details.backends = existing_backends input_health_checker = oci_lb_utils.create_health_checker( module.params.get("health_checker") ) health_checker_changed = oci_utils.update_class_type_attr_difference( update_backend_set_details, backend_set, "health_checker", HealthCheckerDetails, input_health_checker, ) policy_changed = oci_utils.check_and_update_attributes( update_backend_set_details, "policy", module.params.get("policy"), backend_set.policy, False, ) input_session_persistence_configuration = oci_lb_utils.create_session_persistence_configuration( module.params.get("session_persistence_configuration", None) ) session_persistence_configuration_changed = oci_utils.update_class_type_attr_difference( update_backend_set_details, backend_set, "session_persistence_configuration", SessionPersistenceConfigurationDetails, input_session_persistence_configuration, ) input_ssl_configuration = oci_lb_utils.create_ssl_configuration( module.params.get("ssl_configuration", None) ) ssl_configuration_changed = oci_utils.update_class_type_attr_difference( update_backend_set_details, backend_set, "ssl_configuration", SSLConfigurationDetails, input_ssl_configuration, ) changed = ( backends_changed or health_checker_changed or policy_changed or session_persistence_configuration_changed or ssl_configuration_changed ) if changed: result = oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type="backend_set", function=lb_client.update_backend_set, kwargs_function={ "update_backend_set_details": update_backend_set_details, "load_balancer_id": lb_id, "backend_set_name": name, }, lb_client=lb_client, get_fn=lb_client.get_backend_set, kwargs_get={"load_balancer_id": lb_id, "backend_set_name": name}, module=module, ) get_logger().info( "Successfully updated backend set %s in the load balancer %s", name, lb_id ) else: get_logger().info( "No update on backend set %s in the load balancer %s as no attribute changed", name, lb_id, ) return result
def update_listener(lb_client, module, listener, lb_id, name): result = dict(listener=to_dict(listener), changed=False) update_listener_details = UpdateListenerDetails() changed = False get_logger().info("Updating listener %s in load balancer %s", name, lb_id) for attribute in update_listener_details.attribute_map.keys(): if attribute not in [ "ssl_configuration", "connection_configuration", "hostname_names", ]: changed = oci_utils.check_and_update_attributes( update_listener_details, attribute, module.params.get(attribute, None), getattr(listener, attribute), changed, ) input_ssl_configuration = oci_lb_utils.create_ssl_configuration( module.params.get("ssl_configuration", None) ) existing_ssl_configuration = oci_utils.get_hashed_object( SSLConfigurationDetails, listener.ssl_configuration ) ssl_configuration_changed = oci_utils.check_and_update_attributes( update_listener_details, "ssl_configuration", input_ssl_configuration, existing_ssl_configuration, False, ) input_connection_configuration = oci_lb_utils.create_connection_configuration( module.params.get("connection_configuration", None) ) existing_connection_configuration = oci_utils.get_hashed_object( ConnectionConfiguration, listener.connection_configuration ) connection_configuration_changed = oci_utils.check_and_update_attributes( update_listener_details, "connection_configuration", input_connection_configuration, existing_connection_configuration, False, ) input_hostname_names = module.params.get("hostname_names", None) update_listener_details.hostname_names = listener.hostname_names hostname_names_changed = False if input_hostname_names is not None: ( changed_hostname_names, hostname_names_changed, ) = oci_utils.check_and_return_component_list_difference( input_hostname_names, listener.hostname_names, module.params.get("purge_hostname_names"), module.params.get("delete_hostname_names"), ) if hostname_names_changed: update_listener_details.hostname_names = changed_hostname_names changed = ( changed or ssl_configuration_changed or connection_configuration_changed or hostname_names_changed ) get_logger().debug( "Existing listener property values: %s, input property values: %s", listener, update_listener_details, ) if changed: result = oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type="listener", function=lb_client.update_listener, kwargs_function={ "update_listener_details": update_listener_details, "load_balancer_id": lb_id, "listener_name": name, }, lb_client=lb_client, get_sub_resource_fn=oci_lb_utils.get_listener, kwargs_get={ "lb_client": lb_client, "module": module, "load_balancer_id": lb_id, "name": name, }, module=module, ) else: get_logger().info( "Successfully updated listener %s in load balancer %s", name, lb_id ) return result