1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[google] Create zone and zones models

This commit is contained in:
Carlos Sanchez 2013-09-26 17:52:15 +02:00
parent ed6886d2da
commit fae65838ba
4 changed files with 56 additions and 13 deletions

View file

@ -61,6 +61,9 @@ module Fog
model :snapshot
collection :snapshots
model :zone
collection :zones
class Mock
include Collections
@ -112,18 +115,6 @@ module Fog
@default_network = 'default'
end
# TODO: Total hack, create zone and zones model.
def zones
zones = []
self.list_zones.data[:body]["items"].each do |z|
if z["status"] == "UP"
zones.push z["name"]
end
end
return zones
end
def build_result(api_method, parameters, body_object=nil)
if body_object
result = @client.execute(

View file

@ -94,7 +94,7 @@ module Fog
requires :machine_type
requires :zone_name
if not service.zones.include? self.zone_name
if not service.zones.find{ |zone| zone.name == self.zone_name }
raise ArgumentError.new "#{self.zone_name.inspect} is either down or you don't have permission to use it."
end

View file

@ -0,0 +1,25 @@
require 'fog/core/model'
module Fog
module Compute
class Google
class Zone < Fog::Model
identity :name
attribute :description
attribute :status
attribute :maintenance_windows, :aliases => 'maintenanceWindows'
attribute :begin_time, :aliases => 'beginTime'
attribute :end_time, :aliases => 'endTime'
attribute :quotas
attribute :region
def up?
self.status == "UP"
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/core/collection'
require 'fog/google/models/compute/zone'
module Fog
module Compute
class Google
class Zones < Fog::Collection
model Fog::Compute::Google::Zone
def all
data = service.list_zones.body["items"] || []
load(data)
end
def get(identity)
data = connection.get_zone(identity).body
new(data)
rescue Excon::Errors::NotFound
nil
end
end
end
end
end