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

Instance Method Summary collapse

Methods inherited from AWSResource

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

Methods inherited from SuperLWRP

attribute, #load_prior_resource

Constructor Details

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

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.



20
21
22
23
24
# File 'lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb', line 20

def delete_managed_entry(action_handler)
  if should_have_managed_entry?
    managed_entry_store.delete(self.class.resource_name, name, action_handler)
  end
end

#get_id_from_managed_entryObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb', line 48

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



37
38
39
40
41
42
43
44
45
46
# File 'lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb', line 37

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.resource_name, name)
    updated = update_managed_entry(aws_object, managed_entry)
    if updated || !existing_entry
      managed_entry.save(action_handler)
    end
  end
end

#to_sObject

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



64
65
66
67
# File 'lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb', line 64

def to_s
  id = get_driver_and_id[1]
  "#{declared_type}[#{@name}] (#{ id ? id : 'no AWS object id'})"
end