Пример #1
0
def create_db_home(db_client, module):
    create_db_home_details = None
    source = module.params.get("source")
    if source == "NONE":
        create_db_home_details = CreateDbHomeWithDbSystemIdDetails()
        create_db_home_details.database = oci_db_utils.create_database_details(
            module.params.get("database", None)
        )
        create_db_home_details.source = source
    elif source == "DB_BACKUP":
        create_db_home_details = CreateDbHomeWithDbSystemIdFromBackupDetails()
        create_db_home_details.database = create_database_from_backup_details(
            module.params.get("database", None)
        )
        create_db_home_details.source = source

    for attribute in create_db_home_details.attribute_map.keys():
        if attribute not in ("database", "source"):
            create_db_home_details.__setattr__(attribute, module.params.get(attribute))
    result = oci_utils.create_and_wait(
        resource_type="db_home",
        create_fn=db_client.create_db_home,
        kwargs_create={
            "create_db_home_with_db_system_id_details": create_db_home_details
        },
        client=db_client,
        get_fn=db_client.get_db_home,
        get_param="db_home_id",
        module=module,
    )
    return result
def create_service_gateway(virtual_network_client, module):
    create_service_gateway_details = CreateServiceGatewayDetails()
    for attribute in create_service_gateway_details.attribute_map.keys():
        if attribute in module.params:
            setattr(create_service_gateway_details, attribute,
                    module.params[attribute])

    list_of_request_details = []
    if module.params['services'] is not None:
        for req in module.params['services']:
            req_details = ServiceIdRequestDetails()
            req_details.service_id = req['service_id']
            list_of_request_details.append(req_details)
    create_service_gateway_details.services = list_of_request_details
    result = oci_utils.create_and_wait(
        resource_type="service_gateway",
        create_fn=virtual_network_client.create_service_gateway,
        kwargs_create={
            "create_service_gateway_details": create_service_gateway_details
        },
        client=virtual_network_client,
        get_fn=virtual_network_client.get_service_gateway,
        get_param="service_gateway_id",
        module=module)
    return result
Пример #3
0
def create_volume_backup(block_storage_client, module):
    cvbd = CreateVolumeBackupDetails()

    for attribute in cvbd.attribute_map.keys():
        if attribute in module.params:
            setattr(cvbd, attribute, module.params[attribute])

    get_logger().info("Creating a new volume backup.")

    result = oci_utils.create_and_wait(
        resource_type="volume_backup",
        create_fn=block_storage_client.create_volume_backup,
        kwargs_create={"create_volume_backup_details": cvbd},
        client=block_storage_client,
        get_fn=block_storage_client.get_volume_backup,
        get_param="volume_backup_id",
        module=module,
        states=[module.params['wait_until'], "FAULTY", "AVAILABLE"])

    if result['volume_backup']['lifecycle_state'] == "FAULTY":
        oci_utils.call_with_backoff(
            block_storage_client.delete_volume_backup,
            volume_backup_id=result['volume_backup']['id'])
        get_logger().info("Deleting volume backup as it reached FAULTY state.")
        module.fail_json(msg="Volume backup reached FAULTY state.")

    return result
def create_data_guard_association(db_client, module):
    result = dict(changed=False, data_guard_association="")
    database_id = module.params.get("database_id")

    try:
        create_data_guard_assoc_details = get_create_data_guard_association_from_creation_type(
            module)

        result = oci_utils.create_and_wait(
            resource_type="data_guard_association",
            create_fn=db_client.create_data_guard_association,
            kwargs_create={
                "database_id":
                database_id,
                "create_data_guard_association_details":
                create_data_guard_assoc_details,
            },
            client=db_client,
            get_fn=db_client.get_data_guard_association,
            get_param="database_id",
            module=module,
        )

    except ServiceError as ex:
        get_logger().error(
            "Unable to create Data Guard Association due to: %s", ex.message)
        module.fail_json(msg=ex.message)

    return result
