Beispiel #1
0
def create_or_update_virtual_circuit(virtual_network_client, module):
    result = dict(changed=False, virtual_circuit="")
    virtual_circuit_id = module.params.get("virtual_circuit_id")
    exclude_attributes = {"display_name": True, "public_prefixes": True}
    try:
        if virtual_circuit_id:
            existing_virtual_circuit = oci_utils.get_existing_resource(
                virtual_network_client.get_virtual_circuit,
                module,
                virtual_circuit_id=virtual_circuit_id,
            )
            result = update_virtual_circuit(
                virtual_network_client, existing_virtual_circuit, module
            )
        else:
            result = oci_utils.check_and_create_resource(
                resource_type="virtual_circuit",
                create_fn=create_virtual_circuit,
                kwargs_create={
                    "virtual_network_client": virtual_network_client,
                    "module": module,
                },
                list_fn=virtual_network_client.list_virtual_circuits,
                kwargs_list={"compartment_id": module.params.get("compartment_id")},
                module=module,
                exclude_attributes=exclude_attributes,
                model=CreateVirtualCircuitDetails(),
            )
    except ServiceError as ex:
        module.fail_json(msg=ex.message)
    except MaximumWaitTimeExceeded as ex:
        module.fail_json(msg=str(ex))

    return result
def update_db_home(db_client, module, db_home_id):
    result = dict()
    db_home = oci_utils.get_existing_resource(
        db_client.get_db_home, module, db_home_id=db_home_id)
    if db_home is None:
        raise ClientError(Exception("No DB Home with id " +
                                    db_home_id + " is found for update"))
    last_patch_history_entry_id = db_home.last_patch_history_entry_id
    input_version_dict = module.params.get('patch_details', None)
    update_db_home_details = UpdateDbHomeDetails()
    version_changed, patch_details = oci_db_utils.is_version_changed(
        db_client.get_db_home_patch_history_entry, db_client.get_db_home_patch, db_home.db_version,
        input_version_dict, last_patch_history_entry_id, db_home_id=db_home_id)
    if version_changed:
        update_db_home_details.db_version = patch_details
        result = oci_utils.update_and_wait(resource_type='db_home',
                                           update_fn=db_client.update_db_home,
                                           kwargs_update={
                                               'db_home_id': db_home_id,
                                               'update_db_home_details': update_db_home_details},
                                           client=db_client,
                                           get_fn=db_client.get_db_home,
                                           get_param='db_home_id',
                                           module=module)
    else:
        result['db_home'] = to_dict(db_home)
        result['changed'] = False
    return result
Beispiel #3
0
def create_or_update_route_table(virtual_network_client, module):
    result = dict(changed=False, route_table="")
    rt_id = module.params.get("rt_id")
    exclude_attributes = {"display_name": True}
    try:
        if rt_id:
            existing_route_table = oci_utils.get_existing_resource(
                virtual_network_client.get_route_table, module, rt_id=rt_id
            )
            result = update_route_table(
                virtual_network_client, existing_route_table, module
            )
        else:
            result = oci_utils.check_and_create_resource(
                resource_type="route_table",
                create_fn=create_route_table,
                kwargs_create={
                    "virtual_network_client": virtual_network_client,
                    "module": module,
                },
                list_fn=virtual_network_client.list_route_tables,
                kwargs_list={
                    "compartment_id": module.params.get("compartment_id"),
                    "vcn_id": module.params.get("vcn_id"),
                },
                module=module,
                exclude_attributes=exclude_attributes,
                model=CreateRouteTableDetails(),
            )
    except ServiceError as ex:
        module.fail_json(msg=ex.message)
    except MaximumWaitTimeExceeded as ex:
        module.fail_json(msg=str(ex))

    return result
def create_or_update_hostname(lb_client, module):
    hostname = None
    result = dict(changed=False, hostname='')
    load_balancer_id = module.params.get('load_balancer_id')
    name = module.params.get('name')
    hostname = oci_utils.get_existing_resource(
        lb_client.get_hostname,
        module,
        load_balancer_id=load_balancer_id,
        name=name)
    if hostname:
        result = update_hostname(lb_client, module, load_balancer_id, hostname,
                                 name)
    else:
        result = oci_utils.check_and_create_resource(
            resource_type='hostname',
            create_fn=create_hostname,
            kwargs_create={
                'lb_client': lb_client,
                'module': module
            },
            list_fn=lb_client.list_hostnames,
            kwargs_list={
                'load_balancer_id': module.params.get('load_balancer_id')
            },
            module=module,
            model=CreateHostnameDetails())

    return result
