Class: Boxcutter::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/boxcutter/server.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, attrs) ⇒ Server

Returns a new instance of Server.



14
15
16
17
# File 'lib/boxcutter/server.rb', line 14

def initialize(api, attrs)
  @api = api
  @attrs = attrs
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



12
13
14
# File 'lib/boxcutter/server.rb', line 12

def api
  @api
end

Class Method Details

.allObject



3
4
5
6
# File 'lib/boxcutter/server.rb', line 3

def self.all
  api = Api.new(*ENV['BBG_API_KEY'].split(':'))
  api.servers.map {|attrs| new(api, attrs)}
end

.find_by_hostname(hostname) ⇒ Object



8
9
10
# File 'lib/boxcutter/server.rb', line 8

def self.find_by_hostname(hostname)
  all.detect {|server| server.hostname == hostname}
end

Instance Method Details

#cpuObject



51
52
53
# File 'lib/boxcutter/server.rb', line 51

def cpu
  @attrs["cpu"]
end

#descriptionObject



47
48
49
# File 'lib/boxcutter/server.rb', line 47

def description
  @attrs["description"]
end

#hostnameObject



43
44
45
# File 'lib/boxcutter/server.rb', line 43

def hostname
  @attrs["hostname"]
end

#idObject



31
32
33
# File 'lib/boxcutter/server.rb', line 31

def id
  @attrs["id"]
end

#ipsObject



23
24
25
# File 'lib/boxcutter/server.rb', line 23

def ips
  @attrs["ips"].map {|ip| ip["address"]}
end

#lb_applicationsObject



59
60
61
62
63
# File 'lib/boxcutter/server.rb', line 59

def lb_applications
  @attrs["lb_applications"].map do |lb_app_attrs|
    LoadBalancer::Application.find(lb_app_attrs["lb_application_id"], api)
  end
end

#location_idObject



39
40
41
# File 'lib/boxcutter/server.rb', line 39

def location_id
  @attrs["location_id"]
end

#memoryObject



27
28
29
# File 'lib/boxcutter/server.rb', line 27

def memory
  @attrs["memory"]
end

#statusObject



55
56
57
# File 'lib/boxcutter/server.rb', line 55

def status
  @attrs["status"]
end

#storageObject



35
36
37
# File 'lib/boxcutter/server.rb', line 35

def storage
  @attrs["storage"]
end

#to_sObject



19
20
21
# File 'lib/boxcutter/server.rb', line 19

def to_s
  "#<Server id:'#{id}' hostname:'#{hostname}' description:'#{description}' status:'#{status}'>"
end