class Chef::Provisioning::AWSDriver::AWSResourceWithEntry
Common AWS
resource - contains metadata that all AWS
resources will need
Attributes
managed_entry_id_name[R]
managed_entry_type[R]
Protected Class Methods
aws_sdk_type(sdk_class, id: :id, managed_entry_type: nil, managed_entry_id_name: "id", backcompat_data_bag_name: nil, **options)
click to toggle source
Calls superclass method
Chef::Provisioning::AWSDriver::AWSResource::aws_sdk_type
# File lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb, line 90 def self.aws_sdk_type(sdk_class, id: :id, managed_entry_type: nil, managed_entry_id_name: "id", backcompat_data_bag_name: nil, **options) super(sdk_class, id: id, **options) @managed_entry_type = managed_entry_type || resource_name.to_sym @managed_entry_id_name = managed_entry_id_name if backcompat_data_bag_name Chef::Provisioning::ChefManagedEntryStore.type_names_for_backcompat[resource_name] = backcompat_data_bag_name end end
Public Instance Methods
delete_managed_entry(action_handler)
click to toggle source
Dissociate the ID of this object from Chef
.
@param action_handler [Chef::Provisioning::ActionHandler] The action handler,
which handles progress reporting, update reporting ("little green text") and dry run.
# File lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb, line 13 def delete_managed_entry(action_handler) if should_have_managed_entry? managed_entry_store.delete(self.class.managed_entry_type, name, action_handler) end end
get_id_from_managed_entry()
click to toggle source
# File lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb, line 39 def get_id_from_managed_entry if should_have_managed_entry? entry = managed_entry_store.get(self.class.managed_entry_type, name) if entry driver = self.driver if entry.driver_url != driver.driver_url # TODO: some people don't send us run_context (like Drivers). We might need # to exit early here if the driver_url doesn't match the provided driver. driver = run_context.chef_provisioning.driver_for(entry.driver_url) end [driver, entry.reference[self.class.managed_entry_id_name], entry] end end end
save_managed_entry(aws_object, action_handler, existing_entry: nil)
click to toggle source
Save the ID of this object to Chef
.
@param aws_object [::Aws::EC2::Core] The AWS
object containing the ID. @param action_handler [Chef::Provisioning::ActionHandler] The action handler,
which handles progress reporting, update reporting ("little green text") and dry run.
@param existing_entry [Chef::Provisioning::ManagedEntry] The existing entry
(if any). If this is passed in, and no values are changed, we will not attempt to update it (this prevents us from retrieving it twice).
# File lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb, line 30 def save_managed_entry(aws_object, action_handler, existing_entry: nil) if should_have_managed_entry? managed_entry = existing_entry || managed_entry_store.new_entry(self.class.managed_entry_type, name) updated = update_managed_entry(aws_object, managed_entry) managed_entry.save(action_handler) if updated || !existing_entry end end
to_s()
click to toggle source
Formatted output for logging statements - contains resource type, resource name and aws object id (if available)
# File lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb, line 55 def to_s id = get_driver_and_id[1] "#{declared_type}[#{@name}] (#{id || 'no AWS object id'})" end
Protected Instance Methods
get_driver_and_id()
click to toggle source
# File lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb, line 80 def get_driver_and_id driver, id, entry = get_id_from_managed_entry # If the value isn't already stored, look up the user-specified public_ip unless id driver = self.driver id = public_send(self.class.aws_id_attribute) end [driver, id] end
should_have_managed_entry?()
click to toggle source
# File lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb, line 112 def should_have_managed_entry? name != public_send(self.class.aws_id_attribute) end
update_managed_entry(aws_object, managed_entry)
click to toggle source
Update an existing ManagedEntry object.
@return true if the entry was changed, and false if not
# File lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb, line 67 def update_managed_entry(aws_object, managed_entry) new_value = { self.class.managed_entry_id_name => aws_object.public_send(self.class.aws_sdk_class_id) } if managed_entry.reference != new_value managed_entry.reference = new_value changed = true end if managed_entry.driver_url != driver.driver_url managed_entry.driver_url = driver.driver_url changed = true end changed end