Repository: libcloud
Updated Branches:
  refs/heads/trunk 23abf8c93 -> 2bca79b41


Add support for adding a family to an image.
Closes #704


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/41ff5518
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/41ff5518
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/41ff5518

Branch: refs/heads/trunk
Commit: 41ff55180b9ee353a9d3041f7605f7f037bd8293
Parents: 23abf8c
Author: Max Illfelder <[email protected]>
Authored: Thu Feb 11 16:53:30 2016 -0800
Committer: anthony-shaw <[email protected]>
Committed: Sun Feb 14 13:38:23 2016 +1100

----------------------------------------------------------------------
 libcloud/compute/drivers/gce.py                  | 19 ++++++++++++++-----
 .../gce/projects_coreos-cloud_global_images.json |  1 +
 libcloud/test/compute/test_gce.py                |  1 +
 3 files changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/41ff5518/libcloud/compute/drivers/gce.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/gce.py b/libcloud/compute/drivers/gce.py
index 12e296b..c3fcf6b 100644
--- a/libcloud/compute/drivers/gce.py
+++ b/libcloud/compute/drivers/gce.py
@@ -97,8 +97,7 @@ class GCEConnection(GoogleBaseConnection):
                                             auth_type=auth_type,
                                             credential_file=credential_file,
                                             **kwargs)
-        self.request_path = '/compute/%s/projects/%s' % (API_VERSION,
-                                                         project)
+        self.request_path = '/compute/%s/projects/%s' % (API_VERSION, project)
         self.gce_params = None
 
     def pre_connect_hook(self, params, headers):
@@ -2100,7 +2099,7 @@ class GCENodeDriver(NodeDriver):
 
         return self.ex_get_forwarding_rule(name, global_rule=global_rule)
 
-    def ex_create_image(self, name, volume, description=None,
+    def ex_create_image(self, name, volume, description=None, family=None,
                         use_existing=True, wait_for_completion=True):
         """
         Create an image from the provided volume.
@@ -2115,6 +2114,13 @@ class GCENodeDriver(NodeDriver):
         :keyword    description: Description of the new Image
         :type       description: ``str``
 
+        :keyword    family: The name of the image family to which this image
+                            belongs. If you create resources by specifying an
+                            image family instead of a specific image name, the
+                            resource uses the latest non-deprecated image that
+                            is set with that family name.
+        :type       family: ``str``
+
         :keyword  use_existing: If True and an image with the given name
                                 already exists, return an object for that
                                 image instead of attempting to create
@@ -2135,11 +2141,13 @@ class GCENodeDriver(NodeDriver):
         image_data = {}
         image_data['name'] = name
         image_data['description'] = description
+        image_data['family'] = family
         if isinstance(volume, StorageVolume):
             image_data['sourceDisk'] = volume.extra['selfLink']
             image_data['zone'] = volume.extra['zone'].name
-        elif isinstance(volume, str) and \
-                volume.startswith('https://') and volume.endswith('tar.gz'):
+        elif (isinstance(volume, str) and
+              volume.startswith('https://') and
+              volume.endswith('tar.gz')):
             image_data['rawDisk'] = {'source': volume, 'containerType': 'TAR'}
         else:
             raise ValueError('Source must be instance of StorageVolume or URI')
@@ -5240,6 +5248,7 @@ class GCENodeDriver(NodeDriver):
         if 'preferredKernel' in image:
             extra['preferredKernel'] = image.get('preferredKernel', None)
         extra['description'] = image.get('description', None)
+        extra['family'] = image.get('family', None)
         extra['creationTimestamp'] = image.get('creationTimestamp')
         extra['selfLink'] = image.get('selfLink')
         if 'deprecated' in image:

http://git-wip-us.apache.org/repos/asf/libcloud/blob/41ff5518/libcloud/test/compute/fixtures/gce/projects_coreos-cloud_global_images.json
----------------------------------------------------------------------
diff --git 
a/libcloud/test/compute/fixtures/gce/projects_coreos-cloud_global_images.json 
b/libcloud/test/compute/fixtures/gce/projects_coreos-cloud_global_images.json
index f61d03d..ce1a1fd 100644
--- 
a/libcloud/test/compute/fixtures/gce/projects_coreos-cloud_global_images.json
+++ 
b/libcloud/test/compute/fixtures/gce/projects_coreos-cloud_global_images.json
@@ -1326,6 +1326,7 @@
    "creationTimestamp": "2014-12-26T15:04:01.237-08:00",
    "name": "coreos-beta-522-3-0-v20141226",
    "description": "CoreOS beta 522.3.0",
+   "family": "coreos",
    "sourceType": "RAW",
    "rawDisk": {
     "source": "",

http://git-wip-us.apache.org/repos/asf/libcloud/blob/41ff5518/libcloud/test/compute/test_gce.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_gce.py 
b/libcloud/test/compute/test_gce.py
index 72e41b6..15247e3 100644
--- a/libcloud/test/compute/test_gce.py
+++ b/libcloud/test/compute/test_gce.py
@@ -389,6 +389,7 @@ class GCENodeDriverTest(GoogleTestCase, TestCaseMixin):
         self.assertTrue(isinstance(image, GCENodeImage))
         self.assertTrue(image.name.startswith('coreos'))
         self.assertEqual(image.extra['description'], 'CoreOS beta 522.3.0')
+        self.assertEqual(image.extra['family'], 'coreos')
 
     def test_ex_create_firewall(self):
         firewall_name = 'lcfirewall'

Reply via email to