Ejemplo n.º 1
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
def delete_smtp_credential(identity_client, module):
    result = oci_utils.delete_and_wait(
        resource_type=RESOURCE_NAME,
        client=identity_client,
        get_fn=oci_utils.get_target_resource_from_list,
        kwargs_get={
            "module": module,
            "list_resource_fn": identity_client.list_smtp_credentials,
            "target_resource_id": module.params.get("smtp_credential_id"),
            "user_id": module.params.get("user_id"),
        },
        delete_fn=identity_client.delete_smtp_credential,
        kwargs_delete={
            "user_id": module.params["user_id"],
            "smtp_credential_id": module.params["smtp_credential_id"],
        },
        module=module,
        wait_applicable=False,
    )
    # XXX: The smtp credential is not returned after it is deleted,
    # and so we currently reuse the earlier smtp credential object and mark
    # its lifecycle state as DELETED.
    # We also don't wait, as there is no state transition that we need to wait for.
    if result["changed"]:
        smtp_credential = result[RESOURCE_NAME]
        smtp_credential["lifecycle_state"] = "DELETED"
        result[RESOURCE_NAME] = smtp_credential
    return result
Ejemplo n.º 3
0
def handle_delete_auth_token(identity_client, module):
    result = oci_utils.delete_and_wait(
        resource_type=RESOURCE_NAME,
        client=identity_client,
        get_fn=oci_utils.get_target_resource_from_list,
        kwargs_get={
            'module': module,
            'list_resource_fn': identity_client.list_auth_tokens,
            'target_resource_id': module.params.get('auth_token_id'),
            'user_id': module.params.get('user_id')
        },
        delete_fn=identity_client.delete_auth_token,
        kwargs_delete={
            "user_id": module.params['user_id'],
            "auth_token_id": module.params["auth_token_id"]
        },
        module=module,
        wait_applicable=False)
    # XXX: The auth token is not returned by list auth tokens after it
    # is deleted, and so we currently reuse the earlier auth token object and mark
    # its lifecycle state as DELETED.
    # We also don't wait, as there is no state transition that we need to wait for.
    if result['changed']:
        auth_token = result[RESOURCE_NAME]
        auth_token['lifecycle_state'] = "DELETED"
        result[RESOURCE_NAME] = auth_token
    return result
Ejemplo n.º 4
0
def delete_image(compute_client, id, module):
    return oci_utils.delete_and_wait(resource_type=RESOURCE_NAME,
                                     client=compute_client,
                                     get_fn=compute_client.get_image,
                                     kwargs_get={"image_id": id},
                                     delete_fn=compute_client.delete_image,
                                     kwargs_delete={"image_id": id},
                                     module=module)
def delete_dhcp_options(virtual_network_client, module):
    return oci_utils.delete_and_wait(
        resource_type='dhcp_options',
        client=virtual_network_client,
        get_fn=virtual_network_client.get_dhcp_options,
        kwargs_get={'dhcp_id': module.params['dhcp_id']},
        delete_fn=virtual_network_client.delete_dhcp_options,
        kwargs_delete={'dhcp_id': module.params['dhcp_id']},
        module=module)
Ejemplo n.º 6
0
def delete_internet_gateway(virtual_network_client, module):
    return oci_utils.delete_and_wait(
        resource_type='internet_gateway',
        client=virtual_network_client,
        get_fn=virtual_network_client.get_internet_gateway,
        kwargs_get={'ig_id': module.params['ig_id']},
        delete_fn=virtual_network_client.delete_internet_gateway,
        kwargs_delete={'ig_id': module.params['ig_id']},
        module=module)
def handle_delete_boot_volume(block_storage_client, module):
    return oci_utils.delete_and_wait(resource_type="boot_volume",
                                     client=block_storage_client,
                                     get_fn=block_storage_client.get_boot_volume,
                                     kwargs_get={"boot_volume_id": module.params["boot_volume_id"]},
                                     delete_fn=block_storage_client.delete_boot_volume,
                                     kwargs_delete={"boot_volume_id": module.params["boot_volume_id"]},
                                     module=module
                                     )
def delete_route_table(virtual_network_client, module):
    return oci_utils.delete_and_wait(
        resource_type='route_table',
        client=virtual_network_client,
        get_fn=virtual_network_client.get_route_table,
        kwargs_get={'rt_id': module.params['rt_id']},
        delete_fn=virtual_network_client.delete_route_table,
        kwargs_delete={'rt_id': module.params['rt_id']},
        module=module)
Ejemplo n.º 9
0
def delete_subnet(virtual_network_client, module):
    return oci_utils.delete_and_wait(
        resource_type="subnet",
        client=virtual_network_client,
        get_fn=virtual_network_client.get_subnet,
        kwargs_get={"subnet_id": module.params["subnet_id"]},
        delete_fn=virtual_network_client.delete_subnet,
        kwargs_delete={"subnet_id": module.params["subnet_id"]},
        module=module)
