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

Merge pull request #2065 from maginatics/gce_get_list_snapshots

[google|compute] get/list snapshots
This commit is contained in:
Nat Welch 2013-08-13 11:40:13 -07:00
commit fffa8dea69
6 changed files with 147 additions and 0 deletions

View file

@ -19,6 +19,7 @@ module Fog
request :list_zones request :list_zones
request :list_global_operations request :list_global_operations
request :list_zone_operations request :list_zone_operations
request :list_snapshots
request :get_server request :get_server
request :get_disk request :get_disk
@ -27,6 +28,7 @@ module Fog
request :get_machine_type request :get_machine_type
request :get_network request :get_network
request :get_zone request :get_zone
request :get_snapshot
request :delete_disk request :delete_disk
request :delete_firewall request :delete_firewall
@ -56,6 +58,9 @@ module Fog
model :disk model :disk
collection :disks collection :disks
model :snapshot
collection :snapshots
class Mock class Mock
include Collections include Collections

View file

@ -0,0 +1,18 @@
def test
connection = Fog::Compute.new({ :provider => "Google" })
# puts 'Listing images in all projects...'
# puts '---------------------------------'
snapshots = connection.snapshots.all
raise 'Could not LIST the snapshots' unless snapshots
# puts snapshots.inspect
snap = snapshots.first
# puts 'Fetching a single image from a global project...'
# puts '------------------------------------------------'
snap = connection.snapshots.get(snap)
raise 'Could not GET the snapshot' unless snap
# puts snap.inspect
end

View file

@ -0,0 +1,36 @@
require 'fog/core/model'
module Fog
module Compute
class Google
class Snapshot < Fog::Model
identity :name
attribute :kind
attribute :self_link , :aliases => 'selfLink'
attribute :creation_timestamp, :aliases => 'creationTimestamp'
attribute :disk_size_gb , :aliases => 'diskSizeGb'
attribute :source_disk , :aliases => 'sourceDisk'
attribute :source_disk_id , :aliases => 'sourceDiskId'
attribute :description
def reload
requires :name
data = service.get_snapshot(name, self.service.project).body
self.merge_attributes(data)
self
end
def resource_url
"#{self.project}/global/snapshots/#{name}"
end
end
end
end
end

View file

@ -0,0 +1,28 @@
require 'fog/core/collection'
require 'fog/google/models/compute/snapshot'
module Fog
module Compute
class Google
class Snapshots < Fog::Collection
model Fog::Compute::Google::Snapshot
def all
data = service.list_snapshots(self.service.project)
snapshots = data.body['items'] || []
load(snapshots)
end
def get(snap_id)
response = service.get_snapshot(snap_id, self.service.project)
return nil if response.nil?
new(response.body)
end
end
end
end
end

View file

@ -0,0 +1,30 @@
module Fog
module Compute
class Google
class Mock
def get_snapshot(snap_name)
Fog::Mock.not_implemented
end
end
class Real
def get_snapshot(snap_name, project=@project)
api_method = @compute.snapshots.get
parameters = {
'snapshot' => snap_name,
'project' => project,
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
end
end
end
end

View file

@ -0,0 +1,30 @@
module Fog
module Compute
class Google
class Mock
def list_snapshots
Fog::Mock.not_implemented
end
end
class Real
def list_snapshots(project=nil)
api_method = @compute.snapshots.list
project=@project if project.nil?
parameters = {
'project' => project
}
result = self.build_result(api_method, parameters)
response = self.build_response(result)
end
end
end
end
end