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 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_or_update_listener(lb_client, module): listener = None result = dict(changed=False, listener="") load_balancer_id = module.params.get("load_balancer_id") name = module.params.get("name") existing_load_balancer = oci_lb_utils.get_existing_load_balancer( lb_client, module, load_balancer_id ) if existing_load_balancer is None: module.fail_json( msg="Load balancer with id: " + load_balancer_id + " does not exist" ) listener = existing_load_balancer.listeners.get(name) try: if listener: result = update_listener( lb_client, module, listener, load_balancer_id, name ) get_logger().info( "Successfully updated listener %s in load balancer %s", name, load_balancer_id, ) else: listeners_list = [] for key, value in six.iteritems(existing_load_balancer.listeners): listeners_list.append(value) result = oci_utils.check_and_create_resource( resource_type="listener", create_fn=create_listener, kwargs_create={ "lb_client": lb_client, "module": module, "lb_id": load_balancer_id, "name": name, }, list_fn=None, kwargs_list=None, existing_resources=listeners_list, module=module, model=CreateListenerDetails(), ) 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)) return result
def create_or_update_listener(lb_client, module): listener = None result = dict(changed=False, listener='') load_balancer_id = module.params.get('load_balancer_id') name = module.params.get('name') existing_load_balancer = oci_lb_utils.get_existing_load_balancer( lb_client, module, load_balancer_id) if existing_load_balancer is None: module.fail_json(msg='Load balancer with id: ' + load_balancer_id + ' does not exist') listener = existing_load_balancer.listeners.get(name) try: if listener: result = update_listener(lb_client, module, listener, load_balancer_id, name) get_logger().info( "Successfully updated listener %s in load balancer %s", name, load_balancer_id) else: listeners_list = [] for _, value in six.iteritems(existing_load_balancer.listeners): listeners_list.append(value) result = oci_utils.check_and_create_resource( resource_type='listener', create_fn=create_listener, kwargs_create={ 'lb_client': lb_client, 'module': module, 'lb_id': load_balancer_id, 'name': name }, list_fn=None, kwargs_list=None, existing_resources=listeners_list, module=module, model=CreateListenerDetails()) 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)) return result