def create_or_update_export(file_storage_client, module):
    result = dict(changed=False, export="")
    export_id = module.params.get("export_id")
    try:
        if export_id:
            export = oci_utils.get_existing_resource(
                file_storage_client.get_export, module, export_id=export_id)
            result = update_export(file_storage_client, module, export)
        else:
            result = oci_utils.check_and_create_resource(
                resource_type="export",
                create_fn=create_export,
                kwargs_create={
                    "file_storage_client": file_storage_client,
                    "module": module,
                },
                list_fn=file_storage_client.list_exports,
                kwargs_list={
                    "file_system_id": module.params.get("file_system_id")
                },
                module=module,
                model=CreateExportDetails(),
            )
    except ServiceError as ex:
        get_logger().error("Unable to create/update Export due to: %s",
                           ex.message)
        module.fail_json(msg=ex.message)
    except ClientError as ex:
        get_logger().error("Unable to launch/update Export due to: %s",
                           str(ex))
        module.fail_json(msg=str(ex))

    return result
def delete_load_balancer(lb_client, module):
    changed = False
    load_balancer = None
    result = dict(
        changed=False,
        load_balancer=''
    )

    load_balancer_id = module.params.get('load_balancer_id')
    try:
        load_balancer = oci_utils.get_existing_resource(
            lb_client.get_load_balancer, module, load_balancer_id=load_balancer_id)
        if load_balancer:
            get_logger().info("Deleting load balancer %s", load_balancer_id)
            response = oci_utils.call_with_backoff(
                lb_client.delete_load_balancer, load_balancer_id=load_balancer_id)
            oci_lb_utils.verify_work_request(lb_client, response)
            changed = True
            get_logger().info("Successfully deleted load balancer %s",
                              load_balancer_id)
            result['load_balancer'] = to_dict(load_balancer)
    except ServiceError as ex:
        if ex.status != 404:
            get_logger().error("Failed to delete load balancer due to: %s", ex.message)
            module.fail_json(msg=ex.message)
    if not changed:
        get_logger().info(
            "Unable to delete load balancer %s as it is not available", load_balancer_id)
    result['changed'] = changed
    return result
Beispiel #7
0
def create_or_update_user(identity_client, module):
    existing_user = None
    user = None
    result = dict(changed=False, user='')
    user_id = module.params.get('user_id')
    try:
        if user_id:
            existing_user = oci_utils.get_existing_resource(
                identity_client.get_user, module, user_id=user_id)
            changed, user = update_user(identity_client, existing_user, module)
            result['changed'] = changed
            result['user'] = user
        else:
            result = oci_utils.check_and_create_resource(
                resource_type='user',
                create_fn=create_user,
                kwargs_create={
                    'identity_client': identity_client,
                    'module': module
                },
                list_fn=identity_client.list_users,
                kwargs_list={
                    'compartment_id': module.params.get('compartment_id')
                },
                module=module,
                model=CreateUserDetails())
    except ServiceError as ex:
        module.fail_json(msg=ex.message)
    except MaximumWaitTimeExceeded as ex:
        module.fail_json(msg=ex.args)
    return result
Beispiel #8
0
def delete_user(identity_client, module):
    result = dict(changed=False, user='')
    user_id = module.params.get('user_id')
    force = module.params.get('force')
    compartment_id = module.params.get('compartment_id')
    try:
        existing_user = oci_utils.get_existing_resource(
            identity_client.get_user, module, user_id=user_id)
        if existing_user:
            if force:
                delete_all_group_memberships(identity_client, compartment_id,
                                             existing_user.id)
            result = oci_utils.delete_and_wait(
                resource_type="user",
                client=identity_client,
                get_fn=identity_client.get_user,
                kwargs_get={"user_id": module.params["user_id"]},
                delete_fn=identity_client.delete_user,
                kwargs_delete={"user_id": module.params["user_id"]},
                module=module)

    except ServiceError as ex:
        module.fail_json(msg=ex.message)

    return result