def delete_cross_connect(virtual_network_client, module):
    return oci_utils.delete_and_wait(
        resource_type="cross_connect",
        client=virtual_network_client,
        get_fn=virtual_network_client.get_cross_connect,
        kwargs_get={"cross_connect_id": module.params["cross_connect_id"]},
        delete_fn=virtual_network_client.delete_cross_connect,
        kwargs_delete={"cross_connect_id": module.params["cross_connect_id"]},
        module=module,
    )
Ejemplo n.º 11
0
def delete_public_ip(virtual_network_client, module):
    result = oci_utils.delete_and_wait(
        resource_type="public_ip",
        client=virtual_network_client,
        get_fn=virtual_network_client.get_public_ip,
        kwargs_get={"public_ip_id": module.params["public_ip_id"]},
        delete_fn=virtual_network_client.delete_public_ip,
        kwargs_delete={"public_ip_id": module.params["public_ip_id"]},
        module=module)
    return result
Ejemplo n.º 12
0
def delete_db_home(db_client, module):
    result = oci_utils.delete_and_wait(
        resource_type='db_home',
        client=db_client,
        get_fn=db_client.get_db_home,
        kwargs_get={'db_home_id': module.params['db_home_id']},
        delete_fn=db_client.delete_db_home,
        kwargs_delete={'db_home_id': module.params['db_home_id']},
        module=module)
    return result
Ejemplo n.º 13
0
def delete_instance_pool(compute_management_client, module):
    result = oci_utils.delete_and_wait(resource_type=RESOURCE_NAME,
                                       client=compute_management_client,
                                       get_fn=compute_management_client.get_instance_pool,
                                       kwargs_get={"instance_pool_id": module.params['instance_pool_id']},
                                       delete_fn=compute_management_client.terminate_instance_pool,
                                       kwargs_delete={"instance_pool_id": module.params['instance_pool_id']},
                                       module=module
                                       )
    return result
def delete_security_list(virtual_network_client, module):
    result = oci_utils.delete_and_wait(
        resource_type="security_list",
        client=virtual_network_client,
        get_fn=virtual_network_client.get_security_list,
        kwargs_get={"security_list_id": module.params["security_list_id"]},
        delete_fn=virtual_network_client.delete_security_list,
        kwargs_delete={"security_list_id": module.params["security_list_id"]},
        module=module)
    return result
Ejemplo n.º 15
0
def delete_drg_attachment(virtual_network_client, module):
    result = oci_utils.delete_and_wait(resource_type="drg_attachment",
                                       client=virtual_network_client,
                                       get_fn=virtual_network_client.get_drg_attachment,
                                       kwargs_get={"drg_attachment_id": module.params["drg_attachment_id"]},
                                       delete_fn=virtual_network_client.delete_drg_attachment,
                                       kwargs_delete={"drg_attachment_id": module.params["drg_attachment_id"]},
                                       module=module
                                       )
    return result
Ejemplo n.º 16
0
def delete_policy(identity_client, module):
    result = oci_utils.delete_and_wait(
        resource_type="policy",
        client=identity_client,
        get_fn=identity_client.get_policy,
        kwargs_get={"policy_id": module.params["policy_id"]},
        delete_fn=identity_client.delete_policy,
        kwargs_delete={"policy_id": module.params["policy_id"]},
        module=module)
    return result
Ejemplo n.º 17
0
def delete_zone(dns_client, module):
    result = oci_utils.delete_and_wait(
        resource_type="zone",
        client=dns_client,
        get_fn=dns_client.get_zone,
        kwargs_get={"zone_name_or_id": get_zone_name_or_id(module)},
        delete_fn=dns_client.delete_zone,
        kwargs_delete={"zone_name_or_id": get_zone_name_or_id(module)},
        module=module)
    return result
Ejemplo n.º 18
0
def delete_vcn(virtual_network_client, module):
    result = oci_utils.delete_and_wait(
        resource_type="vcn",
        client=virtual_network_client,
        get_fn=virtual_network_client.get_vcn,
        kwargs_get={"vcn_id": module.params["vcn_id"]},
        delete_fn=virtual_network_client.delete_vcn,
        kwargs_delete={"vcn_id": module.params["vcn_id"]},
        module=module)
    return result
def delete_ip_sec_connection(virtual_network_client, module):
    result = oci_utils.delete_and_wait(
        resource_type="ip_sec_connection",
        client=virtual_network_client,
        get_fn=virtual_network_client.get_ip_sec_connection,
        kwargs_get={"ipsc_id": module.params["ipsc_id"]},
        delete_fn=virtual_network_client.delete_ip_sec_connection,
        kwargs_delete={"ipsc_id": module.params["ipsc_id"]},
        module=module)
    return result
