Class: Chef::Provisioning::ManagedEntryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/provisioning/managed_entry_store.rb

Direct Known Subclasses

ChefManagedEntryStore

Instance Method Summary collapse

Constructor Details

#initialize(chef_run_data) ⇒ ManagedEntryStore

Returns a new instance of ManagedEntryStore.


9
10
11
# File 'lib/chef/provisioning/managed_entry_store.rb', line 9

def initialize(chef_run_data)
  @chef_run_data = chef_run_data
end

Instance Method Details

#delete(resource_type, name, action_handler) ⇒ Boolean

Delete the given spec.

Parameters:

  • resource_type (Symbol)

    The type of spec to delete (:machine, :machine_image, :load_balancer, :aws_vpc, :aws_subnet, …)

  • name (String)

    The unique identifier of the spec to delete

Returns:

  • (Boolean)

    Whether anything was deleted or not.


115
116
117
# File 'lib/chef/provisioning/managed_entry_store.rb', line 115

def delete(resource_type, name, action_handler)
  delete_data(resource_type, name, action_handler)
end

#delete_data(resource_type, name, action_handler) ⇒ Boolean

Delete the given data

Parameters:

  • resource_type (Symbol)

    The type of thing to delete (:machine, :machine_image, :load_balancer, :aws_vpc, :aws_subnet, …)

  • name (String)

    The unique identifier of the thing to delete

Returns:

  • (Boolean)

    Whether anything was deleted or not.

Raises:

  • (NotImplementedError)

44
45
46
# File 'lib/chef/provisioning/managed_entry_store.rb', line 44

def delete_data(resource_type, name, action_handler)
  raise NotImplementedError, :delete_data
end

#get(resource_type, name) ⇒ ManagedEntry

Get a spec.

Parameters:

  • resource_type (Symbol)

    The type of spec to retrieve (:machine, :machine_image, :load_balancer, :aws_vpc, :aws_subnet, …)

  • name (String)

    The unique identifier of the spec to retrieve

Returns:

  • (ManagedEntry)

    The entry, or `nil` if the data does not exist.


71
72
73
74
75
76
# File 'lib/chef/provisioning/managed_entry_store.rb', line 71

def get(resource_type, name)
  data = get_data(resource_type, name)
  if data
    new_entry(resource_type, name, data)
  end
end

#get!(resource_type, name) ⇒ ManagedEntry

Get a spec, erroring out if the data does not exist.

Parameters:

  • resource_type (Symbol)

    The type of spec to retrieve (:machine, :machine_image, :load_balancer, :aws_vpc, :aws_subnet, …)

  • name (String)

    The unique identifier of the spec to retrieve

Returns:


99
100
101
102
103
104
105
# File 'lib/chef/provisioning/managed_entry_store.rb', line 99

def get!(resource_type, name)
  result = get(resource_type, name)
  if !result
    raise "#{identifier(resource_type, name)} not found!"
  end
  result
end

#get_data(resource_type, name) ⇒ Hash, Array

Get the given data

Parameters:

  • resource_type (Symbol)

    The type of thing to retrieve (:machine, :machine_image, :load_balancer, :aws_vpc, :aws_subnet, …)

  • name (String)

    The unique identifier of the thing to retrieve

Returns:

  • (Hash, Array)

    The data. Will be JSON- and YAML-compatible (Hash, Array, String, Integer, Boolean, Nil)

Raises:

  • (NotImplementedError)

21
22
23
# File 'lib/chef/provisioning/managed_entry_store.rb', line 21

def get_data(resource_type, name)
  raise NotImplementedError, :get_data
end

#get_or_new(resource_type, name) ⇒ ManagedEntry

Get a spec, or create a new one, depending on whether an entry exists.

Parameters:

  • resource_type (Symbol)

    The type of spec to retrieve (:machine, :machine_image, :load_balancer, :aws_vpc, :aws_subnet, …)

  • name (String)

    The unique identifier of the spec to retrieve

Returns:


86
87
88
89
# File 'lib/chef/provisioning/managed_entry_store.rb', line 86

def get_or_new(resource_type, name)
  data = get_data(resource_type, name)
  new_entry(resource_type, name, data)
end

#identifier(resource_type, name) ⇒ String

Get a globally unique identifier for this resource.

Examples:

ChefManagedEntry does this:

chef_managed_entry_store.identifier(:machine, 'mario') # => https://my.chef.server/organizations/org/nodes/mario

Parameters:

  • resource_type (Symbol)

    The type of spec to retrieve (:machine, :machine_image, :load_balancer, :aws_vpc, :aws_subnet, …)

  • name (String)

    The unique identifier of the spec to retrieve

Returns:

  • (String)

    The identifier.

Raises:

  • (NotImplementedError)

59
60
61
# File 'lib/chef/provisioning/managed_entry_store.rb', line 59

def identifier(resource_type, name)
  raise NotImplementedError, :identifier
end

#new_entry(resource_type, name, data = nil) ⇒ Object

Create a new managed entry of the given type.


122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/chef/provisioning/managed_entry_store.rb', line 122

def new_entry(resource_type, name, data=nil)
  case resource_type
  when :machine
    MachineSpec.new(self, resource_type, name, data)
  when :machine_image
    MachineImageSpec.new(self, resource_type, name, data)
  when :load_balancer
    LoadBalancerSpec.new(self, resource_type, name, data)
  else
    ManagedEntry.new(self, resource_type, name, data)
  end
end

#save_data(resource_type, name, data, action_handler) ⇒ Object

Save the given data

Parameters:

  • resource_type (Symbol)

    The type of thing to save (:machine, :machine_image, :load_balancer, :aws_vpc, :aws_subnet …)

  • name (String)

    The unique identifier of the thing to save

  • data (Hash, Array)

    The data to save. Must be JSON- and YAML-compatible (Hash, Array, String, Integer, Boolean, Nil)

Raises:

  • (NotImplementedError)

32
33
34
# File 'lib/chef/provisioning/managed_entry_store.rb', line 32

def save_data(resource_type, name, data, action_handler)
  raise NotImplementedError, :save_data
end