Пример #5
0
def create_security_list(virtual_network_client, module):
    input_ingress_security_rules = module.params["ingress_security_rules"]
    input_egress_security_rules = module.params["egress_security_rules"]
    ingress_security_rules = []
    egress_security_rules = []
    if input_ingress_security_rules:
        ingress_security_rules = get_security_rules(
            "ingress_security_rules", input_ingress_security_rules
        )
    if input_egress_security_rules:
        egress_security_rules = get_security_rules(
            "egress_security_rules", input_egress_security_rules
        )
    create_security_list_details = CreateSecurityListDetails()
    for attribute in create_security_list_details.attribute_map:
        create_security_list_details.__setattr__(
            attribute, module.params.get(attribute)
        )
    create_security_list_details.ingress_security_rules = ingress_security_rules
    create_security_list_details.egress_security_rules = egress_security_rules
    result = oci_utils.create_and_wait(
        resource_type="security_list",
        create_fn=virtual_network_client.create_security_list,
        kwargs_create={"create_security_list_details": create_security_list_details},
        client=virtual_network_client,
        get_fn=virtual_network_client.get_security_list,
        get_param="security_list_id",
        module=module,
    )
    return result
Пример #6
0
def create_db_home(db_client, module):
    create_db_home_details = None
    source = module.params.get('source')
    if source == 'NONE':
        create_db_home_details = CreateDbHomeWithDbSystemIdDetails()
        create_db_home_details.database = oci_db_utils.create_database_details(
            module.params.get('database', None))
        create_db_home_details.source = source
    elif source == 'DB_BACKUP':
        create_db_home_details = CreateDbHomeWithDbSystemIdFromBackupDetails()
        create_db_home_details.database = create_database_from_backup_details(
            module.params.get('database', None))
        create_db_home_details.source = source

    for attribute in create_db_home_details.attribute_map.keys():
        if attribute != 'database' and attribute != 'source':
            create_db_home_details.__setattr__(attribute,
                                               module.params.get(attribute))
    result = oci_utils.create_and_wait(
        resource_type='db_home',
        create_fn=db_client.create_db_home,
        kwargs_create={
            'create_db_home_with_db_system_id_details': create_db_home_details
        },
        client=db_client,
        get_fn=db_client.get_db_home,
        get_param='db_home_id',
        module=module)
    return result
Пример #7
0
def launch_db_system(db_client, module):
    launch_db_system_details = None
    if module.params.get("source") == "DB_BACKUP":
        launch_db_system_details = LaunchDbSystemFromBackupDetails()
        launch_db_system_details.db_home = create_db_home_from_backup_details(
            module.params.get("db_home", None))
    else:
        launch_db_system_details = LaunchDbSystemDetails()
        launch_db_system_details.db_home = create_db_home(
            module.params.get("db_home", None))
    launch_db_system_details.ssh_public_keys = create_ssh_public_keys(
        module.params.get("ssh_public_keys", None))
    for attribute in launch_db_system_details.attribute_map:
        if attribute not in ("db_home", "ssh_public_keys"):
            launch_db_system_details.__setattr__(attribute,
                                                 module.params.get(attribute))
    result = oci_utils.create_and_wait(
        resource_type="db_system",
        create_fn=db_client.launch_db_system,
        kwargs_create={"launch_db_system_details": launch_db_system_details},
        client=db_client,
        get_fn=db_client.get_db_system,
        get_param="db_system_id",
        module=module,
    )

    return result
def create_remote_peering_connection(virtual_network_client, module):
    create_remote_peering_connection_details = CreateRemotePeeringConnectionDetails(
    )
    for attribute in create_remote_peering_connection_details.attribute_map.keys(
    ):
        if attribute in module.params:
            setattr(
                create_remote_peering_connection_details,
                attribute,
                module.params[attribute],
            )

    result = oci_utils.create_and_wait(
        resource_type="remote_peering_connection",
        create_fn=virtual_network_client.create_remote_peering_connection,
        kwargs_create={
            "create_remote_peering_connection_details":
            create_remote_peering_connection_details
        },
        client=virtual_network_client,
        get_fn=virtual_network_client.get_remote_peering_connection,
        get_param="remote_peering_connection_id",
        module=module,
    )
    return result
Пример #9
0
def create_instance_pool(compute_management_client, module):
    create_instance_pool_details = CreateInstancePoolDetails()
    _update_model_with_attrs(create_instance_pool_details, module.params)

    user_placement_configurations = module.params["placement_configurations"]
    placement_configurations = []
    for item in user_placement_configurations:
        placement_config = CreateInstancePoolPlacementConfigurationDetails()
        _update_model_with_attrs(placement_config, item)
        placement_configurations.append(placement_config)
    create_instance_pool_details.placement_configurations = placement_configurations
    user_load_balancers = module.params["load_balancers"]
    if user_load_balancers:
        load_balancers = []
        for lb in user_load_balancers:
            load_balancer = AttachLoadBalancerDetails()
            _update_model_with_attrs(load_balancer, lb)
            load_balancers.append(load_balancer)
        create_instance_pool_details.load_balancers = load_balancers
    result = oci_utils.create_and_wait(
        resource_type=RESOURCE_NAME,
        create_fn=compute_management_client.create_instance_pool,
        kwargs_create={
            "create_instance_pool_details": create_instance_pool_details
        },
        client=compute_management_client,
        get_fn=compute_management_client.get_instance_pool,
        get_param="instance_pool_id",
        module=module,
    )
    return result
