Class: Chef::Provisioning::AWSDriver::AWSResourceWithEntry

Inherits:
AWSResource
  • Object
show all
Defined in:
lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb

Overview

Common AWS resource - contains metadata that all AWS resources will need

Constant Summary

Constants inherited from AWSResource

Chef::Provisioning::AWSDriver::AWSResource::NOT_PASSED

Class Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AWSResource

#action, #action=, #aws_object, #aws_object_id, get_aws_object, get_aws_object_id, #initialize, lookup_options

Methods inherited from SuperLWRP

#_pv_is, attribute, lazy

Constructor Details

This class inherits a constructor from Chef::Provisioning::AWSDriver::AWSResource

Class Attribute Details

.managed_entry_id_nameObject (readonly)

Returns the value of attribute managed_entry_id_name.



109
110
111
# File 'lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb', line 109

def managed_entry_id_name
  @managed_entry_id_name
end

.managed_entry_typeObject (readonly)

Returns the value of attribute managed_entry_type.



105
106
107
# File 'lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb', line 105

def managed_entry_type
  @managed_entry_type
end

Instance Method Details

#delete_managed_entry(action_handler) ⇒ Object

Dissociate the ID of this object from Chef.

Parameters:

  • action_handler (Chef::Provisioning::ActionHandler)

    The action handler, which handles progress reporting, update reporting (“little green text”) and dry run.



13
14
15
16
17
# 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_entryObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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) ⇒ Object

Save the ID of this object to Chef.

Parameters:

  • aws_object (::Aws::EC2::Core)

    The AWS object containing the ID.

  • action_handler (Chef::Provisioning::ActionHandler)

    The action handler, which handles progress reporting, update reporting (“little green text”) and dry run.

  • existing_entry (Chef::Provisioning::ManagedEntry) (defaults to: nil)

    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).



30
31
32
33
34
35
36
37
# 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_sObject

Formatted output for logging statements - contains resource type, resource name and aws object id (if available)



55
56
57
58
# 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