Class: Chef::Provisioning::ChefLoadBalancerSpec

Inherits:
LoadBalancerSpec show all
Defined in:
lib/chef/provisioning/chef_load_balancer_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 LoadBalancerSpec

#load_balancer_data, #machines

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LoadBalancerSpec

#driver_url, #location, #location=, #name

Constructor Details

#initialize(node, chef_server) ⇒ ChefLoadBalancerSpec

Returns a new instance of ChefLoadBalancerSpec


12
13
14
15
# File 'lib/chef/provisioning/chef_load_balancer_spec.rb', line 12

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/provisioning/chef_load_balancer_spec.rb', line 36

def self.empty(id, chef_server = Cheffish.default_chef_server)
  ChefLoadBalancerSpec.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.


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/chef/provisioning/chef_load_balancer_spec.rb', line 21

def self.get(name, chef_server = Cheffish.default_chef_server)
  chef_api = Cheffish.chef_server_api(chef_server)
  begin
    data = chef_api.get("/data/loadbalancers/#{name}")
    ChefLoadBalancerSpec.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/provisioning/chef_load_balancer_spec.rb', line 48

def self.id_from(chef_server, name)
  "#{chef_server[:chef_server_url]}/data/loadbalancers/#{name}"
end

Instance Method Details

#delete(action_handler) ⇒ Object


71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/chef/provisioning/chef_load_balancer_spec.rb', line 71

def delete(action_handler)
  # Save the node to the server.
  _self = self
  _chef_server = _self.chef_server
  Chef::Provisioning.inline_resource(action_handler) do
    chef_data_bag_item _self.name do
      data_bag 'loadbalancers'
      chef_server _chef_server
      action :destroy
    end
  end
end

#idObject

Globally unique identifier for this image. Does not depend on the image's location or existence.


44
45
46
# File 'lib/chef/provisioning/chef_load_balancer_spec.rb', line 44

def id
  ChefLoadBalancerSpec.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
69
# File 'lib/chef/provisioning/chef_load_balancer_spec.rb', line 57

def save(action_handler)
  # Save the node to the server.
  _self = self
  _chef_server = _self.chef_server
  Chef::Provisioning.inline_resource(action_handler) do
    chef_data_bag 'loadbalancers'
    chef_data_bag_item _self.name do
      data_bag 'loadbalancers'
      chef_server _chef_server
      raw_data _self.load_balancer_data
    end
  end
end