Beispiel #9
0
def create_or_update_group(identity_client, module):
    group = None
    existing_group = None
    result = dict(changed=False, group='')
    group_id = module.params.get('group_id')
    exclude_attributes = {'compartment_id': True}
    try:
        if group_id:
            existing_group = oci_utils.get_existing_resource(
                identity_client.get_group, module, group_id=group_id)
            changed, group = update_group(identity_client, existing_group,
                                          module)
            result['changed'] = changed
            result['group'] = group
        else:
            result = oci_utils.check_and_create_resource(
                resource_type='group',
                create_fn=create_group,
                kwargs_create={
                    'identity_client': identity_client,
                    'module': module
                },
                list_fn=identity_client.list_groups,
                kwargs_list={
                    'compartment_id': module.params.get('compartment_id')
                },
                module=module,
                exclude_attributes=exclude_attributes,
                model=CreateGroupDetails())
    except ServiceError as ex:
        module.fail_json(msg=ex.message)
    except MaximumWaitTimeExceeded as ex:
        module.fail_json(msg=ex.args)
    return result
def create_or_update_path_route_set(lb_client, module):
    path_route_set = None
    result = dict(
        changed=False,
        path_route_set=''
    )
    load_balancer_id = module.params.get('load_balancer_id')
    name = module.params.get('name')
    path_route_set = oci_utils.get_existing_resource(
        lb_client.get_path_route_set, module, load_balancer_id=load_balancer_id, path_route_set_name=name)
    try:
        if path_route_set:
            result = update_path_route_set(lb_client, module, load_balancer_id, path_route_set, name)
        else:
            result = oci_utils.check_and_create_resource(resource_type='path_route_set',
                                                         create_fn=create_path_route_set,
                                                         kwargs_create={'lb_client': lb_client,
                                                                        'module': module},
                                                         list_fn=lb_client.list_path_route_sets,
                                                         kwargs_list={
                                                             'load_balancer_id': module.params.get('load_balancer_id')},
                                                         module=module,
                                                         model=CreatePathRouteSetDetails())
    except ServiceError as ex:
        get_logger().error("Unable to create/update path route set due to: %s", ex.message)
        module.fail_json(msg=ex.message)
    except ClientError as ex:
        get_logger().error("Unable to create/update path route set due to: %s", str(ex))
        module.fail_json(msg=str(ex))

    return result
def create_or_update_backend_set(lb_client, module):
    backend_set = None
    result = dict(changed=False, backend_set="")
    lb_id = module.params.get("load_balancer_id")
    name = module.params.get("name")
    backend_set = oci_utils.get_existing_resource(
        lb_client.get_backend_set, module, load_balancer_id=lb_id, backend_set_name=name
    )
    try:
        if backend_set:
            result = update_backend_set(lb_client, module, lb_id, backend_set, name)
        else:
            result = oci_utils.check_and_create_resource(
                resource_type="backend_set",
                create_fn=create_backend_set,
                kwargs_create={"lb_client": lb_client, "module": module},
                list_fn=lb_client.list_backend_sets,
                kwargs_list={"load_balancer_id": lb_id},
                module=module,
                model=CreateBackendSetDetails(),
            )
    except ServiceError as ex:
        get_logger().error("Unable to create/update backend set due to: %s", ex.message)
        module.fail_json(msg=ex.message)
    except ClientError as ex:
        get_logger().error("Unable to create/update backend set due to: %s", str(ex))
        module.fail_json(msg=str(ex))

    return result
Beispiel #12
0
def create_path_route_set(lb_client, module):
    result = dict()
    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
    response = oci_utils.call_with_backoff(
        lb_client.create_path_route_set,
        create_path_route_set_details=create_path_route_set_details,
        load_balancer_id=lb_id)
    oci_lb_utils.verify_work_request(lb_client, response)
    get_logger().info(
        "Successfully created path route set %s in the load balancer %s", name,
        lb_id)
    path_route_set = oci_utils.get_existing_resource(
        lb_client.get_path_route_set,
        module,
        load_balancer_id=lb_id,
        path_route_set_name=name)
    result['path_route_set'] = to_dict(path_route_set)
    result['changed'] = True
    return result