Пример #10
0
def create_image(compute_client, module):
    cid = _get_create_image_details(module)
    return oci_utils.create_and_wait(
        resource_type=RESOURCE_NAME,
        client=compute_client,
        create_fn=compute_client.create_image,
        kwargs_create={"create_image_details": cid},
        get_fn=compute_client.get_image,
        get_param="image_id",
        module=module)
Пример #11
0
def create_subnet(virtual_network_client, module):
    create_subnet_details = CreateSubnetDetails()
    for attribute in create_subnet_details.attribute_map.keys():
        if attribute in module.params:
            setattr(create_subnet_details, attribute, module.params[attribute])

    return oci_utils.create_and_wait(
        resource_type="subnet",
        create_fn=virtual_network_client.create_subnet,
        kwargs_create={"create_subnet_details": create_subnet_details},
        client=virtual_network_client,
        get_fn=virtual_network_client.get_subnet,
        get_param="subnet_id",
        module=module)
Пример #12
0
def create_snapshot(file_storage_client, module):
    create_snapshot_details = CreateSnapshotDetails()
    for attribute in create_snapshot_details.attribute_map:
        create_snapshot_details.__setattr__(attribute,
                                            module.params.get(attribute))

    result = oci_utils.create_and_wait(
        resource_type='snapshot',
        create_fn=file_storage_client.create_snapshot,
        kwargs_create={'create_snapshot_details': create_snapshot_details},
        client=file_storage_client,
        get_fn=file_storage_client.get_snapshot,
        get_param='snapshot_id',
        module=module)
    return result
def create_autonomous_data_warehouse(db_client, module):
    create_autonomous_data_warehouse_details = CreateAutonomousDataWarehouseDetails()
    for attribute in create_autonomous_data_warehouse_details.attribute_map:
        create_autonomous_data_warehouse_details.__setattr__(attribute, module.params.get(attribute))

    result = oci_utils.create_and_wait(resource_type='autonomous_data_warehouse',
                                       create_fn=db_client.create_autonomous_data_warehouse,
                                       kwargs_create={
                                           'create_autonomous_data_warehouse_details': create_autonomous_data_warehouse_details},
                                       client=db_client,
                                       get_fn=db_client.get_autonomous_data_warehouse,
                                       get_param='autonomous_data_warehouse_id',
                                       module=module
                                       )
    return result
Пример #14
0
def create_compartment(identity_client, module):
    create_compartment_details = CreateCompartmentDetails()
    for attribute in create_compartment_details.attribute_map.keys():
        if attribute in module.params:
            setattr(create_compartment_details, attribute, module.params[attribute])

    result = oci_utils.create_and_wait(resource_type="compartment",
                                       create_fn=identity_client.create_compartment,
                                       kwargs_create={"create_compartment_details": create_compartment_details},
                                       client=identity_client,
                                       get_fn=identity_client.get_compartment,
                                       get_param="compartment_id",
                                       module=module
                                       )
    return result
Пример #15
0
def create_zone(dns_client, module):
    create_zone_details = CreateZoneDetails()
    for attribute in create_zone_details.attribute_map:
        if attribute in module.params:
            setattr(create_zone_details, attribute, module.params[attribute])

    result = oci_utils.create_and_wait(
        resource_type="zone",
        create_fn=dns_client.create_zone,
        kwargs_create={"create_zone_details": create_zone_details},
        client=dns_client,
        get_fn=dns_client.get_zone,
        get_param="zone_name_or_id",
        module=module)
    return result
Пример #16
0
def create_vcn(virtual_network_client, module):
    create_vcn_details = CreateVcnDetails()
    for attribute in create_vcn_details.attribute_map.keys():
        if attribute in module.params:
            setattr(create_vcn_details, attribute, module.params[attribute])

    result = oci_utils.create_and_wait(
        resource_type="vcn",
        create_fn=virtual_network_client.create_vcn,
        kwargs_create={"create_vcn_details": create_vcn_details},
        client=virtual_network_client,
        get_fn=virtual_network_client.get_vcn,
        get_param="vcn_id",
        module=module)
    return result
