2010-10-04 17:02:08 -04:00
|
|
|
require 'fog/core/collection'
|
2010-05-17 23:57:13 -04:00
|
|
|
require 'fog/terremark/models/shared/server'
|
2010-04-16 03:20:02 -04:00
|
|
|
|
|
|
|
module Fog
|
2010-05-17 23:57:13 -04:00
|
|
|
module Terremark
|
2010-04-16 03:20:02 -04:00
|
|
|
module Shared
|
|
|
|
|
|
|
|
module Mock
|
|
|
|
def servers(options = {})
|
2012-12-22 18:23:10 -05:00
|
|
|
Fog::Terremark::Shared::Servers.new(options.merge(:service => self))
|
2010-04-16 03:20:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module Real
|
|
|
|
def servers(options = {})
|
2012-12-22 18:23:10 -05:00
|
|
|
Fog::Terremark::Shared::Servers.new(options.merge(:service => self))
|
2010-04-16 03:20:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Servers < Fog::Collection
|
|
|
|
|
2010-05-17 23:57:13 -04:00
|
|
|
model Fog::Terremark::Shared::Server
|
2010-04-16 03:20:02 -04:00
|
|
|
|
|
|
|
def all
|
2012-04-29 22:48:06 -04:00
|
|
|
data = []
|
2012-12-22 18:23:10 -05:00
|
|
|
service.get_vdc(vdc_id).body['ResourceEntities'].select do |entity|
|
|
|
|
data << service.servers.get(entity["href"].split('/').last)
|
2010-04-16 03:20:02 -04:00
|
|
|
end
|
2012-04-29 22:48:06 -04:00
|
|
|
data
|
2010-04-16 03:20:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def get(server_id)
|
2012-08-05 08:10:55 -04:00
|
|
|
if server_id
|
2012-12-22 18:23:10 -05:00
|
|
|
new(service.get_vapp(server_id).body)
|
2012-08-05 08:10:55 -04:00
|
|
|
else
|
2010-04-16 03:20:02 -04:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def vdc_id
|
2012-12-22 18:23:10 -05:00
|
|
|
@vdc_id ||= service.default_vdc_id
|
2010-04-16 03:20:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def vdc_id=(new_vdc_id)
|
|
|
|
@vdc_id = new_vdc_id
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|