How to use the ansible.module_utils.oracle.oci_utils.create_service_client function in ansible

To help you get started, we’ve selected a few ansible examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oracle / oci-ansible-modules / library / oci_ip_sec_connection_device_status_facts.py View on Github external
def main():
    module_args = oci_utils.get_common_arg_spec()
    module_args.update(dict(ipsc_id=dict(type="str", required=True, aliases=["id"])))

    module = AnsibleModule(argument_spec=module_args, supports_check_mode=False)

    if not HAS_OCI_PY_SDK:
        module.fail_json(msg="oci python sdk required for this module.")

    virtual_network_client = oci_utils.create_service_client(
        module, VirtualNetworkClient
    )

    ip_sec_connection_id = module.params["ipsc_id"]
    try:
        result = to_dict(
            oci_utils.call_with_backoff(
                virtual_network_client.get_ip_sec_connection_device_status,
                ipsc_id=ip_sec_connection_id,
            ).data
        )
    except ServiceError as ex:
        module.fail_json(msg=ex.message)

    module.exit_json(ip_sec_connection_device_status=result)
github oracle / oci-ansible-modules / library / oci_virtual_circuit_public_prefix_facts.py View on Github external
module_args.update(
        dict(
            virtual_circuit_id=dict(type="str", required=False, aliases=["id"]),
            verification_state=dict(
                type="str",
                required=False,
                choices=["IN_PROGRESS", "COMPLETED", "FAILED"],
            ),
        )
    )
    module = AnsibleModule(argument_spec=module_args)

    if not HAS_OCI_PY_SDK:
        module.fail_json(msg="oci python sdk required for this module")

    virtual_network_client = oci_utils.create_service_client(
        module, VirtualNetworkClient
    )

    result = list_virtual_circuit_public_prefixes(virtual_network_client, module)

    module.exit_json(**result)
github oracle / oci-ansible-modules / library / oci_smtp_credential.py View on Github external
description=dict(type="str", required=False),
            state=dict(
                type="str",
                required=False,
                default="present",
                choices=["present", "absent"],
            ),
        )
    )

    module = AnsibleModule(argument_spec=module_args)

    if not HAS_OCI_PY_SDK:
        module.fail_json(msg="oci python sdk required for this module")

    identity_client = oci_utils.create_service_client(module, IdentityClient)
    state = module.params["state"]

    if state == "present":
        result = create_or_update_smtp_credential(identity_client, module)
    elif state == "absent":
        result = delete_smtp_credential(identity_client, module)

    module.exit_json(**result)
github oracle / oci-ansible-modules / library / oci_cpe_facts.py View on Github external
dict(
            compartment_id=dict(type="str", required=False),
            cpe_id=dict(type="str", required=False, aliases=["id"]),
        )
    )

    module = AnsibleModule(
        argument_spec=module_args,
        supports_check_mode=False,
        required_one_of=[["compartment_id", "cpe_id"]],
    )

    if not HAS_OCI_PY_SDK:
        module.fail_json(msg="oci python sdk required for this module.")

    virtual_network_client = oci_utils.create_service_client(
        module, VirtualNetworkClient
    )

    cpe_id = module.params["cpe_id"]
    compartment_id = module.params["compartment_id"]
    result = []

    try:
        if cpe_id is not None:
            result = [
                to_dict(
                    oci_utils.call_with_backoff(
                        virtual_network_client.get_cpe, cpe_id=cpe_id
                    ).data
                )
            ]
github oracle / oci-ansible-modules / library / oci_volume_backup_facts.py View on Github external
],
            ),
        )
    )

    module = AnsibleModule(
        argument_spec=module_args,
        supports_check_mode=False,
        mutually_exclusive=[["compartment_id", "volume_backup_id"]],
        required_one_of=[["compartment_id", "volume_backup_id"]],
    )

    if not HAS_OCI_PY_SDK:
        module.fail_json(msg="oci python sdk required for this module.")

    block_storage_client = oci_utils.create_service_client(module, BlockstorageClient)

    volume_backup_id = module.params["volume_backup_id"]

    try:
        if volume_backup_id is not None:
            result = [
                to_dict(
                    oci_utils.call_with_backoff(
                        block_storage_client.get_volume_backup,
                        volume_backup_id=volume_backup_id,
                    ).data
                )
            ]

        else:
            compartment_id = module.params["compartment_id"]
