You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2014/01/03 15:59:20 UTC
[08/44] git commit: Add Snapshots to demo code and a snapshot fix
Add Snapshots to demo code and a snapshot fix
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/ca96c9b6
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/ca96c9b6
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/ca96c9b6
Branch: refs/heads/trunk
Commit: ca96c9b659772d9fb22cd15219dc460a4f284c93
Parents: 2d3caa8
Author: Rick Wright <ri...@google.com>
Authored: Mon Dec 16 10:30:49 2013 -0800
Committer: Rick Wright <ri...@google.com>
Committed: Mon Dec 16 10:30:49 2013 -0800
----------------------------------------------------------------------
demos/gce_demo.py | 34 ++++++++++++++++++++++++++--------
libcloud/compute/drivers/gce.py | 13 ++++++-------
2 files changed, 32 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/ca96c9b6/demos/gce_demo.py
----------------------------------------------------------------------
diff --git a/demos/gce_demo.py b/demos/gce_demo.py
index b6f2cb4..5f45c68 100755
--- a/demos/gce_demo.py
+++ b/demos/gce_demo.py
@@ -180,14 +180,17 @@ def main():
zones = gce.ex_list_zones()
display('Zones', zones)
+ snapshots = gce.ex_list_snapshots()
+ display('Snapshots', snapshots)
+
# == Clean up any old demo resources ==
print('Cleaning up any "%s" resources:' % DEMO_BASE_NAME)
clean_up(gce, DEMO_BASE_NAME, all_nodes,
- all_addresses + all_volumes + firewalls + networks)
+ all_addresses + all_volumes + firewalls + networks + snapshots)
- # == Create Node with non-persistent disk ==
+ # == Create Node with disk auto-created ==
if MAX_NODES > 1:
- print('Creating Node with non-persistent disk:')
+ print('Creating Node with auto-created disk:')
name = '%s-np-node' % DEMO_BASE_NAME
node_1 = gce.create_node(name, 'n1-standard-1', 'debian-7',
ex_tags=['libcloud'])
@@ -205,17 +208,29 @@ def main():
if gce.detach_volume(volume, ex_node=node_1):
print(' Detached %s from %s' % (volume.name, node_1.name))
- # == Create Node with persistent disk ==
- print('Creating Node with Persistent disk:')
+ # == Create Snapshot ==
+ print('Creating a snapshot from existing disk:')
+ # Create a disk to snapshot
+ vol_name = '%s-snap-template' % DEMO_BASE_NAME
+ image = gce.ex_get_image('debian-7')
+ vol = gce.create_volume(None, vol_name, image=image)
+ print(' Created disk %s to shapshot' % DEMO_BASE_NAME)
+ # Snapshot volume
+ snapshot = vol.snapshot('%s-snapshot' % DEMO_BASE_NAME)
+ print(' Snapshot %s created' % snapshot.name)
+
+ # == Create Node with existing disk ==
+ print('Creating Node with existing disk:')
name = '%s-persist-node' % DEMO_BASE_NAME
# Use objects this time instead of names
# Get latest Debian 7 image
image = gce.ex_get_image('debian-7')
# Get Machine Size
size = gce.ex_get_size('n1-standard-1')
- # Create Disk. Size is None to just take default of image
+ # Create Disk from Snapshot created above
volume_name = '%s-boot-disk' % DEMO_BASE_NAME
- volume = gce.create_volume(None, volume_name, image=image)
+ volume = gce.create_volume(None, volume_name, snapshot=snapshot)
+ print(' Created %s from snapshot' % volume.name)
# Create Node with Disk
node_2 = gce.create_node(name, size, image, ex_tags=['libcloud'],
ex_boot_disk=volume)
@@ -282,10 +297,13 @@ def main():
networks = gce.ex_list_networks()
display('Networks', networks)
+ snapshots = gce.ex_list_snapshots()
+ display('Snapshots', snapshots)
+
if CLEANUP:
print('Cleaning up %s resources created.' % DEMO_BASE_NAME)
clean_up(gce, DEMO_BASE_NAME, nodes,
- addresses + volumes + firewalls + networks)
+ addresses + volumes + firewalls + networks + snapshots)
if __name__ == '__main__':
main()
http://git-wip-us.apache.org/repos/asf/libcloud/blob/ca96c9b6/libcloud/compute/drivers/gce.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/gce.py b/libcloud/compute/drivers/gce.py
index faa2905..d8cdc09 100644
--- a/libcloud/compute/drivers/gce.py
+++ b/libcloud/compute/drivers/gce.py
@@ -1653,13 +1653,12 @@ class GCENodeDriver(NodeDriver):
volume_data['description'] = 'Image: %s' % (
image.extra['selfLink'])
if snapshot:
- # Check for full URI to not break backward-compatibility
- if snapshot.startswith('https'):
- snapshot_link = snapshot
- else:
- if not hasattr(snapshot, 'name'):
- snapshot = self.ex_get_snapshot(snapshot)
- snapshot_link = snapshot.extra['selfLink']
+ if not hasattr(snapshot, 'name'):
+ # Check for full URI to not break backward-compatibility
+ if snapshot.startswith('https'):
+ snapshot = self._get_components_from_path(snapshot)['name']
+ snapshot = self.ex_get_snapshot(snapshot)
+ snapshot_link = snapshot.extra['selfLink']
volume_data['sourceSnapshot'] = snapshot_link
volume_data['description'] = 'Snapshot: %s' % (snapshot_link)
location = location or self.zone