def create_mount_target(file_storage_client, module):
    create_mount_target_details = CreateMountTargetDetails()
    for attribute in create_mount_target_details.attribute_map:
        create_mount_target_details.__setattr__(attribute, module.params.get(attribute))

    result = oci_utils.create_and_wait(
        resource_type="mount_target",
        create_fn=file_storage_client.create_mount_target,
        kwargs_create={"create_mount_target_details": create_mount_target_details},
        client=file_storage_client,
        get_fn=file_storage_client.get_mount_target,
        get_param="mount_target_id",
        module=module,
    )
    return result
Пример #18
0
def create_export(file_storage_client, module):
    create_export_details = CreateExportDetails()
    for attribute in create_export_details.attribute_map:
        create_export_details.__setattr__(attribute, module.params.get(attribute))
    create_export_details.export_options = get_export_options(module.params.get('export_options', None))
    result = oci_utils.create_and_wait(resource_type='export',
                                       create_fn=file_storage_client.create_export,
                                       kwargs_create={
                                           'create_export_details': create_export_details},
                                       client=file_storage_client,
                                       get_fn=file_storage_client.get_export,
                                       get_param='export_id',
                                       module=module
                                       )
    return result
Пример #19
0
def create_sender(email_client, module):
    create_sender_details = CreateSenderDetails()
    for attribute in create_sender_details.attribute_map:
        create_sender_details.__setattr__(attribute,
                                          module.params.get(attribute))

    result = oci_utils.create_and_wait(
        resource_type='sender',
        create_fn=email_client.create_sender,
        kwargs_create={'create_sender_details': create_sender_details},
        client=email_client,
        get_fn=email_client.get_sender,
        get_param='sender_id',
        module=module)
    return result
def attach_volume(compute_client, module):
    attach_volume_details = AttachVolumeDetails()
    for attribute in attach_volume_details.attribute_map.keys():
        if attribute in module.params:
            setattr(attach_volume_details, attribute, module.params[attribute])

    result = oci_utils.create_and_wait(
        resource_type=RESOURCE_NAME,
        client=compute_client,
        create_fn=compute_client.attach_volume,
        kwargs_create={"attach_volume_details": attach_volume_details},
        get_fn=compute_client.get_volume_attachment,
        get_param="volume_attachment_id",
        module=module)
    return result
Пример #21
0
def create_internet_gateway(virtual_network_client, module):
    create_internet_gateway_details = CreateInternetGatewayDetails()
    for attribute in create_internet_gateway_details.attribute_map:
        attribute_value = module.params.get(attribute)
        create_internet_gateway_details.__setattr__(attribute, attribute_value)
    result = oci_utils.create_and_wait(
        resource_type='internet_gateway',
        create_fn=virtual_network_client.create_internet_gateway,
        kwargs_create={
            'create_internet_gateway_details': create_internet_gateway_details
        },
        client=virtual_network_client,
        get_fn=virtual_network_client.get_internet_gateway,
        get_param='ig_id',
        module=module)
    return result
def create_dhcp_options(virtual_network_client, module):
    options = get_options_objects(module.params['options'])
    create_dhcp_details = CreateDhcpDetails()
    for attribute in create_dhcp_details.attribute_map:
        create_dhcp_details.__setattr__(attribute,
                                        module.params.get(attribute))
    create_dhcp_details.options = options
    result = oci_utils.create_and_wait(
        resource_type='dhcp_options',
        create_fn=virtual_network_client.create_dhcp_options,
        kwargs_create={'create_dhcp_details': create_dhcp_details},
        client=virtual_network_client,
        get_fn=virtual_network_client.get_dhcp_options,
        get_param='dhcp_id',
        module=module)
    return result
Пример #23
0
def create_cpe(virtual_network_client, module):
    create_cpe_details = CreateCpeDetails()
    for attribute in create_cpe_details.attribute_map.keys():
        if attribute in module.params:
            setattr(create_cpe_details, attribute, module.params[attribute])

    result = oci_utils.create_and_wait(
        resource_type="cpe",
        create_fn=virtual_network_client.create_cpe,
        kwargs_create={"create_cpe_details": create_cpe_details},
        client=virtual_network_client,
        get_fn=virtual_network_client.get_cpe,
        get_param="cpe_id",
        module=module,
        wait_applicable=False)
    return result
