Class: ChefMetal::ChefImageSpec
- Defined in:
- lib/chef_metal/chef_image_spec.rb
Overview
Specification for a image. Sufficient information to find and contact it after it has been set up.
Instance Attribute Summary
Attributes inherited from ImageSpec
Class Method Summary collapse
-
.empty(id, chef_server = Cheffish.default_chef_server) ⇒ Object
Creates a new empty ImageSpec with the given name.
-
.get(name, chef_server = Cheffish.default_chef_server) ⇒ Object
Get a ImageSpec from the chef server.
- .id_from(chef_server, name) ⇒ Object
Instance Method Summary collapse
- #delete(action_handler) ⇒ Object
-
#id ⇒ Object
Globally unique identifier for this image.
-
#initialize(node, chef_server) ⇒ ChefImageSpec
constructor
A new instance of ChefImageSpec.
-
#save(action_handler) ⇒ Object
Save this node to the server.
Methods inherited from ImageSpec
#driver_url, #location, #location=, #machine_options, #machine_options=, #name
Constructor Details
#initialize(node, chef_server) ⇒ ChefImageSpec
Returns a new instance of ChefImageSpec.
11 12 13 14 |
# File 'lib/chef_metal/chef_image_spec.rb', line 11 def initialize(node, chef_server) super(node) @chef_server = chef_server end |
Class Method Details
.empty(id, chef_server = Cheffish.default_chef_server) ⇒ Object
Creates a new empty ImageSpec with the given name.
36 37 38 |
# File 'lib/chef_metal/chef_image_spec.rb', line 36 def self.empty(id, chef_server = Cheffish.default_chef_server) ChefImageSpec.new({ 'id' => id }, chef_server) end |
.get(name, chef_server = Cheffish.default_chef_server) ⇒ Object
Get a ImageSpec from the chef server. If the node does not exist on the server, it returns nil.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/chef_metal/chef_image_spec.rb', line 20 def self.get(name, chef_server = Cheffish.default_chef_server) chef_api = Cheffish.chef_server_api(chef_server) begin data = chef_api.get("/data/images/#{name}") data['machine_options'] = strings_to_symbols(data['machine_options']) ChefImageSpec.new(data, 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_metal/chef_image_spec.rb', line 48 def self.id_from(chef_server, name) "#{chef_server[:chef_server_url]}/data/images/#{name}" end |
Instance Method Details
#delete(action_handler) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/chef_metal/chef_image_spec.rb', line 70 def delete(action_handler) # Save the node to the server. _self = self _chef_server = _self.chef_server ChefMetal.inline_resource(action_handler) do chef_data_bag_item _self.name do data_bag 'images' chef_server _chef_server action :destroy end end end |
#id ⇒ Object
Globally unique identifier for this image. Does not depend on the image’s location or existence.
44 45 46 |
# File 'lib/chef_metal/chef_image_spec.rb', line 44 def id ChefImageSpec.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_image and ready_image.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/chef_metal/chef_image_spec.rb', line 57 def save(action_handler) # Save the node to the server. _self = self _chef_server = _self.chef_server ChefMetal.inline_resource(action_handler) do chef_data_bag_item _self.name do data_bag 'images' chef_server _chef_server raw_data _self.image_data end end end |