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

Merge pull request #2843 from frodenas/gce_regions

[google|compute] Add Regions support
This commit is contained in:
Nat Welch 2014-04-14 20:37:17 +01:00
commit 6acc6f5205
4 changed files with 91 additions and 0 deletions

View file

@ -36,6 +36,7 @@ module Fog
request :get_machine_type
request :get_network
request :get_zone
request :get_region
request :get_snapshot
request :get_global_operation
request :get_region_operation
@ -110,6 +111,9 @@ module Fog
model :zone
collection :zones
model :region
collection :regions
model :http_health_check
collection :http_health_checks

View file

@ -0,0 +1,34 @@
require 'fog/core/model'
module Fog
module Compute
class Google
##
# Represents a Region resource
#
# @see https://developers.google.com/compute/docs/reference/latest/regions
class Region < Fog::Model
identity :name
attribute :kind
attribute :id
attribute :creation_timestamp, :aliases => 'creationTimestamp'
attribute :deprecated
attribute :description
attribute :quotas
attribute :self_link, :aliases => 'selfLink'
attribute :status
attribute :zones
DOWN_STATE = 'DOWN'
UP_STATE = 'UP'
def up?
self.status == UP_STATE
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/core/collection'
require 'fog/google/models/compute/region'
module Fog
module Compute
class Google
class Regions < Fog::Collection
model Fog::Compute::Google::Region
def all
data = service.list_regions.body
load(data['items'] || [])
end
def get(identity)
if region = service.get_region(identity).body
new(region)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,26 @@
module Fog
module Compute
class Google
class Mock
def get_region(identity)
Fog::Mock.not_implemented
end
end
class Real
def get_region(identity)
api_method = @compute.regions.get
parameters = {
'project' => @project,
'region' => identity.split('/')[-1],
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
end
end
end
end