Пример #24
0
def attach_vnic(compute_client, module):
    avd = AttachVnicDetails()
    avd.display_name = module.params.get("display_name", None)
    avd.instance_id = module.params.get("instance_id")
    avd.create_vnic_details = get_vnic_details(module)
    avd.nic_index = module.params.get("nic_index", None)

    result = oci_utils.create_and_wait(
        resource_type=RESOURCE_NAME,
        client=compute_client,
        create_fn=compute_client.attach_vnic,
        kwargs_create={"attach_vnic_details": avd},
        get_fn=compute_client.get_vnic_attachment,
        get_param="vnic_attachment_id",
        module=module)
    return result
Пример #25
0
def create_backup(db_client, module):
    result = dict(changed=False, backup='')
    create_backup_details = CreateBackupDetails()
    for attribute in create_backup_details.attribute_map:
        create_backup_details.__setattr__(attribute,
                                          module.params.get(attribute))
    result = oci_utils.create_and_wait(
        resource_type='backup',
        create_fn=db_client.create_backup,
        kwargs_create={'create_backup_details': create_backup_details},
        client=db_client,
        get_fn=db_client.get_backup,
        get_param='backup_id',
        module=module)

    return result
def execute_function_and_wait(resource_type,
                              client,
                              function,
                              kwargs_function,
                              get_fn,
                              get_param,
                              module,
                              states=None,
                              kwargs_get=None):
    return oci_utils.create_and_wait(resource_type=resource_type,
                                     create_fn=function,
                                     kwargs_create=kwargs_function,
                                     client=client,
                                     get_fn=get_fn,
                                     get_param='db_node_id',
                                     module=module,
                                     kwargs_get=kwargs_get)
Пример #27
0
def create_public_ip(virtual_network_client, module):
    create_public_ip_details = CreatePublicIpDetails()
    for attribute in create_public_ip_details.attribute_map.keys():
        if attribute in module.params:
            setattr(create_public_ip_details, attribute,
                    module.params[attribute])

    result = oci_utils.create_and_wait(
        resource_type="public_ip",
        create_fn=virtual_network_client.create_public_ip,
        kwargs_create={"create_public_ip_details": create_public_ip_details},
        client=virtual_network_client,
        get_fn=virtual_network_client.get_public_ip,
        get_param="public_ip_id",
        module=module,
    )
    return result
Пример #28
0
def create_certificate(waas_client, module):
    create_certificate_details = CreateCertificateDetails()
    for attr in create_certificate_details.attribute_map.keys():
        if attr in module.params:
            setattr(create_certificate_details, attr, module.params[attr])
    result = oci_utils.create_and_wait(
        resource_type=RESOURCE_TYPE,
        create_fn=waas_client.create_certificate,
        kwargs_create={
            "create_certificate_details": create_certificate_details
        },
        client=waas_client,
        get_fn=waas_client.get_certificate,
        get_param="certificate_id",
        module=module,
    )
    return result
def create_cross_connect(virtual_network_client, module):
    create_cross_connect_details = CreateCrossConnectDetails()
    for attribute in create_cross_connect_details.attribute_map:
        create_cross_connect_details.__setattr__(attribute,
                                                 module.params.get(attribute))
    result = oci_utils.create_and_wait(
        resource_type="cross_connect",
        create_fn=virtual_network_client.create_cross_connect,
        kwargs_create={
            "create_cross_connect_details": create_cross_connect_details
        },
        client=virtual_network_client,
        get_fn=virtual_network_client.get_cross_connect,
        get_param="cross_connect_id",
        module=module,
        states=["PENDING_CUSTOMER", "PENDING_PROVIDER", "PROVISIONED"],
    )
    return result
Пример #30
0
def create_volume_group_backup(block_storage_client, module):
    cvgbd = CreateVolumeGroupBackupDetails()

    for attribute in cvgbd.attribute_map.keys():
        if attribute in module.params:
            setattr(cvgbd, attribute, module.params[attribute])

    result = oci_utils.create_and_wait(
        resource_type="volume_group_backup",
        create_fn=block_storage_client.create_volume_group_backup,
        kwargs_create={"create_volume_group_backup_details": cvgbd},
        client=block_storage_client,
        get_fn=block_storage_client.get_volume_group_backup,
        get_param="volume_group_backup_id",
        module=module,
        states=[module.params['wait_until'], "FAULTY", "AVAILABLE"])

    return result