github oracle / oci-ansible-modules / library / oci_load_balancer_certificate_facts.py View on Github external
def main():
    logger = oci_utils.get_logger("oci_load_balancer_certificate_facts")
    set_logger(logger)
    module_args = oci_utils.get_common_arg_spec()
    module_args.update(
        dict(
            name=dict(type="str", required=False),
            load_balancer_id=dict(type="str", required=True, aliases=["id"]),
        )
    )
    module = AnsibleModule(argument_spec=module_args)

    if not HAS_OCI_PY_SDK:
        module.fail_json(msg="oci python sdk required for this module")

    lb_client = oci_utils.create_service_client(module, LoadBalancerClient)
    result = list_load_balancer_certificates(lb_client, module)

    module.exit_json(**result)
github oracle / oci-ansible-modules / library / oci_local_peering_gateway.py View on Github external
def matching_lpg_exists(
    virtual_network_client, module, lpg, peer_lpg, lpg_vcn, peer_vcn
):
    tenancy = oci_utils.get_oci_config(module)["tenancy"]
    identity_client = oci_utils.create_service_client(module, IdentityClient)
    compartments = []
    try:
        compartments = oci_utils.list_all_resources(
            identity_client.list_compartments,
            compartment_id=tenancy,
            compartment_id_in_subtree=True,
        )
    except ServiceError as ex:
        if ex.status == 403:
            pass
    similar_lpg = get_similar_lpg(
        compartments,
        virtual_network_client,
        lpg_vcn.cidr_block,
        peer_vcn.cidr_block,
        peer_lpg,
github oracle / oci-ansible-modules / library / oci_compartment.py View on Github external
parent_compartment_id=dict(type="str", required=False),
        )
    )

    module = AnsibleModule(
        argument_spec=module_args,
        supports_check_mode=False,
        # Name of the compartment `name` is required when `parent_compartment_id` is provided to create a compartment.
        required_if=[["parent_compartment_id", not None, ["name"]]],
        required_one_of=[["parent_compartment_id", "compartment_id"]],
    )

    if not HAS_OCI_PY_SDK:
        module.fail_json(msg="oci python sdk required for this module.")

    identity_client = oci_utils.create_service_client(module, IdentityClient)

    state = module.params["state"]

    if state == "present":
        # For backward compatibility if tenancy OCID is specified in module option `compartment_id` along with option
        # `name`, then process the task as a request to create a sub-compartment under root compartment. If option
        # `name` is not specified or non-root compartment id is provided, process the task as a request to update
        # root/non-root compartment details.
        if module.params["compartment_id"]:
            if (
                is_compartment_root(identity_client, module.params["compartment_id"])
                and module.params["name"]
            ):
                # Create a sub-compartment under root.
                result = oci_utils.check_and_create_resource(
                    resource_type="compartment",
github oracle / oci-ansible-modules / library / oci_instance_pool_instances_facts.py View on Github external
def main():
    module_args = oci_utils.get_common_arg_spec()
    module_args.update(
        dict(
            compartment_id=dict(type="str", required=True),
            instance_pool_id=dict(type="str", required=True, aliases=["id"]),
        )
    )

    module = AnsibleModule(argument_spec=module_args, supports_check_mode=False)

    if not HAS_OCI_PY_SDK:
        module.fail_json(msg="oci python sdk required for this module.")

    compute_management_client = oci_utils.create_service_client(
        module, ComputeManagementClient
    )
    compute_client = oci_utils.create_service_client(module, ComputeClient)

    try:
        compartment_id = module.params["compartment_id"]
        instance_pool_id = module.params["instance_pool_id"]
        instance_summaries = to_dict(
            oci_utils.list_all_resources(
                compute_management_client.list_instance_pool_instances,
                compartment_id=compartment_id,
                instance_pool_id=instance_pool_id,
            )
        )
        # Get model from summaries returned by `list_instance_pools_instances`
        result = to_dict(
github oracle / oci-ansible-modules / library / oci_node_pool_facts.py View on Github external
def main():
    module_args = oci_utils.get_facts_module_arg_spec(filter_by_name=True)
    module_args.update(
        dict(
            node_pool_id=dict(type="str", required=False, aliases=["id"]),
            cluster_id=dict(type="str", required=False),
            compartment_id=dict(type="str", required=False),
        )
    )

    module = AnsibleModule(argument_spec=module_args, supports_check_mode=False)

    if not HAS_OCI_PY_SDK:
        module.fail_json(msg="oci python sdk required for this module.")

    container_engine_client = oci_utils.create_service_client(
        module, ContainerEngineClient
    )

    node_pool_id = module.params["node_pool_id"]

    try:
        if node_pool_id is not None:
            result = [
                to_dict(
                    oci_utils.call_with_backoff(
                        container_engine_client.get_node_pool, node_pool_id=node_pool_id
                    ).data
                )
            ]
        else:
            if module.params["cluster_id"]: