def get_resource(self): resources = self.list_resources() for resource in resources: if self.get_module_resource_id() == resource.id: return oci_common_utils.get_default_response_from_resource(resource) oci_common_utils.raise_does_not_exist_service_error()
def get_resource_using_name(self): name_parameter = self.get_resource_name_parameter() if not name_parameter: self.module.fail_json( msg="Resource does not have a {0} or not specified.".format( name_parameter ) ) existing_resources = [ existing_resource for existing_resource in self.list_resources() if hasattr(existing_resource, name_parameter) and getattr(existing_resource, name_parameter) == self.module.params.get(name_parameter) and self._is_resource_active(existing_resource) ] if len(existing_resources) > 1: self.module.fail_json( msg="Duplicate resources with {0} {1} exist.".format( name_parameter, self.module.params.get(name_parameter) ) ) elif len(existing_resources) == 0: oci_common_utils.raise_does_not_exist_service_error( message="Resource with {0} {1} does not exist.".format( name_parameter, self.module.params.get(name_parameter) ) ) return oci_common_utils.get_default_response_from_resource( resource=self.get_get_model_from_summary_model(existing_resources[0]) if self.is_summary_model(existing_resources[0]) else existing_resources[0] )
def get_resource(self): # normally get via list would be generated, but in this case the resource doesn't # have a GET or a LIST API so both are custom resources = self.list_resources() for resource in resources: if self.module.params["name"] == resource.name: return oci_common_utils.get_default_response_from_resource( resource) oci_common_utils.raise_does_not_exist_service_error()
def get_resource(self): app_catalog_subscriptions = oci_common_utils.list_all_resources( self.client.list_app_catalog_subscriptions, compartment_id=self.module.params["compartment_id"], listing_id=self.module.params["listing_id"], ) for app_catalog_subscription in app_catalog_subscriptions: if ( app_catalog_subscription.listing_resource_version == self.module.params["resource_version"] ): return oci_common_utils.get_default_response_from_resource( resource=app_catalog_subscription ) oci_common_utils.raise_does_not_exist_service_error( message="The app catalog subscription does not exist." )
def get_resource(self, *args, **kwargs): obj = get_object( self.client, self.module.params.get("namespace_name"), self.module.params.get("bucket_name"), self.module.params.get("object_name"), ) if not obj: oci_common_utils.raise_does_not_exist_service_error() head_response = oci_common_utils.call_with_backoff( self.client.head_object, namespace_name=self.module.params.get("namespace_name"), bucket_name=self.module.params.get("bucket_name"), object_name=self.module.params.get("object_name"), ) return oci_common_utils.get_default_response_from_resource( obj, headers=head_response.headers)
def get_resource(self): # The API endpoint for getting endpoint intermittently fails with 404. CLI has the same issue as well so it # should be an API issue. The console uses the get_resolver endpoint to get the details of endpoints as well. # So using the same here as well. resolver = oci_common_utils.call_with_backoff( self.client.get_resolver, resolver_id=self.module.params.get("resolver_id"), scope=self.module.params.get("scope"), ).data endpoints = resolver.endpoints or [] for endpoint in endpoints: if endpoint.name == self.module.params.get("name"): return oci_common_utils.get_default_response_from_resource( resource=self.get_get_model_from_summary_model(endpoint)) return oci_common_utils.raise_does_not_exist_service_error()
def get_resource(self): vanity_url_list = self.list_resources() for resource in vanity_url_list: resource_dict = to_dict(resource) vanity_url_key = self.module.params.get("vanity_url_key") if vanity_url_key and vanity_url_key == resource_dict.get("key"): return oci_common_utils.get_default_response_from_resource( resource) elif oci_common_utils.compare_dicts( source_dict=self.module.params, target_dict=resource_dict, ignore_attr_if_not_in_target=True, ): return oci_common_utils.get_default_response_from_resource( resource) return oci_common_utils.raise_does_not_exist_service_error()
def get_resource(self): private_access_channels = self.list_resources() if private_access_channels: for channel in private_access_channels: resource_dict = to_dict(channel) private_access_channel_key = self.module.params.get( "private_access_channel_key") if (private_access_channel_key and private_access_channel_key == channel.key): return oci_common_utils.get_default_response_from_resource( resource=channel) elif oci_common_utils.compare_dicts( source_dict=self.module.params, target_dict=resource_dict, ignore_attr_if_not_in_target=True, ): return oci_common_utils.get_default_response_from_resource( resource=channel) return oci_common_utils.raise_does_not_exist_service_error()