def create_load_balancer(lb_client, module):
    result = dict()
    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)
    response = oci_utils.call_with_backoff(lb_client.create_load_balancer,
                                           create_load_balancer_details=create_load_balancer_details)

    response = oci_lb_utils.verify_work_request(lb_client, response)
    get_logger().info("Successfully created load balancer %s in the compartment %s",
                      name, compartment_id)
    result['load_balancer'] = to_dict(
        lb_client.get_load_balancer(response.data.load_balancer_id).data)
    result['changed'] = True
    return result
Example #2
0
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,
    )
Example #3
0
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_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_backend_set(lb_client, module):
    result = dict()
    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()
    create_backend_set_details.name = name
    create_backend_set_details.backends = backend_set_details.backends
    create_backend_set_details.health_checker = backend_set_details.health_checker
    create_backend_set_details.policy = backend_set_details.policy
    create_backend_set_details.session_persistence_configuration = \
        backend_set_details.session_persistence_configuration
    create_backend_set_details.ssl_configuration = backend_set_details.ssl_configuration
    response = oci_utils.call_with_backoff(
        lb_client.create_backend_set,
        create_backend_set_details=create_backend_set_details,
        load_balancer_id=lb_id)
    oci_lb_utils.verify_work_request(lb_client, response)
    get_logger().info(
        "Successfully created backend set %s in the load balancer %s", name,
        lb_id)
    backend_set = get_existing_backend_set(lb_client, module, lb_id, name)
    result['backend_set'] = to_dict(backend_set)
    result['changed'] = True
    return result