Exemplo n.º 1
0
 def update_resource(self):
     update_details = self.get_update_model()
     return oci_common_utils.call_with_backoff(
         self.client.update_configuration,
         compartment_id=self.module.params.get("compartment_id"),
         update_configuration_details=update_details,
     )
Exemplo n.º 2
0
 def delete_resource(self):
     api_key = self.get_resource().data
     return oci_common_utils.call_with_backoff(
         self.client.delete_api_key,
         user_id=self.module.params.get("user_id"),
         fingerprint=api_key.fingerprint,
     )
Exemplo n.º 3
0
 def stop(self):
     return oci_common_utils.call_with_backoff(
         self.client.stop_autonomous_data_warehouse,
         autonomous_data_warehouse_id=self.module.params.get(
             "autonomous_data_warehouse_id"
         ),
     )
def create_service_client(module, service_client_class):
    """
    Creates a service client using the common module options provided by the user.
    :param module: An AnsibleModule that represents user provided options for a Task
    :param service_client_class: A class that represents a client to an OCI Service
    :return: A fully configured client
    """
    config = get_oci_config(module, service_client_class)
    kwargs = {}

    if _is_instance_principal_auth(module):
        kwargs["signer"] = _create_instance_principal_signer(module)

    # XXX: Validate configuration -- this may be redundant, as all Client constructors perform a validation
    try:
        oci.config.validate_config(config, **kwargs)
    except oci.exceptions.InvalidConfig as ic:
        module.fail_json(
            msg="Invalid OCI configuration. Exception: {0}".format(str(ic)))

    # Create service client class (optionally with signer)
    client = service_client_class(config, **kwargs)

    # Redirect calls to home region for IAM service.
    do_not_redirect = module.params.get(
        "do_not_redirect_to_home_region",
        False) or os.environ.get("OCI_IDENTITY_DO_NOT_REDIRECT_TO_HOME_REGION")

    if service_client_class == IdentityClient and not do_not_redirect:

        if "tenancy" in config:
            tenancy_id = config["tenancy"]
        elif hasattr(kwargs.get("signer"), "tenancy_id"):
            # the instance principals signer has the tenancy ID from the certificate from the
            # local metadata service
            tenancy_id = kwargs.get("signer").tenancy_id
        else:
            module.fail_json(
                msg=
                "Could not identify tenancy OCID from config or local metadata service"
            )

        region_subscriptions = oci_common_utils.call_with_backoff(
            client.list_region_subscriptions, tenancy_id=tenancy_id).data

        # Replace the region for the client with the home region.
        home_regions = [
            rs.region_name for rs in region_subscriptions
            if rs.is_home_region is True
        ]
        if len(home_regions) == 0:
            module.fail_json(
                msg="Could not identify home region for this tenancy")

        home_region = home_regions[0]

        client.base_client.set_region(home_region)
        set_db_test_flag(client)

    return client
Exemplo n.º 5
0
 def create_resource(self):
     create_details = self.get_create_model()
     return oci_common_utils.call_with_backoff(
         self.client.create_alert_rule,
         budget_id=self.module.params.get("budget_id"),
         create_alert_rule_details=create_details,
     )
Exemplo n.º 6
0
 def update_resource(self):
     update_details = self.get_update_model()
     return oci_common_utils.call_with_backoff(
         self.client.update_drg,
         drg_id=self.module.params.get("drg_id"),
         update_drg_details=update_details,
     )
Exemplo n.º 7
0
 def get_resource(self):
     optional_get_method_params = ["compartment_id"]
     optional_kwargs = dict((param, self.module.params[param])
                            for param in optional_get_method_params
                            if self.module.params.get(param) is not None)
     return oci_common_utils.call_with_backoff(self.client.get_namespace,
                                               **optional_kwargs)
Exemplo n.º 8
0
    def create_resource(self):
        create_api_key_details = self.get_create_model()
        create_response = oci_common_utils.call_with_backoff(
            self.client.upload_api_key,
            user_id=self.module.params.get("user_id"),
            create_api_key_details=create_api_key_details,
        )
        api_key_id = create_response.data.key_id

        # wait until the api key is active.
        # The following logic manually checks if the API key in `list_api_keys` has reached the desired ACTIVE state
        response = self.client.list_api_keys(self.module.params.get("user_id"))

        def is_api_key_active(response):
            for api_key in response.data:
                if api_key.key_id == api_key_id and api_key.lifecycle_state == "ACTIVE":
                    return True
            return False

        # wait until the created API Key reaches Active state
        wait_response = oci.wait_until(self.client,
                                       response,
                                       evaluate_response=is_api_key_active)

        api_keys = wait_response.data
        created_api_key = None
        for api_key in api_keys:
            if api_key.key_id == api_key_id:
                created_api_key = api_key

        return created_api_key