def start_or_stop_autonomous_data_warehouse(db_client, module):
    autonomous_data_warehouse_id = module.params.get('autonomous_data_warehouse_id')
    autonomous_data_warehouse = oci_utils.get_existing_resource(
        db_client.get_autonomous_data_warehouse, module, autonomous_data_warehouse_id=autonomous_data_warehouse_id)

    if autonomous_data_warehouse is None:
        raise ClientError(Exception("No Autonomous Data Warehouse with id " +
                                    autonomous_data_warehouse_id + " is found for update"))

    return perform_start_or_stop(db_client, autonomous_data_warehouse, autonomous_data_warehouse_id, module)
Beispiel #14
0
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 create_or_update_security_list(virtual_network_client, module):
    result = dict(changed=False, security_list="")
    security_list_id = module.params.get("security_list_id")
    exclude_attributes = {"display_name": True}
    default_attribute_values = {
        "egress_security_rules": {
            "is_stateless": False
        },
        "ingress_security_rules": {
            "is_stateless": False
        },
    }
    try:
        if security_list_id:
            existing_security_list = oci_utils.get_existing_resource(
                virtual_network_client.get_security_list,
                module,
                security_list_id=security_list_id,
            )
            result = update_security_list(virtual_network_client,
                                          existing_security_list, module)
        else:
            # ingress_security_rules and egress_security_rules are required for create operation
            if (module.params.get("ingress_security_rules") is None
                    or module.params.get("egress_security_rules") is None):
                module.fail_json(
                    msg=
                    "ingress_security_rules and egress_security_rules are required for creating security list."
                )
            result = oci_utils.check_and_create_resource(
                resource_type="security_list",
                create_fn=create_security_list,
                kwargs_create={
                    "virtual_network_client": virtual_network_client,
                    "module": module,
                },
                list_fn=virtual_network_client.list_security_lists,
                kwargs_list={
                    "compartment_id": module.params.get("compartment_id"),
                    "vcn_id": module.params.get("vcn_id"),
                },
                exclude_attributes=exclude_attributes,
                default_attribute_values=default_attribute_values,
                module=module,
                model=CreateSecurityListDetails(),
            )
    except ServiceError as ex:
        module.fail_json(msg=ex.message)
    except MaximumWaitTimeExceeded as ex:
        module.fail_json(msg=str(ex))

    return result
Beispiel #16
0
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
Beispiel #17
0
def get_listener(**kwargs_get_listener):
    listener = ""
    lb_client = kwargs_get_listener.get("lb_client")
    module = kwargs_get_listener.get("module")
    lb_id = kwargs_get_listener.get("load_balancer_id")
    name = kwargs_get_listener.get("name")
    existing_load_balancer = to_dict(
        oci_utils.get_existing_resource(
            lb_client.get_load_balancer, module, load_balancer_id=lb_id
        )
    )
    if existing_load_balancer is None:
        module.fail_json(msg="Load balancer with id: " + lb_id + " does not exist")
    if name in existing_load_balancer.get("listeners"):
        listener = existing_load_balancer["listeners"][name]
    return listener
Beispiel #18
0
def get_listener(**kwargs_get_listener):
    listener = ''
    lb_client = kwargs_get_listener.get('lb_client')
    module = kwargs_get_listener.get('module')
    lb_id = kwargs_get_listener.get('load_balancer_id')
    name = kwargs_get_listener.get('name')
    existing_load_balancer = to_dict(
        oci_utils.get_existing_resource(lb_client.get_load_balancer,
                                        module,
                                        load_balancer_id=lb_id))
    if existing_load_balancer is None:
        module.fail_json(msg='Load balancer with id: ' + lb_id +
                         ' does not exist')
    if name in existing_load_balancer.get('listeners'):
        listener = existing_load_balancer['listeners'][name]
    return listener
