mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2841 from frodenas/gce_projects
[google|compute] Add Projects support
This commit is contained in:
commit
9e028c6198
6 changed files with 115 additions and 1 deletions
|
@ -19,10 +19,10 @@ Our implementation of the API currently supports
|
|||
* Operations
|
||||
* Snapshots
|
||||
* Instance Metadata
|
||||
* Project Metadata
|
||||
|
||||
Features we are looking forward to implementing in the future:
|
||||
|
||||
* Global Metadata support
|
||||
* Image creation
|
||||
* Load balancer configuration
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ module Fog
|
|||
request :get_snapshot
|
||||
request :get_global_operation
|
||||
request :get_zone_operation
|
||||
request :get_project
|
||||
|
||||
request :delete_address
|
||||
request :delete_disk
|
||||
|
@ -52,6 +53,7 @@ module Fog
|
|||
|
||||
request :set_metadata
|
||||
request :set_tags
|
||||
request :set_common_instance_metadata
|
||||
|
||||
model_path 'fog/google/models/compute'
|
||||
model :server
|
||||
|
@ -75,6 +77,9 @@ module Fog
|
|||
model :zone
|
||||
collection :zones
|
||||
|
||||
model :project
|
||||
collection :projects
|
||||
|
||||
module Shared
|
||||
attr_reader :project, :api_version
|
||||
|
||||
|
|
32
lib/fog/google/models/compute/project.rb
Normal file
32
lib/fog/google/models/compute/project.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
##
|
||||
# Represents a Project resource
|
||||
#
|
||||
# @see https://developers.google.com/compute/docs/reference/latest/projects
|
||||
class Project < Fog::Model
|
||||
identity :name
|
||||
|
||||
attribute :kind
|
||||
attribute :id
|
||||
attribute :common_instance_metadata, :aliases => 'commonInstanceMetadata'
|
||||
attribute :creation_timestamp, :aliases => 'creationTimestamp'
|
||||
attribute :description
|
||||
attribute :quotas
|
||||
attribute :self_link, :aliases => 'selfLink'
|
||||
|
||||
def set_metadata(metadata = {})
|
||||
requires :identity
|
||||
|
||||
data = service.set_common_instance_metadata(identity, self.common_instance_metadata['fingerprint'], metadata)
|
||||
Fog::Compute::Google::Operations.new(:service => service).get(data.body['name'])
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
22
lib/fog/google/models/compute/projects.rb
Normal file
22
lib/fog/google/models/compute/projects.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/google/models/compute/project'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
class Projects < Fog::Collection
|
||||
model Fog::Compute::Google::Project
|
||||
|
||||
def get(identity)
|
||||
if project = service.get_project(identity).body
|
||||
new(project)
|
||||
end
|
||||
rescue Fog::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
25
lib/fog/google/requests/compute/get_project.rb
Normal file
25
lib/fog/google/requests/compute/get_project.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
class Mock
|
||||
def get_project(identity)
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
|
||||
class Real
|
||||
def get_project(identity)
|
||||
api_method = @compute.projects.get
|
||||
parameters = {
|
||||
:project => identity,
|
||||
}
|
||||
|
||||
result = self.build_result(api_method, parameters)
|
||||
response = self.build_response(result)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,30 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Google
|
||||
|
||||
class Mock
|
||||
def set_common_instance_metadata(identity, current_fingerprint, metadata = {})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Real
|
||||
def set_common_instance_metadata(identity, current_fingerprint, metadata = {})
|
||||
api_method = @compute.projects.set_common_instance_metadata
|
||||
parameters = {
|
||||
:project => identity,
|
||||
}
|
||||
body_object = {
|
||||
:fingerprint => current_fingerprint,
|
||||
:items => Array(metadata).map { |pair| { :key => pair[0], :value => pair[1] } },
|
||||
}
|
||||
|
||||
result = self.build_result(api_method, parameters, body_object)
|
||||
response = self.build_response(result)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue