2011-08-10 09:03:51 -04:00
|
|
|
require 'fog/core/collection'
|
2011-09-08 17:07:04 -04:00
|
|
|
require 'fog/glesys/models/compute/server'
|
2011-08-10 09:03:51 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Glesys
|
|
|
|
|
|
|
|
class Servers < Fog::Collection
|
|
|
|
|
|
|
|
model Fog::Compute::Glesys::Server
|
|
|
|
|
|
|
|
def all
|
2012-12-22 18:27:08 -05:00
|
|
|
data = service.list_servers.body['response']['servers']
|
|
|
|
load(data)
|
2011-08-10 09:03:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def get(identifier)
|
|
|
|
return nil if identifier.nil? || identifier == ""
|
2012-06-12 08:54:07 -04:00
|
|
|
|
|
|
|
begin
|
2012-12-22 18:27:08 -05:00
|
|
|
details = service.server_details(identifier).body['response']
|
|
|
|
status = service.server_status(identifier).body['response']
|
2012-06-12 08:54:07 -04:00
|
|
|
|
|
|
|
if details.empty? || status.empty?
|
|
|
|
nil
|
|
|
|
else
|
2013-02-09 08:53:51 -05:00
|
|
|
details['server']['usage'] = Hash.new
|
|
|
|
|
|
|
|
%w|cpu memory disk transfer|.each do |attr|
|
|
|
|
details['server']['usage'][attr] = status['server'].delete(attr)
|
|
|
|
end
|
|
|
|
|
2012-06-12 08:54:07 -04:00
|
|
|
details['server'].merge!(status['server'])
|
2013-02-09 08:53:51 -05:00
|
|
|
|
2012-06-12 08:54:07 -04:00
|
|
|
new(details['server'])
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
return nil
|
2011-08-10 09:03:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|