Exemplo n.º 9
0
 def get_resource(self):
     return oci_common_utils.call_with_backoff(
         self.client.get_network_security_group,
         network_security_group_id=self.module.params.get(
             "network_security_group_id"
         ),
     )
 def get_resource(self):
     return oci_common_utils.call_with_backoff(
         self.client.get_auto_scaling_configuration,
         auto_scaling_configuration_id=self.module.params.get(
             "auto_scaling_configuration_id"
         ),
     )
 def create_wait(self, create_response):
     work_request_response = self.wait_for_work_request(
         create_response, oci_common_utils.WORK_REQUEST_COMPLETED_STATES
     )
     for work_request_resource in work_request_response.data.resources:
         if (
             work_request_resource.entity_type == "waas"
             and work_request_resource.action_type == "CREATED"
         ):
             waas_policy_id = work_request_resource.identifier
             break
     if not waas_policy_id:
         self.module.fail_json(
             msg="Cound not get the waas policy id from the work request."
         )
     waas_policy = oci_common_utils.call_with_backoff(
         self.client.get_waas_policy, waas_policy_id=waas_policy_id
     ).data
     if not waas_policy:
         self.module.fail_json(
             "Could not get the waas policy resource after creation."
         )
     if waas_policy.lifecycle_state in oci_common_utils.DEAD_STATES:
         self.module.fail_json(
             msg="WAAS policy created but in {0} state.".format(
                 waas_policy.lifecycle_state
             )
         )
     return waas_policy
Exemplo n.º 12
0
 def create_resource(self):
     create_api_key_details = self.get_create_model()
     return oci_common_utils.call_with_backoff(
         self.client.upload_api_key,
         user_id=self.module.params.get("user_id"),
         create_api_key_details=create_api_key_details,
     )
Exemplo n.º 13
0
 def delete_resource(self):
     return oci_common_utils.call_with_backoff(
         self.client.delete_autonomous_data_warehouse,
         autonomous_data_warehouse_id=self.module.params.get(
             "autonomous_data_warehouse_id"
         ),
     )
 def create_resource(self):
     create_autonomous_data_warehouse_details = self.get_create_model()
     return oci_common_utils.call_with_backoff(
         self.client.create_autonomous_data_warehouse,
         create_autonomous_data_warehouse_details=
         create_autonomous_data_warehouse_details,
     )
 def list_resources(self):
     return [
         oci_common_utils.call_with_backoff(
             self.client.get_waas_policy,
             waas_policy_id=waas_policy_summary.id).data
         for waas_policy_summary in super(WaasPolicyHelperCustom,
                                          self).list_resources()
     ]
 def update_resource(self):
     update_details = self.get_update_model()
     return oci_common_utils.call_with_backoff(
         self.client.put_object_lifecycle_policy,
         namespace_name=self.module.params.get("namespace_name"),
         bucket_name=self.module.params.get("bucket_name"),
         put_object_lifecycle_policy_details=update_details,
     )
 def copy(self):
     action_details = convert_input_data_to_model_class(
         self.module.params, CopyVolumeBackupDetails)
     return oci_common_utils.call_with_backoff(
         self.client.copy_volume_backup,
         volume_backup_id=self.module.params.get("volume_backup_id"),
         copy_volume_backup_details=action_details,
     )
 def export(self):
     action_details = convert_input_data_to_model_class(
         self.module.params, ExportImageDetails)
     return oci_common_utils.call_with_backoff(
         self.client.export_image,
         image_id=self.module.params.get("image_id"),
         export_image_details=action_details,
     )
Exemplo n.º 19
0
 def update_resource(self):
     update_details = self.get_update_model()
     return oci_common_utils.call_with_backoff(
         self.client.update_autonomous_exadata_infrastructure,
         autonomous_exadata_infrastructure_id=self.module.params.get(
             "autonomous_exadata_infrastructure_id"),
         update_autonomous_exadata_infrastructures_details=update_details,
     )
Exemplo n.º 20
0
 def update_resource(self):
     update_details = self.get_update_model()
     return oci_common_utils.call_with_backoff(
         self.client.update_alert_rule,
         budget_id=self.module.params.get("budget_id"),
         alert_rule_id=self.module.params.get("alert_rule_id"),
         update_alert_rule_details=update_details,
     )
 def update_resource(self):
     update_details = self.get_update_model()
     return oci_common_utils.call_with_backoff(
         self.client.update_network_security_group,
         network_security_group_id=self.module.params.get(
             "network_security_group_id"
         ),
         update_network_security_group_details=update_details,
     )
