Class: Puppet_X::EnterpriseModules::Oci::AssociatedHashProperty
- Inherits:
-
AssociatedProperty
- Object
- Puppet::Property
- AssociatedProperty
- Puppet_X::EnterpriseModules::Oci::AssociatedHashProperty
- Defined in:
- lib/puppet_x/enterprisemodules/oci/associated_hash_property.rb
Overview
Docs
Class Method Summary collapse
- .resource_data(_tenant, record) ⇒ Object
- .resource_name(tenant, record) ⇒ Object
- .translate_to_resource(raw_resource, _resource) ⇒ Object
Instance Method Summary collapse
- #after_apply ⇒ Object
-
#change_to_s(current, should) ⇒ Object
Print a good change message when changing the contents of an array.
- #insync?(_) ⇒ Boolean
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
.resource_data(_tenant, record) ⇒ Object
69 70 71 72 |
# File 'lib/puppet_x/enterprisemodules/oci/associated_hash_property.rb', line 69 def self.resource_data(_tenant, record) data = record.to_hash.reject { |k, _v| k =~ /Ids?$/ || [:id, :lifecycleState, :timeCreated].include?(k) } data.to_puppet end |
.resource_name(tenant, record) ⇒ Object
64 65 66 67 |
# File 'lib/puppet_x/enterprisemodules/oci/associated_hash_property.rb', line 64 def self.resource_name(tenant, record) resolver = Puppet_X::EnterpriseModules::Oci::NameResolver.instance(tenant) resolver.ocid_to_name(tenant, record.send(association_to)) end |
.translate_to_resource(raw_resource, _resource) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/puppet_x/enterprisemodules/oci/associated_hash_property.rb', line 39 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'] 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.each_with_object({}) do |assoc_record, value| Puppet.debug "Resolving resource name for #{assoc_record.puppet_name}" value[resource_name(tenant, assoc_record)] = resource_data(tenant, assoc_record) 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_apply ⇒ Object
34 35 36 37 |
# File 'lib/puppet_x/enterprisemodules/oci/associated_hash_property.rb', line 34 def after_apply (removed_records + updated_records).each { |r| remove_record_by_name(r) } (added_records + updated_records).each { |r| add_record(r, requested_value[r]) } end |
#change_to_s(current, should) ⇒ Object
Print a good change message when changing the contents of an array
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/puppet_x/enterprisemodules/oci/associated_hash_property.rb', line 11 def change_to_s(current, should) return if insync?(current) = [] << "removing #{removed_records.join(', ')}" if removed_records.any? << "adding #{added_records.join(', ')}" if added_records.any? all_changes = should.only_change_diff(current_value) all_changes.each do |resource, resource_changes| resource_changes.each do |property, change| next if property.nil? || change.nil? change[0] = change[0].nil? ? :absent : change[0] change[1] = change[1].nil? ? :absent : change[1] << "changing #{property} of #{resource} from #{change[1]} to #{change[0]}" end end .join(' and ') << '.' end |
#insync?(_) ⇒ Boolean
30 31 32 |
# File 'lib/puppet_x/enterprisemodules/oci/associated_hash_property.rb', line 30 def insync?(_) should.only_change_diff(current_value).values.all? { |v| v == {} } end |