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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AWSResource

#action, #action=, attribute, aws_id_attribute, aws_id_prefix, #aws_object, aws_option_handlers, aws_sdk_class, aws_sdk_class_id, aws_sdk_option_name, 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

Class Method Details

.aws_sdk_type(sdk_class, id: :id, managed_entry_type: nil, managed_entry_id_name: 'id', backcompat_data_bag_name: nil, **options) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb', line 96

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

.managed_entry_id_nameObject



114
115
116
# File 'lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb', line 114

def self.managed_entry_id_name
  @managed_entry_id_name
end

.managed_entry_typeObject



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

def self.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.



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