diff --git a/lib/fog/google/compute.rb b/lib/fog/google/compute.rb index 6e5dce3ca..3f3926cdf 100644 --- a/lib/fog/google/compute.rb +++ b/lib/fog/google/compute.rb @@ -61,6 +61,9 @@ module Fog model :snapshot collection :snapshots + model :zone + collection :zones + module Shared attr_reader :project @@ -795,19 +798,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 - - # returns Google::APIClient::Result def build_result(api_method, parameters, body_object=nil) if body_object result = @client.execute( diff --git a/lib/fog/google/models/compute/server.rb b/lib/fog/google/models/compute/server.rb index 768109ad4..895f5f482 100644 --- a/lib/fog/google/models/compute/server.rb +++ b/lib/fog/google/models/compute/server.rb @@ -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 diff --git a/lib/fog/google/models/compute/zone.rb b/lib/fog/google/models/compute/zone.rb new file mode 100644 index 000000000..dab753667 --- /dev/null +++ b/lib/fog/google/models/compute/zone.rb @@ -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 diff --git a/lib/fog/google/models/compute/zones.rb b/lib/fog/google/models/compute/zones.rb new file mode 100644 index 000000000..53049d1a4 --- /dev/null +++ b/lib/fog/google/models/compute/zones.rb @@ -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