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 Method Summary collapse

Instance Method Summary collapse

Methods inherited from AWSResource

#action, #action=, attribute, aws_id_attribute, aws_id_prefix, #aws_object, #aws_object_id, 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

#_pv_is, attribute, lazy

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



90
91
92
93
94
95
96
97
98
99
100
101
102
# 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

.managed_entry_id_nameObject



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

def self.managed_entry_id_name
  @managed_entry_id_name
end

.managed_entry_typeObject



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

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.



14
15
16
17
18
# File 'lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb', line 14

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



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

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



31
32
33
34
35
36
37
38
39
40
# File 'lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb', line 31

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



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

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