def handle_delete_volume_group(block_storage_client, module):
    return oci_utils.delete_and_wait(
        resource_type="volume_group",
        client=block_storage_client,
        get_fn=block_storage_client.get_volume_group,
        kwargs_get={"volume_group_id": module.params["volume_group_id"]},
        delete_fn=block_storage_client.delete_volume_group,
        kwargs_delete={"volume_group_id": module.params["volume_group_id"]},
        module=module,
    )
Ejemplo n.º 21
0
def delete_dynamic_group(identity_client, module):
    result = oci_utils.delete_and_wait(
        resource_type="dynamic_group",
        client=identity_client,
        get_fn=identity_client.get_dynamic_group,
        kwargs_get={"dynamic_group_id": module.params["dynamic_group_id"]},
        delete_fn=identity_client.delete_dynamic_group,
        kwargs_delete={"dynamic_group_id": module.params["dynamic_group_id"]},
        module=module)
    return result
Ejemplo n.º 22
0
def delete_identity_provider(identity_client, module):
    result = oci_utils.delete_and_wait(
        resource_type=RESOURCE_TYPE,
        client=identity_client,
        get_fn=identity_client.get_identity_provider,
        kwargs_get={"identity_provider_id": module.params["identity_provider_id"]},
        delete_fn=identity_client.delete_identity_provider,
        kwargs_delete={"identity_provider_id": module.params["identity_provider_id"]},
        module=module,
    )
    return result
Ejemplo n.º 23
0
def delete_backup(db_client, module):
    result = oci_utils.delete_and_wait(
        resource_type='backup',
        client=db_client,
        get_fn=db_client.get_backup,
        kwargs_get={'backup_id': module.params['backup_id']},
        delete_fn=db_client.delete_backup,
        kwargs_delete={'backup_id': module.params['backup_id']},
        module=module)

    return result
Ejemplo n.º 24
0
def delete_snapshot(file_storage_client, module):
    result = oci_utils.delete_and_wait(
        resource_type='snapshot',
        client=file_storage_client,
        get_fn=file_storage_client.get_snapshot,
        kwargs_get={'snapshot_id': module.params['snapshot_id']},
        delete_fn=file_storage_client.delete_snapshot,
        kwargs_delete={'snapshot_id': module.params['snapshot_id']},
        module=module)

    return result
Ejemplo n.º 25
0
def delete_sender(email_client, module):
    result = oci_utils.delete_and_wait(
        resource_type='sender',
        client=email_client,
        get_fn=email_client.get_sender,
        kwargs_get={'sender_id': module.params['sender_id']},
        delete_fn=email_client.delete_sender,
        kwargs_delete={'sender_id': module.params['sender_id']},
        module=module)

    return result
Ejemplo n.º 26
0
def delete_cpe(virtual_network_client, module):
    result = oci_utils.delete_and_wait(
        resource_type="cpe",
        client=virtual_network_client,
        get_fn=virtual_network_client.get_cpe,
        kwargs_get={"cpe_id": module.params["cpe_id"]},
        delete_fn=virtual_network_client.delete_cpe,
        kwargs_delete={"cpe_id": module.params["cpe_id"]},
        module=module,
        wait_applicable=False)
    return result
Ejemplo n.º 27
0
def delete_db_system(db_client, module):
    result = oci_utils.delete_and_wait(
        resource_type='db_system',
        client=db_client,
        get_fn=db_client.get_db_system,
        kwargs_get={'db_system_id': module.params['db_system_id']},
        delete_fn=db_client.terminate_db_system,
        kwargs_delete={'db_system_id': module.params['db_system_id']},
        module=module)

    return result
Ejemplo n.º 28
0
def delete_nat_gateway(virtual_network_client, module):
    result = oci_utils.delete_and_wait(
        resource_type="nat_gateway",
        client=virtual_network_client,
        get_fn=virtual_network_client.get_nat_gateway,
        kwargs_get={"nat_gateway_id": module.params["nat_gateway_id"]},
        delete_fn=virtual_network_client.delete_nat_gateway,
        kwargs_delete={"nat_gateway_id": module.params["nat_gateway_id"]},
        module=module,
    )
    return result
Ejemplo n.º 29
0
def delete_certificate(waas_client, module):
    result = oci_utils.delete_and_wait(
        resource_type=RESOURCE_TYPE,
        client=waas_client,
        get_fn=waas_client.get_certificate,
        kwargs_get={"certificate_id": module.params["certificate_id"]},
        delete_fn=waas_client.delete_certificate,
        kwargs_delete={"certificate_id": module.params["certificate_id"]},
        module=module,
    )
    return result
Ejemplo n.º 30
0
def delete_db_home(db_client, module):
    result = oci_utils.delete_and_wait(
        resource_type="db_home",
        client=db_client,
        get_fn=db_client.get_db_home,
        kwargs_get={"db_home_id": module.params["db_home_id"]},
        delete_fn=db_client.delete_db_home,
        kwargs_delete={"db_home_id": module.params["db_home_id"]},
        module=module,
    )
    return result