Exemplo n.º 22
0
 def get_compartment_id(self, resource_id_name, resource_get):
     compartment_id = self.module.params.get("compartment_id")
     resource_id = self.module.params.get(resource_id_name)
     if not compartment_id and resource_id:
         try:
             return oci_common_utils.call_with_backoff(
                 resource_get, resource_id).data.compartment_id
         except Exception:
             return None
     return compartment_id
Exemplo n.º 23
0
 def update_resource(self):
     update_details = self.get_update_model()
     return oci_common_utils.call_with_backoff(
         self.client.update_auto_scaling_policy,
         auto_scaling_configuration_id=self.module.params.get(
             "auto_scaling_configuration_id"
         ),
         auto_scaling_policy_id=self.module.params.get("auto_scaling_policy_id"),
         update_auto_scaling_policy_details=update_details,
     )
 def copy_object(self):
     action_details = convert_input_data_to_model_class(
         self.module.params, CopyObjectDetails
     )
     return oci_common_utils.call_with_backoff(
         self.client.copy_object,
         namespace_name=self.module.params.get("namespace_name"),
         bucket_name=self.module.params.get("bucket_name"),
         copy_object_details=action_details,
     )
 def restore_objects(self):
     action_details = convert_input_data_to_model_class(
         self.module.params, RestoreObjectsDetails
     )
     return oci_common_utils.call_with_backoff(
         self.client.restore_objects,
         namespace_name=self.module.params.get("namespace_name"),
         bucket_name=self.module.params.get("bucket_name"),
         restore_objects_details=action_details,
     )
Exemplo n.º 26
0
    def list_resources(self):
        auto_scaling_configuration_summaries = super(
            AutoScalingConfigurationHelperCustom, self
        ).list_resources()
        auto_scaling_configurations = [
            oci_common_utils.call_with_backoff(
                self.client.get_auto_scaling_configuration,
                auto_scaling_configuration_id=auto_scaling_configuration.id,
            ).data
            for auto_scaling_configuration in auto_scaling_configuration_summaries
        ]

        return auto_scaling_configurations
 def restore(self):
     restore_autonomous_data_warehouse_details = (
         RestoreAutonomousDataWarehouseDetails())
     for attr in restore_autonomous_data_warehouse_details.attribute_map:
         if self.module.params.get(attr) is None:
             continue
         setattr(
             restore_autonomous_data_warehouse_details,
             attr,
             self.module.params.get(attr),
         )
     return oci_common_utils.call_with_backoff(
         self.client.generate_autonomous_data_warehouse_wallet,
         autonomous_data_warehouse_id=self.module.params.get(
             "autonomous_data_warehouse_id"),
         restore_autonomous_data_warehouse_details=
         restore_autonomous_data_warehouse_details,
     )
 def generate_wallet(self):
     generate_autonomous_data_warehouse_wallet_details = (
         GenerateAutonomousDataWarehouseWalletDetails())
     for attr in generate_autonomous_data_warehouse_wallet_details.attribute_map:
         if self.module.params.get(attr) is None:
             continue
         setattr(
             generate_autonomous_data_warehouse_wallet_details,
             attr,
             self.module.params.get(attr),
         )
     return oci_common_utils.call_with_backoff(
         self.client.generate_autonomous_data_warehouse_wallet,
         autonomous_data_warehouse_id=self.module.params.get(
             "autonomous_data_warehouse_id"),
         generate_autonomous_data_warehouse_wallet_details=
         generate_autonomous_data_warehouse_wallet_details,
     )
Exemplo n.º 29
0
def call_and_wait(
    call_fn,
    call_fn_args,
    call_fn_kwargs,
    waiter_type,
    operation,
    waiter_client,
    resource_helper,
    wait_for_states,
):
    """Call the given function and wait until the operation is completed and return the resource."""
    operation_response = oci_common_utils.call_with_backoff(
        call_fn, *call_fn_args, **call_fn_kwargs)
    waiter = get_waiter(
        waiter_type,
        operation,
        waiter_client,
        resource_helper,
        operation_response=operation_response,
        wait_for_states=wait_for_states,
    )
    return waiter.wait()
 def get_resource(self):
     return oci_common_utils.call_with_backoff(
         self.client.get_budget,
         budget_id=self.module.params.get("budget_id"))