From 61de7e89ff5a33adf7642ba1612cc9178b26ef5b Mon Sep 17 00:00:00 2001 From: Max Illfelder Date: Thu, 11 Feb 2016 16:53:30 -0800 Subject: [PATCH] Add support for adding a family to an image. --- libcloud/compute/drivers/gce.py | 19 ++++++++++++++----- .../projects_coreos-cloud_global_images.json | 1 + libcloud/test/compute/test_gce.py | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/libcloud/compute/drivers/gce.py b/libcloud/compute/drivers/gce.py index 12e296bbee..c3fcf6b64c 100644 --- a/libcloud/compute/drivers/gce.py +++ b/libcloud/compute/drivers/gce.py @@ -97,8 +97,7 @@ def __init__(self, user_id, key, secure, auth_type=None, 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 @@ def ex_create_forwarding_rule(self, name, target=None, region=None, 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 @@ def ex_create_image(self, name, volume, description=None, :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 @@ def ex_create_image(self, name, volume, description=None, 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 @@ def _to_node_image(self, image): 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: 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 f61d03d915..ce1a1fd6e2 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": "", diff --git a/libcloud/test/compute/test_gce.py b/libcloud/test/compute/test_gce.py index 72e41b6f11..15247e3ed6 100644 --- a/libcloud/test/compute/test_gce.py +++ b/libcloud/test/compute/test_gce.py @@ -389,6 +389,7 @@ def test_ex_create_image(self): 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'