Class: Fog::Compute::ProfitBricks::LoadBalancer

Inherits:
Models::ProfitBricks::Base show all
Includes:
Helpers::ProfitBricks::DataHelper
Defined in:
lib/fog/profitbricks/models/compute/load_balancer.rb

Instance Method Summary collapse

Methods included from Helpers::ProfitBricks::DataHelper

#flatten

Methods inherited from Models::ProfitBricks::Base

#request_status, #wait_for

Constructor Details

#initialize(attributes = {}) ⇒ LoadBalancer

Returns a new instance of LoadBalancer.



30
31
32
# File 'lib/fog/profitbricks/models/compute/load_balancer.rb', line 30

def initialize(attributes = {})
  super
end

Instance Method Details

#associate_nic(nic_id) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/fog/profitbricks/models/compute/load_balancer.rb', line 101

def associate_nic(nic_id)
  requires :datacenter_id, :id

  response = service.associate_nic_to_load_balancer(datacenter_id, id, nic_id)

  flatten(response.body)
end

#deleteObject



63
64
65
66
67
# File 'lib/fog/profitbricks/models/compute/load_balancer.rb', line 63

def delete
  requires :datacenter_id, :id
  service.delete_load_balancer(datacenter_id, id)
  true
end

#failed?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/fog/profitbricks/models/compute/load_balancer.rb', line 121

def failed?
  state == 'ERROR'
end

#get_nic(nic_id) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/fog/profitbricks/models/compute/load_balancer.rb', line 93

def get_nic(nic_id)
  requires :datacenter_id, :id

  response = service.get_load_balanced_nic(datacenter_id, id, nic_id)

  flatten(response.body)
end

#list_nicsObject



85
86
87
88
89
90
91
# File 'lib/fog/profitbricks/models/compute/load_balancer.rb', line 85

def list_nics
  requires :datacenter_id, :id

  response = service.get_all_load_balanced_nics(datacenter_id, id)

  response.body['items'].each { |load_balanced_nic| flatten(load_balanced_nic) }
end

#ready?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/fog/profitbricks/models/compute/load_balancer.rb', line 117

def ready?
  state == 'AVAILABLE'
end

#reloadObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fog/profitbricks/models/compute/load_balancer.rb', line 69

def reload
  requires :datacenter_id, :id

  data = begin
    collection.get(datacenter_id, id)
  rescue Excon::Errors::SocketError
    nil
  end

  return unless data

  new_attributes = data.attributes
  merge_attributes(new_attributes)
  self
end

#remove_nic_association(nic_id) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/fog/profitbricks/models/compute/load_balancer.rb', line 109

def remove_nic_association(nic_id)
  requires :datacenter_id, :id

  service.remove_nic_association(datacenter_id, id, nic_id)

  true
end

#saveObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/profitbricks/models/compute/load_balancer.rb', line 34

def save
  requires :datacenter_id, :name

  properties = {}
  properties[:name]       = name if name
  properties[:ip]         = ip if ip
  properties[:dhcp]       = dhcp if dhcp

  entities = {}
  entities[:balancednics] = balancednics if balancednics

  data = service.create_load_balancer(datacenter_id, properties, entities)
  merge_attributes(flatten(data.body))
  true
end

#updateObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fog/profitbricks/models/compute/load_balancer.rb', line 50

def update
  requires :datacenter_id, :id

  properties = {}
  properties[:name]       = name if name
  properties[:ip]         = ip if ip
  properties[:dhcp]       = dhcp if dhcp

  data = service.update_load_balancer(datacenter_id, id, properties)
  merge_attributes(data.body)
  true
end