diff --git a/lib/fog/google/compute.rb b/lib/fog/google/compute.rb index 24f376ae9..b5bb26d8c 100644 --- a/lib/fog/google/compute.rb +++ b/lib/fog/google/compute.rb @@ -19,6 +19,7 @@ module Fog request :list_zones request :list_global_operations request :list_zone_operations + request :list_snapshots request :get_server request :get_disk @@ -27,6 +28,7 @@ module Fog request :get_machine_type request :get_network request :get_zone + request :get_snapshot request :delete_disk request :delete_firewall @@ -56,6 +58,9 @@ module Fog model :disk collection :disks + model :snapshot + collection :snapshots + class Mock include Collections diff --git a/lib/fog/google/examples/get_list_snapshots.rb b/lib/fog/google/examples/get_list_snapshots.rb new file mode 100644 index 000000000..fbfb15b98 --- /dev/null +++ b/lib/fog/google/examples/get_list_snapshots.rb @@ -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 diff --git a/lib/fog/google/models/compute/snapshot.rb b/lib/fog/google/models/compute/snapshot.rb new file mode 100644 index 000000000..f7908f379 --- /dev/null +++ b/lib/fog/google/models/compute/snapshot.rb @@ -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 diff --git a/lib/fog/google/models/compute/snapshots.rb b/lib/fog/google/models/compute/snapshots.rb new file mode 100644 index 000000000..bc23a1b5e --- /dev/null +++ b/lib/fog/google/models/compute/snapshots.rb @@ -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 diff --git a/lib/fog/google/requests/compute/get_snapshot.rb b/lib/fog/google/requests/compute/get_snapshot.rb new file mode 100644 index 000000000..1dc66282e --- /dev/null +++ b/lib/fog/google/requests/compute/get_snapshot.rb @@ -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 diff --git a/lib/fog/google/requests/compute/list_snapshots.rb b/lib/fog/google/requests/compute/list_snapshots.rb new file mode 100644 index 000000000..2c3a982e6 --- /dev/null +++ b/lib/fog/google/requests/compute/list_snapshots.rb @@ -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