-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2106 from maginatics/gce_create_snapshot
[google|compute] Create a Snapshot based on a Disk
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Fog | ||
module Compute | ||
class Google | ||
|
||
class Mock | ||
|
||
def insert_snapshot(snap_name) | ||
Fog::Mock.not_implemented | ||
end | ||
|
||
end | ||
|
||
class Real | ||
|
||
def insert_snapshot(disk_name, zone_name, project=@project, opts={}) | ||
|
||
# This is unfortunate, since we might be called from 2 contexts | ||
# 1. disk.snapshot <-- here validation of disk_name is not needed | ||
# 2. snapshot.create <-- here we must validate the disk_name | ||
# | ||
# Validation would involve 'get'ing the disk by that name. This is | ||
# redundant (and expensive) for case (1) which is likely the common | ||
# codepath. So we won't do it. | ||
|
||
api_method = @compute.disks.create_snapshot | ||
|
||
parameters = { | ||
'disk' => disk_name, | ||
'zone' => zone_name, | ||
'project' => @project, | ||
} | ||
|
||
snap_name = opts.delete('name') | ||
raise ArgumentError.new('Must specify snapshot name') unless snap_name | ||
body_object = { 'name' => snap_name } | ||
|
||
# Merge in any remaining options (description) | ||
body_object.merge(opts) | ||
|
||
result = self.build_result(api_method, parameters, | ||
body_object) | ||
response = self.build_response(result) | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end |