2012-10-22 20:15:33 -04:00
|
|
|
require 'fog/core/collection'
|
2012-12-04 15:01:36 -05:00
|
|
|
require 'fog/google/models/compute/server'
|
2012-10-22 20:15:33 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
2012-12-04 15:05:11 -05:00
|
|
|
class Google
|
2012-10-22 20:15:33 -04:00
|
|
|
|
|
|
|
class Servers < Fog::Collection
|
|
|
|
|
2012-12-04 15:05:11 -05:00
|
|
|
model Fog::Compute::Google::Server
|
2012-10-22 20:15:33 -04:00
|
|
|
|
|
|
|
def all
|
2013-03-12 18:06:19 -04:00
|
|
|
data = service.list_servers.body["items"] || []
|
2012-10-22 20:15:33 -04:00
|
|
|
load(data)
|
|
|
|
end
|
|
|
|
|
2013-04-29 19:55:38 -04:00
|
|
|
def get(identity, zone=nil)
|
|
|
|
data = nil
|
|
|
|
if zone.nil?
|
|
|
|
service.list_zones.body['items'].each do |zone|
|
|
|
|
data = service.get_server(identity, zone['name']).body
|
|
|
|
break if data["code"] == 200
|
|
|
|
end
|
|
|
|
else
|
|
|
|
data = service.get_server(identity, zone).body
|
|
|
|
end
|
2013-04-29 20:09:51 -04:00
|
|
|
|
|
|
|
if data["code"] != 200
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
new(data)
|
|
|
|
end
|
2012-10-22 20:15:33 -04:00
|
|
|
rescue Excon::Errors::NotFound
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2013-03-12 18:06:19 -04:00
|
|
|
def bootstrap(new_attributes = {})
|
|
|
|
defaults = {
|
2013-03-12 18:22:48 -04:00
|
|
|
:name => "fog-#{Time.now.to_i}",
|
2013-03-12 18:46:30 -04:00
|
|
|
:image_name => "gcel-12-04-v20130225",
|
|
|
|
:machine_type => "n1-standard-1",
|
|
|
|
:zone_name => "us-central1-a",
|
2013-03-12 18:06:19 -04:00
|
|
|
}
|
|
|
|
|
2013-03-12 18:55:04 -04:00
|
|
|
server = create(defaults.merge(new_attributes))
|
2013-03-12 18:06:19 -04:00
|
|
|
server.wait_for { ready? }
|
|
|
|
server
|
|
|
|
end
|
|
|
|
|
2012-10-22 20:15:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|