Class: Chef::Provisioning::ManagedEntry

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

Overview

Specification for a managed thing. Remembers where it was stored, and lets you stuff reference data in it.

Direct Known Subclasses

LoadBalancerSpec, MachineImageSpec, MachineSpec

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(managed_entry_store, resource_type, name, data = nil) ⇒ ManagedEntry

Returns a new instance of ManagedEntry.



8
9
10
11
12
13
# File 'lib/chef/provisioning/managed_entry.rb', line 8

def initialize(managed_entry_store, resource_type, name, data=nil)
  @managed_entry_store = managed_entry_store
  @resource_type = resource_type
  @name = name
  @data = data || {}
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



18
19
20
# File 'lib/chef/provisioning/managed_entry.rb', line 18

def data
  @data
end

#managed_entry_storeObject (readonly)

Returns the value of attribute managed_entry_store.



15
16
17
# File 'lib/chef/provisioning/managed_entry.rb', line 15

def managed_entry_store
  @managed_entry_store
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/chef/provisioning/managed_entry.rb', line 17

def name
  @name
end

#resource_typeObject (readonly)

Returns the value of attribute resource_type.



16
17
18
# File 'lib/chef/provisioning/managed_entry.rb', line 16

def resource_type
  @resource_type
end

Instance Method Details

#attrsObject



20
21
22
# File 'lib/chef/provisioning/managed_entry.rb', line 20

def attrs
  data
end

#delete(action_handler) ⇒ Object



72
73
74
# File 'lib/chef/provisioning/managed_entry.rb', line 72

def delete(action_handler)
  managed_entry_store.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)


112
113
114
# File 'lib/chef/provisioning/managed_entry.rb', line 112

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

#driver_urlObject

URL to the driver.



56
57
58
# File 'lib/chef/provisioning/managed_entry.rb', line 56

def driver_url
  attrs['driver_url'] || (reference ? reference['driver_url'] : nil)
end

#driver_url=(value) ⇒ Object



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

def driver_url=(value)
  attrs['driver_url'] = value
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, or ‘nil` if the data does not exist. Will be JSON- and YAML-compatible (Hash, Array, String, Integer, Boolean, Nil)

Raises:

  • (NotImplementedError)


89
90
91
# File 'lib/chef/provisioning/managed_entry.rb', line 89

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

#idObject

Globally unique identifier for this machine. Does not depend on the machine’s reference or existence.



28
29
30
# File 'lib/chef/provisioning/managed_entry.rb', line 28

def id
  managed_entry_store.identifier(resource_type, name)
end

#identifier(resource_type, name) ⇒ Object

Raises:

  • (NotImplementedError)


116
117
118
# File 'lib/chef/provisioning/managed_entry.rb', line 116

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

#referenceObject

Reference to this managed thing. This should be a freeform hash, with enough information for the driver to look it up and create a Machine object to access it.

This MUST include a ‘driver_url’ attribute with the driver’s URL in it.

chef-provisioning will do its darnedest to not lose this information.



41
42
43
44
45
46
# File 'lib/chef/provisioning/managed_entry.rb', line 41

def reference
  # Backcompat: old data bags didn't have the "reference" field.  If we have
  # no reference field in the data, and the data bag is non-empty, return
  # the root of the data bag.
  attrs['reference'] || attrs['location'] || (attrs == {} ? nil : attrs)
end

#reference=(value) ⇒ Object

Set the reference for this machine.



51
52
53
# File 'lib/chef/provisioning/managed_entry.rb', line 51

def reference=(value)
  self.attrs['reference'] = value
end

#save(action_handler) ⇒ Object

Save this node to the server. If you have significant information that could be lost, you should do this as quickly as possible. Data will be saved automatically for you after allocate_machine and ready_machine.



68
69
70
# File 'lib/chef/provisioning/managed_entry.rb', line 68

def save(action_handler)
  managed_entry_store.save_data(resource_type, name, data, action_handler)
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)


100
101
102
# File 'lib/chef/provisioning/managed_entry.rb', line 100

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