Class: Puppet_X::EnterpriseModules::Oci::AssociatedArrayProperty

Inherits:
AssociatedProperty
  • Object
show all
Defined in:
lib/puppet_x/enterprisemodules/oci/associated_array_property.rb

Overview

Docs

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AssociatedProperty

association, association_add, association_from, association_model, association_name, association_remove, association_to, #before_destroy, client, puppet_type, #resolver

Methods included from Config

#client_for, #config_for_settings, #default_tenant, #determine_setting_for, #proxy_config, #retry_config, #settings_for, #tenant_config

Methods included from Settings

#configuration, included, #read_from_yaml, #setting_for, #settings, #settings_file

Class Method Details

.translate_to_resource(raw_resource, _resource) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/puppet_x/enterprisemodules/oci/associated_array_property.rb', line 13

def self.translate_to_resource(raw_resource, _resource)
  resource_id         = raw_resource['id']
  tenant              = raw_resource['tenant']
  compartment_id      = raw_resource['compartment_id']
  availability_domain = raw_resource['availability_domain']
  resolver            = Puppet_X::EnterpriseModules::Oci::NameResolver.instance(tenant)
  assoc_records = case association_to
                  when :boot_volume_id
                    client(tenant).send("list_#{association_name}s", availability_domain, compartment_id, association_from => resource_id).data.select(&:present?)
                  else
                    client(tenant).send("list_#{association_name}s", compartment_id, association_from => resource_id).data.select(&:present?)
                  end
  assoc_records.map(&association_to).collect do |assoc_id|
    Puppet.debug "Resolving resource name for #{assoc_id}"
    resolver.ocid_to_name(tenant, assoc_id)
  end
rescue OCI::Errors::ServiceError => e
  #
  # If we are not autorized, return an empty Hash and leave the property blank
  #
  raise unless e.service_code == 'NotAuthorizedOrNotFound'

  Puppet.debug "Skip fetching property #{name} because of an authorization failure."
  []
end

Instance Method Details

#after_applyObject



8
9
10
11
# File 'lib/puppet_x/enterprisemodules/oci/associated_array_property.rb', line 8

def after_apply
  removed_records.each { |r| remove_record_by_name(r) }
  added_records.each { |r| add_record(r) }
end