Class: ChefMetal::MachineSpec
- Inherits:
-
Object
- Object
- ChefMetal::MachineSpec
- Defined in:
- lib/chef_metal/machine_spec.rb
Overview
Specification for a machine. Sufficient information to find and contact it after it has been set up.
Class Method Summary collapse
Instance Method Summary collapse
-
#id ⇒ Object
Globally unique identifier for this machine.
-
#initialize(node, chef_server) ⇒ MachineSpec
constructor
A new instance of MachineSpec.
-
#location ⇒ Object
Location of this machine.
-
#location=(value) ⇒ Object
Set the location for this machine.
-
#name ⇒ Object
Name of the machine.
-
#save(action_handler) ⇒ Object
Save this node to the server.
Constructor Details
#initialize(node, chef_server) ⇒ MachineSpec
Returns a new instance of MachineSpec.
10 11 12 13 |
# File 'lib/chef_metal/machine_spec.rb', line 10 def initialize(node, chef_server) @node = node @chef_server = chef_server end |
Class Method Details
.get(name, chef_server) ⇒ Object
15 16 17 18 |
# File 'lib/chef_metal/machine_spec.rb', line 15 def self.get(name, chef_server) rest = Cheffish::CheffishServerAPI.new(chef_server || Cheffish.current_chef_server) MachineSpec.new(rest.get("/nodes/#{name}"), chef_server) end |
Instance Method Details
#id ⇒ Object
Globally unique identifier for this machine. Does not depend on the machine’s location or existence.
24 25 26 |
# File 'lib/chef_metal/machine_spec.rb', line 24 def id "#{@chef_server[:chef_server_url]}/nodes/#{name}" end |
#location ⇒ Object
Location of this machine. This should be a freeform hash, with enough information for the provider to look it up and create a Machine object to access it.
This MUST include a ‘provider_url’ attribute with the provider’s URL in it.
chef-metal will do its darnedest to not lose this information.
44 45 46 |
# File 'lib/chef_metal/machine_spec.rb', line 44 def location ('location') end |
#location=(value) ⇒ Object
Set the location for this machine.
51 52 53 54 |
# File 'lib/chef_metal/machine_spec.rb', line 51 def location=(value) @node['normal']['metal'] ||= {} @node['normal']['metal']['spec'] = value end |
#name ⇒ Object
Name of the machine. Corresponds to the name in “machine ‘name’ do” …
31 32 33 |
# File 'lib/chef_metal/machine_spec.rb', line 31 def name @node['name'] 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.
61 62 63 64 65 66 67 68 69 |
# File 'lib/chef_metal/machine_spec.rb', line 61 def save(action_handler) # Save the node to the server. ChefMetal.inline_resource(action_handler) do chef_node node['name'] do chef_server @chef_server raw_json node end end end |