Class: Chef::Provisioning::ChefMachineSpec
- Inherits:
-
MachineSpec
- Object
- MachineSpec
- Chef::Provisioning::ChefMachineSpec
- Defined in:
- lib/chef/provisioning/chef_machine_spec.rb
Overview
Specification for a machine. Sufficient information to find and contact it after it has been set up.
Instance Attribute Summary
Attributes inherited from MachineSpec
Class Method Summary collapse
-
.empty(name, chef_server = Cheffish.default_chef_server) ⇒ Object
Creates a new empty MachineSpec with the given name.
-
.get(name, chef_server = Cheffish.default_chef_server) ⇒ Object
Get a MachineSpec from the chef server.
- .id_from(chef_server, name) ⇒ Object
Instance Method Summary collapse
-
#id ⇒ Object
Globally unique identifier for this machine.
-
#initialize(node, chef_server) ⇒ ChefMachineSpec
constructor
A new instance of ChefMachineSpec.
-
#save(action_handler) ⇒ Object
Save this node to the server.
Methods inherited from MachineSpec
#driver_url, #location, #location=, #name
Constructor Details
#initialize(node, chef_server) ⇒ ChefMachineSpec
Returns a new instance of ChefMachineSpec.
13 14 15 16 |
# File 'lib/chef/provisioning/chef_machine_spec.rb', line 13 def initialize(node, chef_server) super(node) @chef_server = chef_server end |
Class Method Details
.empty(name, chef_server = Cheffish.default_chef_server) ⇒ Object
Creates a new empty MachineSpec with the given name.
36 37 38 |
# File 'lib/chef/provisioning/chef_machine_spec.rb', line 36 def self.empty(name, chef_server = Cheffish.default_chef_server) ChefMachineSpec.new({ 'name' => name, 'normal' => {} }, chef_server) end |
.get(name, chef_server = Cheffish.default_chef_server) ⇒ Object
Get a MachineSpec from the chef server. If the node does not exist on the server, it returns nil.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/chef/provisioning/chef_machine_spec.rb', line 22 def self.get(name, chef_server = Cheffish.default_chef_server) chef_api = Cheffish.chef_server_api(chef_server) begin ChefMachineSpec.new(chef_api.get("/nodes/#{name}"), chef_server) rescue Net::HTTPServerException => e if e.response.code == '404' nil else raise end end end |
.id_from(chef_server, name) ⇒ Object
48 49 50 |
# File 'lib/chef/provisioning/chef_machine_spec.rb', line 48 def self.id_from(chef_server, name) "#{chef_server[:chef_server_url]}/nodes/#{name}" end |
Instance Method Details
#id ⇒ Object
Globally unique identifier for this machine. Does not depend on the machine’s location or existence.
44 45 46 |
# File 'lib/chef/provisioning/chef_machine_spec.rb', line 44 def id ChefMachineSpec.id_from(chef_server, 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.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/chef/provisioning/chef_machine_spec.rb', line 57 def save(action_handler) if location && (!location.is_a?(Hash) || !location['driver_url']) raise "Drivers must specify a canonical driver_url in machine_spec.location. Contact your driver's author." end # Save the node to the server. _self = self _chef_server = _self.chef_server Chef::Provisioning.inline_resource(action_handler) do chef_node _self.name do chef_server _chef_server raw_json _self.node end end end |