1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/google/models/compute/servers.rb

55 lines
1.2 KiB
Ruby
Raw Normal View History

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
data = service.list_servers.body["items"] || []
2012-10-22 20:15:33 -04:00
load(data)
end
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
def bootstrap(new_attributes = {})
defaults = {
: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:55:04 -04:00
server = create(defaults.merge(new_attributes))
server.wait_for { ready? }
server
end
2012-10-22 20:15:33 -04:00
end
end
end
end