def perform_data_guard_operations(db_client, module):
    changed = False
    result = dict(changed=False, data_guard_association="")
    data_guard_association_id = module.params.get("data_guard_association_id")
    database_id = module.params.get("database_id")
    if data_guard_association_id is None or database_id is None:
        module.fail_json(
            msg=
            "Data Guard Association related operation must contain valid database_id and data_guard_association_id"
        )
    data_guard_association = oci_utils.get_existing_resource(
        db_client.get_data_guard_association,
        module,
        database_id=database_id,
        data_guard_association_id=data_guard_association_id,
    )
    changed, target_fn, kwargs = get_operation_details(db_client, module,
                                                       data_guard_association)
    if changed:
        kwargs.update(database_id=database_id,
                      data_guard_association_id=data_guard_association_id)
        try:
            result = oci_db_utils.execute_function_and_wait(
                resource_type="data_guard_association",
                function=target_fn,
                kwargs_function=kwargs,
                client=db_client,
                get_fn=db_client.get_data_guard_association,
                get_param=None,
                kwargs_get={
                    "database_id": database_id,
                    "data_guard_association_id": data_guard_association_id,
                },
                module=module,
            )
        except ServiceError as ex:
            get_logger().error(
                "Unable to perform operation on  Data Guard Association due to: %s",
                ex.message,
            )
            module.fail_json(msg=ex.message)

    result["changed"] = changed
    result["data_guard_association"] = to_dict(data_guard_association)

    return result
def create_or_update_lb(lb_client, module):
    load_balancer = None
    result = dict(
        changed=False,
        load_balancer=''
    )
    load_balancer_id = module.params.get('load_balancer_id')
    default_attribute_values = {'backend_sets': {'backends': {'backup': False, 'drain': False, 'offline': False, 'weight': 1},
                                                 'health_checker': {'interval_in_millis': 10000, 'port': 0,
                                                                    'response_body_regex': '.*', 'retries': 3, 'return_code': 200,
                                                                    'timeout_in_millis': 3000},
                                                 'listener': {'connection_configuration': {'idle_timeout': 60}}}}
    exclude_attributes = {'display_name': True}

    try:
        if load_balancer_id:
            existing_load_balancer = oci_utils.get_existing_resource(
                lb_client.get_load_balancer, module, load_balancer_id=load_balancer_id)
            changed, load_balancer = update_load_balancer(
                lb_client, module, existing_load_balancer)
            result['changed'] = changed
            result['load_balancer'] = to_dict(load_balancer)
        else:
            module1 = copy.deepcopy(module)
            module1.params.update({'certificates': to_dict(
                oci_lb_utils.create_certificates(module1.params.get('certificates')))})
            result = oci_utils.check_and_create_resource(resource_type='load_balancer',
                                                         create_fn=create_load_balancer,
                                                         kwargs_create={'lb_client': lb_client,
                                                                        'module': module},
                                                         list_fn=lb_client.list_load_balancers,
                                                         kwargs_list={
                                                             'compartment_id': module.params.get('compartment_id')},
                                                         module=module1,
                                                         exclude_attributes=exclude_attributes,
                                                         default_attribute_values=default_attribute_values,
                                                         model=CreateLoadBalancerDetails())
    except ServiceError as ex:
        get_logger().error("Unable to create/update load balancer due to: %s", ex.message)
        module.fail_json(msg=ex.message)
    except ClientError as ex:
        get_logger().error("Unable to create/update backend due to: %s", str(ex))
        module.fail_json(msg=str(ex))

    return result
Beispiel #21
0
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 create_or_update_security_list(virtual_network_client, module):
    result = dict(changed=False, security_list='')
    security_list_id = module.params.get('security_list_id')
    exclude_attributes = {'display_name': True}
    default_attribute_values = {
        'egress_security_rules': {
            'is_stateless': False
        },
        'ingress_security_rules': {
            'is_stateless': False
        }
    }
    try:
        if security_list_id:
            existing_security_list = oci_utils.get_existing_resource(
                virtual_network_client.get_security_list,
                module,
                security_list_id=security_list_id)
            result = update_security_list(virtual_network_client,
                                          existing_security_list, module)
        else:
            result = oci_utils.check_and_create_resource(
                resource_type='security_list',
                create_fn=create_security_list,
                kwargs_create={
                    'virtual_network_client': virtual_network_client,
                    'module': module
                },
                list_fn=virtual_network_client.list_security_lists,
                kwargs_list={
                    'compartment_id': module.params.get('compartment_id'),
                    'vcn_id': module.params.get('vcn_id')
                },
                exclude_attributes=exclude_attributes,
                default_attribute_values=default_attribute_values,
                module=module,
                model=CreateSecurityListDetails())
    except ServiceError as ex:
        module.fail_json(msg=ex.message)
    except MaximumWaitTimeExceeded as ex:
        module.fail_json(msg=str(ex))

    return result
