def create_path_route_set(lb_client, module): path_route_set_input_details = dict({'path_routes': module.params.get( 'path_routes', None)}) name = module.params.get('name') lb_id = module.params.get('load_balancer_id') get_logger().info("Creating path route set %s in the load balancer %s", name, lb_id) path_route_set_details = oci_lb_utils.create_path_route_sets( dict({name: path_route_set_input_details})).get(name) create_path_route_set_details = CreatePathRouteSetDetails() create_path_route_set_details.name = name create_path_route_set_details.path_routes = path_route_set_details.path_routes result = oci_lb_utils.create_or_update_lb_resources_and_wait(resource_type="path_route_set", function=lb_client.create_path_route_set, kwargs_function={ 'create_path_route_set_details': create_path_route_set_details, 'load_balancer_id': lb_id}, lb_client=lb_client, get_fn=lb_client.get_path_route_set, kwargs_get={'load_balancer_id': lb_id, 'path_route_set_name': name}, module=module ) get_logger().info("Successfullt created path route set %s in the load balancer %s", name, lb_id) return result
def create_backend(lb_client, module, lb_id, backend_set_name): backend_name = oci_lb_utils.get_backend_name(module) create_backend_details = CreateBackendDetails() for attribute in create_backend_details.attribute_map: create_backend_details.__setattr__( attribute, module.params.get(attribute, None)) get_logger().info("Creating backend for backendset %s with parameters %s", backend_set_name, str(create_backend_details)) get_logger().debug("backend ip_address: %s and port: %s", module.params['ip_address'], str(module.params['port'])) result = oci_lb_utils.create_or_update_lb_resources_and_wait(resource_type="backend", function=lb_client.create_backend, kwargs_function={ 'create_backend_details': create_backend_details, 'load_balancer_id': lb_id, 'backend_set_name': backend_set_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 created backend for backendset %s with parameters %s", backend_set_name, str(create_backend_details)) return result
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 create_listener(lb_client, module, lb_id, name): listener_input_details = get_listener_input_details(module) listener_details = oci_lb_utils.create_listeners({ name: listener_input_details }).get(name) create_listener_details = CreateListenerDetails() for attribute in create_listener_details.attribute_map: create_listener_details.__setattr__( attribute, getattr(listener_details, attribute, None)) create_listener_details.name = name get_logger().info( "Creating listener %s in load balancer %s with parameters %s", name, lb_id, str(create_listener_details)) return oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type='listener', function=lb_client.create_listener, kwargs_function={ 'create_listener_details': create_listener_details, 'load_balancer_id': lb_id }, 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)
def update_path_route_set(lb_client, module, lb_id, path_route_set, name): result = dict(path_route_set=to_dict(path_route_set), changed=False) update_path_route_set_details = UpdatePathRouteSetDetails() purge_path_routes = module.params.get('purge_path_routes') input_path_routes = oci_lb_utils.create_path_routes(module.params.get('path_routes', None)) existing_path_routes = oci_utils.get_hashed_object_list( PathRoute, path_route_set.path_routes, attributes_class_type=[PathMatchType]) get_logger().info("Updating path route set %s in the load balancer %s", name, lb_id) changed = False if input_path_routes is not None: path_routes, changed = oci_utils.check_and_return_component_list_difference( input_path_routes, existing_path_routes, purge_path_routes) if changed: update_path_route_set_details.path_routes = path_routes else: update_path_route_set_details.path_routes = existing_path_routes if changed: result = oci_lb_utils.create_or_update_lb_resources_and_wait(resource_type="path_route_set", function=lb_client.update_path_route_set, kwargs_function={ 'update_path_route_set_details': update_path_route_set_details, 'load_balancer_id': lb_id, 'path_route_set_name': name}, lb_client=lb_client, get_fn=lb_client.get_path_route_set, kwargs_get={'load_balancer_id': lb_id, 'path_route_set_name': name}, module=module ) get_logger().info("Successfully updated path route set %s in the load balancer %s", name, lb_id) else: get_logger().info("No update to the path route set %s in the load balancer %s as no attribute changed", name, lb_id) return result
def update_load_balancer(lb_client, module, load_balancer): if load_balancer is None: raise ClientError( Exception("No Load Balancer with id " + module.params.get('load_balancer_id') + " is found for update")) result = dict(load_balancer=to_dict(load_balancer), changed=False) name = module.params['display_name'] update_load_balancer_details = UpdateLoadBalancerDetails() if load_balancer.display_name.strip() != name.strip(): get_logger().info( "Updating the display name of load balancer from %s to %s", load_balancer.display_name, name) update_load_balancer_details.display_name = name result = oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type="load_balancer", function=lb_client.update_load_balancer, kwargs_function={ 'update_load_balancer_details': update_load_balancer_details, 'load_balancer_id': load_balancer.id }, lb_client=lb_client, get_fn=lb_client.get_load_balancer, kwargs_get={'load_balancer_id': load_balancer.id}, module=module) get_logger().info( "Successfully updated the display name of load balancer from %s to %s", load_balancer.display_name, name) if not result['changed']: get_logger().info( "Unable to update display name of load balancer as the new name is same as old" ) return result
def create_hostname(lb_client, module): hostname_input_details = dict( { "name": module.params.get("name", None), "hostname": module.params.get("hostname"), } ) name = module.params.get("name") lb_id = module.params.get("load_balancer_id") get_logger().info("Creating hostname %s in the load balancer %s", name, lb_id) hostname_details = oci_lb_utils.create_hostnames( dict({name: hostname_input_details}) ).get(name) create_hostname_details = CreateHostnameDetails() for attribute in create_hostname_details.attribute_map: create_hostname_details.__setattr__( attribute, getattr(hostname_details, attribute) ) result = oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type="hostname", function=lb_client.create_hostname, kwargs_function={ "create_hostname_details": create_hostname_details, "load_balancer_id": lb_id, }, 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 created hostname %s in the load balancer %s", 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 create_hostname(lb_client, module): hostname_input_details = dict({ 'name': module.params.get('name', None), 'hostname': module.params.get('hostname') }) name = module.params.get('name') lb_id = module.params.get('load_balancer_id') get_logger().info("Creating hostname %s in the load balancer %s", name, lb_id) hostname_details = oci_lb_utils.create_hostnames( dict({name: hostname_input_details})).get(name) create_hostname_details = CreateHostnameDetails() for attribute in create_hostname_details.attribute_map: create_hostname_details.__setattr__( attribute, getattr(hostname_details, attribute)) return oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type="hostname", function=lb_client.create_hostname, kwargs_function={ 'create_hostname_details': create_hostname_details, 'load_balancer_id': lb_id }, lb_client=lb_client, get_fn=lb_client.get_hostname, kwargs_get={ 'load_balancer_id': lb_id, 'name': name }, module=module)
def create_certificate(lb_client, module): result = dict(changed=False, certificate="") lb_id = module.params.get("load_balancer_id") name = module.params.get("name") certificate = oci_lb_utils.get_certificate(lb_client, module, lb_id, name) create_certificate_details = oci_lb_utils.get_create_certificate_details( module, name ) same_certificate = False if certificate is not None: same_certificate = oci_lb_utils.is_same_certificate( create_certificate_details, certificate ) if same_certificate: get_logger().info( "Certificate %s with same attribute values already available", name ) result["changed"] = False result["certificate"] = to_dict(certificate) else: get_logger().error( "Certificate %s with different attribute value already available in load balancer %s", name, lb_id, ) module.fail_json( msg="Certificate " + name + " with different attribute value already available in " "load balancer " + lb_id ) if not same_certificate: get_logger().info( "Creating certificate %s in the load balancer %s", name, lb_id ) result = oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type="certificate", function=lb_client.create_certificate, kwargs_function={ "create_certificate_details": create_certificate_details, "load_balancer_id": lb_id, }, lb_client=lb_client, get_sub_resource_fn=oci_lb_utils.get_certificate, kwargs_get={ "lb_client": lb_client, "module": module, "lb_id": lb_id, "name": name, }, module=module, ) get_logger().info( "Successfully created certificate %s in the load balancer %s", name, lb_id ) return result
def update_load_balancer(lb_client, module, load_balancer): if load_balancer is None: raise ClientError( Exception("No Load Balancer with id " + module.params.get("load_balancer_id") + " is found for update")) result = dict(load_balancer=to_dict(load_balancer), changed=False) name = module.params["display_name"] defined_tags = module.params["defined_tags"] freeform_tags = module.params["freeform_tags"] update_load_balancer_details = UpdateLoadBalancerDetails() changed = False if name is not None and load_balancer.display_name.strip() != name.strip(): get_logger().info( "Updating the display name of load balancer from %s to %s", load_balancer.display_name, name, ) changed = True if freeform_tags is not None and load_balancer.freeform_tags != freeform_tags: get_logger().info( "Updating the freeform_tags of load balancer from {0} to {1}". format(load_balancer.freeform_tags, freeform_tags)) changed = True if defined_tags is not None and load_balancer.defined_tags != defined_tags: get_logger().info( "Updating the defined_tags of load balancer from {0} to {1}". format(load_balancer.defined_tags, defined_tags)) changed = True if changed is True: update_load_balancer_details.display_name = name update_load_balancer_details.freeform_tags = freeform_tags update_load_balancer_details.defined_tags = defined_tags result = oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type="load_balancer", function=lb_client.update_load_balancer, kwargs_function={ "update_load_balancer_details": update_load_balancer_details, "load_balancer_id": load_balancer.id, }, lb_client=lb_client, get_fn=lb_client.get_load_balancer, kwargs_get={"load_balancer_id": load_balancer.id}, module=module, ) get_logger().info( "Successfully updated the parameters of load balancer") if not result["changed"]: get_logger().info( "Unable to update load balancer as the new parameter is same as old one" ) return result
def create_certificate(lb_client, module): result = dict(changed=False, certificate='') lb_id = module.params.get('load_balancer_id') name = module.params.get('name') certificate = oci_lb_utils.get_certificate(lb_client, module, lb_id, name) create_certificate_details = oci_lb_utils.get_create_certificate_details( module, name) same_certificate = False if certificate is not None: same_certificate = oci_lb_utils.is_same_certificate( create_certificate_details, certificate) if same_certificate: get_logger().info( "Certificate %s with same attribute values already available", name) result['changed'] = False result['certificate'] = to_dict(certificate) else: get_logger().error( "Certificate %s with different attribute value already available in load balancer %s", name, lb_id) module.fail_json( msg="Certificate " + name + " with different attribute value already available in " "load balancer " + lb_id) if not same_certificate: get_logger().info("Creating certificate %s in the load balancer %s", name, lb_id) result = oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type='certificate', function=lb_client.create_certificate, kwargs_function={ 'create_certificate_details': create_certificate_details, 'load_balancer_id': lb_id }, lb_client=lb_client, get_sub_resource_fn=oci_lb_utils.get_certificate, kwargs_get={ 'lb_client': lb_client, 'module': module, 'lb_id': lb_id, 'name': name }, module=module) get_logger().info( "Successfully created certificate %s in the load balancer %s", name, lb_id) 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 create_load_balancer(lb_client, module): compartment_id = module.params["compartment_id"] name = module.params["display_name"] get_logger().info("Creating load balancer %s in the compartment %s", name, compartment_id) backend_sets = oci_lb_utils.create_backend_sets( module.params.get("backend_sets", None)) certificates = oci_lb_utils.create_certificates( module.params.get("certificates", None)) listeners = oci_lb_utils.create_listeners( module.params.get("listeners", None)) path_route_sets = oci_lb_utils.create_path_route_sets( module.params.get("path_route_sets", None)) hostnames = oci_lb_utils.create_hostnames( module.params.get("hostnames", None)) subnet_ids = module.params["subnet_ids"] shape_name = module.params["shape_name"] is_private = module.params.get("is_private", False) defined_tags = module.params["defined_tags"] freeform_tags = module.params["freeform_tags"] create_load_balancer_details = CreateLoadBalancerDetails() atributes_to_value_dict = dict({ "compartment_id": compartment_id, "display_name": name, "is_private": is_private, "certificates": certificates, "listeners": listeners, "backend_sets": backend_sets, "path_route_sets": path_route_sets, "hostnames": hostnames, "shape_name": shape_name, "subnet_ids": subnet_ids, "freeform_tags": freeform_tags, "defined_tags": defined_tags, }) for key, value in six.iteritems(atributes_to_value_dict): create_load_balancer_details.__setattr__(key, value) return oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type="load_balancer", function=lb_client.create_load_balancer, kwargs_function={ "create_load_balancer_details": create_load_balancer_details }, lb_client=lb_client, get_fn=lb_client.get_load_balancer, get_param="load_balancer_id", module=module, )
def create_load_balancer(lb_client, module): compartment_id = module.params['compartment_id'] name = module.params['display_name'] get_logger().info("Creating load balancer %s in the compartment %s", name, compartment_id) backend_sets = oci_lb_utils.create_backend_sets( module.params.get('backend_sets', None)) certificates = oci_lb_utils.create_certificates( module.params.get('certificates', None)) listeners = oci_lb_utils.create_listeners( module.params.get('listeners', None)) path_route_sets = oci_lb_utils.create_path_route_sets( module.params.get('path_route_sets', None)) hostnames = oci_lb_utils.create_hostnames( module.params.get('hostnames', None)) subnet_ids = module.params['subnet_ids'] shape_name = module.params['shape_name'] is_private = module.params.get('is_private', False) create_load_balancer_details = CreateLoadBalancerDetails() atributes_to_value_dict = dict({ 'compartment_id': compartment_id, 'display_name': name, 'is_private': is_private, 'certificates': certificates, 'listeners': listeners, 'backend_sets': backend_sets, 'path_route_sets': path_route_sets, 'hostnames': hostnames, 'shape_name': shape_name, 'subnet_ids': subnet_ids }) for key, value in six.iteritems(atributes_to_value_dict): create_load_balancer_details.__setattr__(key, value) return oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type="load_balancer", function=lb_client.create_load_balancer, kwargs_function={ 'create_load_balancer_details': create_load_balancer_details }, lb_client=lb_client, get_fn=lb_client.get_load_balancer, get_param='load_balancer_id', module=module)
def create_backend_set(lb_client, module): backen_end_set_input_details = dict({ 'backends': module.params.get('backends', None), 'health_checker': module.params.get('health_checker'), 'policy': module.params.get('policy'), 'session_persistence_configuration': module.params.get('session_persistence_configuration', None), 'ssl_configuration': module.params.get('ssl_configuration', None) }) name = module.params.get('name') lb_id = module.params.get('load_balancer_id') get_logger().info("Creating backend set %s in the load balancer %s", name, lb_id) backend_set_details = oci_lb_utils.create_backend_sets( dict({name: backen_end_set_input_details})).get(name) create_backend_set_details = CreateBackendSetDetails() for attribute in create_backend_set_details.attribute_map: create_backend_set_details.__setattr__( attribute, getattr(backend_set_details, attribute, None)) create_backend_set_details.name = name result = oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type="backend_set", function=lb_client.create_backend_set, kwargs_function={ 'create_backend_set_details': create_backend_set_details, 'load_balancer_id': lb_id }, 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 created backend set %s in the load balancer %s", name, lb_id) return result
def create_listener(lb_client, module, lb_id, name): listener_input_details = get_listener_input_details(module) listener_details = oci_lb_utils.create_listeners( {name: listener_input_details} ).get(name) create_listener_details = CreateListenerDetails() for attribute in create_listener_details.attribute_map: create_listener_details.__setattr__( attribute, getattr(listener_details, attribute, None) ) create_listener_details.name = name get_logger().info( "Creating listener %s in load balancer %s with parameters %s", name, lb_id, str(create_listener_details), ) result = oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type="listener", function=lb_client.create_listener, kwargs_function={ "create_listener_details": create_listener_details, "load_balancer_id": lb_id, }, 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, ) get_logger().info( "Successfully created listener %s in load balancer %s with parameters %s", name, lb_id, str(create_listener_details), ) return result
def create_backend_set(lb_client, module): backen_end_set_input_details = dict( { "backends": module.params.get("backends", None), "health_checker": module.params.get("health_checker"), "policy": module.params.get("policy"), "session_persistence_configuration": module.params.get( "session_persistence_configuration", None ), "ssl_configuration": module.params.get("ssl_configuration", None), } ) name = module.params.get("name") lb_id = module.params.get("load_balancer_id") get_logger().info("Creating backend set %s in the load balancer %s", name, lb_id) backend_set_details = oci_lb_utils.create_backend_sets( dict({name: backen_end_set_input_details}) ).get(name) create_backend_set_details = CreateBackendSetDetails() for attribute in create_backend_set_details.attribute_map: create_backend_set_details.__setattr__( attribute, getattr(backend_set_details, attribute, None) ) create_backend_set_details.name = name result = oci_lb_utils.create_or_update_lb_resources_and_wait( resource_type="backend_set", function=lb_client.create_backend_set, kwargs_function={ "create_backend_set_details": create_backend_set_details, "load_balancer_id": lb_id, }, 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 created backend set %s in the load balancer %s", 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 ) 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_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_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_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