Class: Dploy::ChefClient
- Inherits:
-
Object
- Object
- Dploy::ChefClient
- Defined in:
- lib/dploy/chef_client.rb
Instance Method Summary collapse
- #create_node(node) ⇒ Object
- #delete_node(node_name) ⇒ Object
- #get_node(name) ⇒ Object
- #get_nodes ⇒ Object
-
#initialize(server_url, user, key_path = nil) ⇒ ChefClient
constructor
A new instance of ChefClient.
- #put_node(node) ⇒ Object
- #symbolize(hash) ⇒ Object
- #update_node_attributes(node_name, attributes) ⇒ Object
Constructor Details
#initialize(server_url, user, key_path = nil) ⇒ ChefClient
Returns a new instance of ChefClient.
8 9 10 11 |
# File 'lib/dploy/chef_client.rb', line 8 def initialize(server_url, user, key_path = nil) key_path ||= "#{user}.pem" @rest_client = Chef::REST.new(server_url, user, key_path) end |
Instance Method Details
#create_node(node) ⇒ Object
31 32 33 |
# File 'lib/dploy/chef_client.rb', line 31 def create_node(node) symbolize(@rest_client.post_rest("nodes",node.to_json)) end |
#delete_node(node_name) ⇒ Object
35 36 37 |
# File 'lib/dploy/chef_client.rb', line 35 def delete_node(node_name) symbolize(@rest_client.delete_rest("nodes/#{node_name}")) end |
#get_node(name) ⇒ Object
23 24 25 |
# File 'lib/dploy/chef_client.rb', line 23 def get_node(name) symbolize(@rest_client.get_rest("nodes/#{name}")) end |
#get_nodes ⇒ Object
19 20 21 |
# File 'lib/dploy/chef_client.rb', line 19 def get_nodes @rest_client.get_rest("nodes") end |
#put_node(node) ⇒ Object
27 28 29 |
# File 'lib/dploy/chef_client.rb', line 27 def put_node(node) symbolize(@rest_client.put_rest("nodes/#{node[:name]}",node)) end |
#symbolize(hash) ⇒ Object
39 40 41 42 |
# File 'lib/dploy/chef_client.rb', line 39 def symbolize(hash) json_parse_opts = {:symbolize_names => true} JSON.parse(hash.to_json, json_parse_opts) end |
#update_node_attributes(node_name, attributes) ⇒ Object
13 14 15 16 17 |
# File 'lib/dploy/chef_client.rb', line 13 def update_node_attributes(node_name,attributes) node = get_node(node_name) node[:normal] = node[:normal].merge(attributes) symbolize(@rest_client.put_rest("nodes/#{node_name}",node)) end |