Class: CloudLB::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudlb/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(load_balancer, id) ⇒ Node

Initializes a new CloudLB::Node object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cloudlb/node.rb', line 12

def initialize(load_balancer,id)
  @connection    = load_balancer.connection
  @load_balancer = load_balancer
  @id            = id
  @lbmgmthost   = @connection.lbmgmthost
  @lbmgmtpath   = @connection.lbmgmtpath
  @lbmgmtport   = @connection.lbmgmtport
  @lbmgmtscheme = @connection.lbmgmtscheme
  populate
  return self
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



5
6
7
# File 'lib/cloudlb/node.rb', line 5

def address
  @address
end

#conditionObject

Returns the value of attribute condition.



6
7
8
# File 'lib/cloudlb/node.rb', line 6

def condition
  @condition
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/cloudlb/node.rb', line 4

def id
  @id
end

#portObject (readonly)

Returns the value of attribute port.



7
8
9
# File 'lib/cloudlb/node.rb', line 7

def port
  @port
end

#statusObject (readonly)

Returns the value of attribute status.



9
10
11
# File 'lib/cloudlb/node.rb', line 9

def status
  @status
end

#weightObject (readonly)

Returns the value of attribute weight.



8
9
10
# File 'lib/cloudlb/node.rb', line 8

def weight
  @weight
end

Instance Method Details

#destroy!Object

Deletes the current Node object and removes it from the load balancer. Returns true if successful, raises an exception if not.



47
48
49
50
51
# File 'lib/cloudlb/node.rb', line 47

def destroy!
  response = @connection.lbreq("DELETE",@lbmgmthost,"#{@lbmgmtpath}/loadbalancers/#{CloudLB.escape(@load_balancer.id.to_s)}/nodes/#{CloudLB.escape(@id.to_s)}",@lbmgmtport,@lbmgmtscheme)
  CloudLB::Exception.raise_exception(response) unless response.code.to_s.match(/^20.$/)
  true
end

#populateObject Also known as: refresh

Updates the information about this CloudLB::Node object by making an API call.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cloudlb/node.rb', line 25

def populate
  response = @connection.lbreq("GET",@lbmgmthost,"#{@lbmgmtpath}/loadbalancers/#{CloudLB.escape(@load_balancer.id.to_s)}/nodes/#{CloudLB.escape(@id.to_s)}",@lbmgmtport,@lbmgmtscheme)
  CloudLB::Exception.raise_exception(response) unless response.code.to_s.match(/^20.$/)
  data = JSON.parse(response.body)['node']
  @id                    = data["id"]
  @address                  = data["address"]
  @condition              = data["condition"]
  @port                  = data["port"]
  @weight             = data["weight"]
  @status                = data["status"]
  true
end