def perform_db_node_action(db_client, module):
    db_node = None
    result = dict(changed=False, db_node='')
    try:
        db_node = oci_utils.get_existing_resource(
            db_client.get_db_node,
            module,
            db_node_id=module.params.get('db_node_id'))
        if db_node:
            result = db_node_action(db_client, module, db_node)
    except ServiceError as ex:
        get_logger().error(
            "Unable to perform the action on Db Node due to: %s", ex.message)
        module.fail_json(msg=ex.message)
    except ClientError as ex:
        get_logger().error(
            "Unable to perform the action on Db Node due to: %s", str(ex))
        module.fail_json(msg=str(ex))

    return result
def create_or_update_db_home(db_client, module):
    result = dict(changed=False, db_home='')
    db_home_id = module.params.get('db_home_id')
    try:
        if db_home_id:
            result = update_db_home(db_client, module, db_home_id)
        else:
            db_system = oci_utils.get_existing_resource(
                db_client.get_db_system,
                module,
                db_system_id=module.params.get('db_system_id'))
            db_home_model = None
            source = module.params.get('source')
            if source == 'NONE':
                db_home_model = CreateDbHomeWithDbSystemIdDetails()
            elif source == 'DB_BACKUP':
                db_home_model = CreateDbHomeWithDbSystemIdFromBackupDetails()
            result = oci_utils.check_and_create_resource(
                resource_type='db_home',
                create_fn=create_db_home,
                kwargs_create={
                    'db_client': db_client,
                    'module': module
                },
                list_fn=db_client.list_db_homes,
                kwargs_list={
                    'compartment_id': db_system.compartment_id,
                    'db_system_id': module.params.get('db_system_id')
                },
                module=module,
                model=db_home_model)
    except ServiceError as ex:
        get_logger().error("Unable to create/update database home due to: %s",
                           ex.message)
        module.fail_json(msg=ex.message)
    except ClientError as ex:
        get_logger().error("Unable to launch/update database home due to: %s",
                           str(ex))
        module.fail_json(msg=str(ex))

    return result
Beispiel #25
0
def update_path_route_set(lb_client, module, lb_id, path_route_set, name):
    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_lb_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:
        response = oci_utils.call_with_backoff(
            lb_client.update_path_route_set,
            update_path_route_set_details=update_path_route_set_details,
            load_balancer_id=lb_id,
            path_route_set_name=name)
        oci_lb_utils.verify_work_request(lb_client, response)
        path_route_set = oci_utils.get_existing_resource(
            lb_client.get_path_route_set,
            module,
            load_balancer_id=lb_id,
            path_route_set_name=name)
        get_logger().info(
            "Successfully updated path route set %s in the load balancer %s",
            name, lb_id)
    else:
        get_logger().info(
            "No update on path route set %s in the load balancer %s as no attribute changed",
            name, lb_id)

    return changed, path_route_set
Beispiel #26
0
def delete_path_route_set(lb_client, module):
    changed = False
    path_route_set = None
    result = dict(changed=False, path_route_set='')

    load_balancer_id = module.params.get('load_balancer_id')
    name = module.params.get('name')
    try:
        path_route_set = oci_utils.get_existing_resource(
            lb_client.get_path_route_set,
            module,
            load_balancer_id=load_balancer_id,
            path_route_set_name=name)
        if path_route_set:
            get_logger().info("Deleting Pah Route Set %s on load balancer %s",
                              name, load_balancer_id)
            response = oci_utils.call_with_backoff(
                lb_client.delete_path_route_set,
                load_balancer_id=load_balancer_id,
                path_route_set_name=name)
            oci_lb_utils.verify_work_request(lb_client, response)
            changed = True
            get_logger().info(
                "Successfully deleted Path Route Set %s on load balancer %s",
                name, load_balancer_id)
            result['path_route_set'] = to_dict(path_route_set)
    except ServiceError as ex:
        get_logger().error("Failed to delete Path Route Set due to: %s",
                           ex.message)
        module.fail_json(msg=ex.message)
    except ClientError as ex:
        get_logger().error("Failed to delete Path Route Set due to: %s",
                           str(ex))
        module.fail_json(msg=str(ex))

    if not changed:
        get_logger().info(
            "Unable to delete Path Route Set %s as it is not available", name)
    result['changed'] = changed
    return result
