libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [26/44] git commit: Add Snapshots to demo code and a snapshot fix
Date Fri, 03 Jan 2014 14:59:38 GMT
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/65f8c2db
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/65f8c2db
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/65f8c2db

Branch: refs/heads/trunk
Commit: 65f8c2db12ecb67b7cae1c259710a98f8f52d0a9
Parents: adb9aca
Author: Rick Wright <rickw@google.com>
Authored: Mon Dec 16 10:30:49 2013 -0800
Committer: Rick Wright <rickw@google.com>
Committed: Thu Jan 2 23:30:02 2014 -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/65f8c2db/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/65f8c2db/libcloud/compute/drivers/gce.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/gce.py b/libcloud/compute/drivers/gce.py
index cc1ef36..fef1b98 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


Mime
View raw message