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 launch_or_update_db_system(db_client, module):
    result = dict(changed=False, db_system="")
    db_system_id = module.params.get("db_system_id")
    exclude_attributes = {
        "display_name": True,
        "domain": True,
        "node_count": True
    }
    try:
        if db_system_id is not None:
            result = update_db_system(db_client, module, db_system_id)
        else:
            module_copy = copy.deepcopy(module)
            module_copy.params.update({
                "ssh_public_keys":
                to_dict(
                    create_ssh_public_keys(
                        module_copy.params.get("ssh_public_keys")))
            })
            result = oci_utils.check_and_create_resource(
                resource_type="db_system",
                create_fn=launch_db_system,
                kwargs_create={
                    "db_client": db_client,
                    "module": module
                },
                list_fn=db_client.list_db_systems,
                kwargs_list={
                    "compartment_id": module.params.get("compartment_id")
                },
                module=module_copy,
                exclude_attributes=exclude_attributes,
                model=LaunchDbSystemDetails(),
            )

    except ServiceError as ex:
        get_logger().error(
            "Unable to launch/update database system due to: %s", ex.message)
        module.fail_json(msg=ex.message)
    except ClientError as ex:
        get_logger().error(
            "Unable to launch/update database system due to: %s", str(ex))
        module.fail_json(msg=str(ex))

    return result
Esempio n. 3
0
def launch_db_system(db_client, module):
    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