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.



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.resource_name, name, action_handler)
  end
end

#get_id_from_managed_entryObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb', line 41

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.



30
31
32
33
34
35
36
37
38
39
# 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.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)



57
58
59
60
# File 'lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb', line 57

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