Beispiel #27
0
def create_or_update_hostname(lb_client, module):
    hostname = None
    result = dict(changed=False, hostname="")
    load_balancer_id = module.params.get("load_balancer_id")
    name = module.params.get("name")
    hostname = oci_utils.get_existing_resource(
        lb_client.get_hostname, module, load_balancer_id=load_balancer_id, name=name
    )
    if hostname:
        result = update_hostname(lb_client, module, load_balancer_id, hostname, name)
    else:
        result = oci_utils.check_and_create_resource(
            resource_type="hostname",
            create_fn=create_hostname,
            kwargs_create={"lb_client": lb_client, "module": module},
            list_fn=lb_client.list_hostnames,
            kwargs_list={"load_balancer_id": module.params.get("load_balancer_id")},
            module=module,
            model=CreateHostnameDetails(),
        )

    return result
def create_or_update_backend(lb_client, module):

    backend = None
    result = dict(
        changed=False,
        backend=''
    )
    lb_id = module.params.get('load_balancer_id')
    backend_set_name = module.params.get('backend_set_name')
    backend = oci_utils.get_existing_resource(lb_client.get_backend, module,
                                              load_balancer_id=lb_id,
                                              backend_set_name=backend_set_name,
                                              backend_name=oci_lb_utils.get_backend_name(module))
    try:
        if backend:
            result = update_backend(
                lb_client, module, backend, lb_id, backend_set_name)
        else:
            result = oci_utils.check_and_create_resource(resource_type='backend',
                                                         create_fn=create_backend,
                                                         kwargs_create={'lb_client': lb_client,
                                                                        'module': module,
                                                                        'lb_id': lb_id,
                                                                        'backend_set_name': backend_set_name},
                                                         list_fn=lb_client.list_backends,
                                                         kwargs_list={
                                                             'load_balancer_id': lb_id,
                                                             'backend_set_name': backend_set_name},
                                                         module=module,
                                                         model=CreateBackendDetails())
    except ServiceError as ex:
        get_logger().error("Unable to create/update backend due to: %s", ex.message)
        module.fail_json(msg=ex.message)
    except ClientError as ex:
        get_logger().error("Unable to create/update backend due to: %s", str(ex))
        module.fail_json(msg=str(ex))

    return result
Beispiel #29
0
def delete_group(identity_client, module):
    group_id = module.params.get('group_id')
    force = module.params.get('force')
    compartment_id = module.params.get('compartment_id')
    changed = False
    result = dict(changed=False, )
    try:
        existing_group = oci_utils.get_existing_resource(
            identity_client.get_group, module, group_id=group_id)
        if existing_group:
            if force == 'yes':
                delete_all_users_from_group(identity_client, compartment_id,
                                            existing_group)
            oci_utils.call_with_backoff(identity_client.delete_group,
                                        group_id=existing_group.id)
            changed = True
    except ServiceError as ex:
        module.fail_json(msg=ex.message)
    except MaximumWaitTimeExceeded as ex:
        module.fail_json(msg=ex.args)

    result['changed'] = changed
    result['group'] = to_dict(existing_group)
    return result
def create_or_update_dhcp_options(virtual_network_client, module):
    result = dict(changed=False, dhcp_options='')
    dhcp_id = module.params.get('dhcp_id')
    exclude_attributes = {'display_name': True}
    try:
        if dhcp_id:
            existing_dhcp_options = oci_utils.get_existing_resource(
                virtual_network_client.get_dhcp_options,
                module,
                dhcp_id=dhcp_id)
            result = update_dhcp_options(virtual_network_client,
                                         existing_dhcp_options, module)
        else:
            result = oci_utils.check_and_create_resource(
                resource_type='dhcp_options',
                create_fn=create_dhcp_options,
                kwargs_create={
                    'virtual_network_client': virtual_network_client,
                    'module': module
                },
                list_fn=virtual_network_client.list_dhcp_options,
                kwargs_list={
                    'compartment_id': module.params.get('compartment_id'),
                    'vcn_id': module.params.get('vcn_id')
                },
                module=module,
                exclude_attributes=exclude_attributes,
                model=CreateDhcpDetails())
    except ServiceError as ex:
        module.fail_json(msg=ex.message)
    except MaximumWaitTimeExceeded as ex:
        module.fail_json(msg=str(ex))
    except ClientError as ex:
        module.fail_json(msg=ex.args[0])

    return result