You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by er...@apache.org on 2016/07/15 19:57:46 UTC
libcloud git commit: [google compute] Update copy image logic to
match create image.
Repository: libcloud
Updated Branches:
refs/heads/trunk c320c61a0 -> a47a51e14
[google compute] Update copy image logic to match create image.
Closes #828
Signed-off-by: Eric Johnson <er...@google.com>
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/a47a51e1
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/a47a51e1
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/a47a51e1
Branch: refs/heads/trunk
Commit: a47a51e14e5300f3fd1b21533c407086e92a3cd1
Parents: c320c61
Author: Max Illfelder <il...@google.com>
Authored: Thu Jun 30 11:30:38 2016 -0700
Committer: Eric Johnson <er...@google.com>
Committed: Fri Jul 15 19:57:07 2016 +0000
----------------------------------------------------------------------
CHANGES.rst | 4 ++
libcloud/compute/drivers/gce.py | 107 ++++++++++++++++++---------------
libcloud/test/compute/test_gce.py | 29 ++++-----
3 files changed, 76 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a47a51e1/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index 9edf264..8c31e49 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -7,6 +7,10 @@ Changes in current version of Apache Libcloud
Compute
~~~~~~~
+- [google compute] Update copy image logic to match create image.
+ (GITHUB-828)
+ [Max Illfelder]
+
- Removed HD attribute from the Abiquo compute driver to support the 3.4 API
(GITHUB-840)
[David Freedman]
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a47a51e1/libcloud/compute/drivers/gce.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/gce.py b/libcloud/compute/drivers/gce.py
index 92cd84c..337b109 100644
--- a/libcloud/compute/drivers/gce.py
+++ b/libcloud/compute/drivers/gce.py
@@ -1061,6 +1061,8 @@ class GCENodeDriver(NodeDriver):
"windows-cloud": ["windows"],
}
+ GUEST_OS_FEATURES = ['VIRTIO_SCSI_MULTIQUEUE']
+
def __init__(self, user_id, key=None, datacenter=None, project=None,
auth_type=None, scopes=None, credential_file=None, **kwargs):
"""
@@ -2237,7 +2239,6 @@ class GCENodeDriver(NodeDriver):
:rtype: :class:`GCENodeImage`
"""
- possible_features = ['VIRTIO_SCSI_MULTIQUEUE']
image_data = {}
image_data['name'] = name
image_data['description'] = description
@@ -2254,11 +2255,11 @@ class GCENodeDriver(NodeDriver):
if guest_os_features:
image_data['guestOsFeatures'] = []
for feature in guest_os_features:
- if feature in possible_features:
+ if feature in self.GUEST_OS_FEATURES:
image_data['guestOsFeatures'].append({'type': feature})
else:
raise ValueError('Features must be one of %s'
- % ','.join(possible_features))
+ % ','.join(self.GUEST_OS_FEATURES))
request = '/global/images'
try:
@@ -2276,6 +2277,59 @@ class GCENodeDriver(NodeDriver):
return self.ex_get_image(name)
+ def ex_copy_image(self, name, url, description=None, family=None,
+ guest_os_features=None):
+ """
+ Copy an image to your image collection.
+
+ :param name: The name of the image
+ :type name: ``str``
+
+ :param url: The URL to the image. The URL can start with `gs://`
+ :param url: ``str``
+
+ :param description: The description of the image
+ :type description: ``str``
+
+ :param family: The family of the image
+ :type family: ``str``
+
+ :param guest_os_features: The features of the guest operating system.
+ :type guest_os_features: ``list`` of ``str`` or ``None``
+
+ :return: NodeImage object based on provided information or None if an
+ image with that name is not found.
+ :rtype: :class:`NodeImage` or ``None``
+ """
+
+ # The URL for an image can start with gs://
+ if url.startswith('gs://'):
+ url = url.replace('gs://', 'https://storage.googleapis.com/', 1)
+
+ image_data = {
+ 'name': name,
+ 'description': description,
+ 'family': family,
+ 'sourceType': 'RAW',
+ 'rawDisk': {
+ 'source': url,
+ },
+ }
+
+ if guest_os_features:
+ image_data['guestOsFeatures'] = []
+ for feature in guest_os_features:
+ if feature in self.GUEST_OS_FEATURES:
+ image_data['guestOsFeatures'].append({'type': feature})
+ else:
+ raise ValueError('Features must be one of %s'
+ % ','.join(self.GUEST_OS_FEATURES))
+
+ request = '/global/images'
+ self.connection.async_request(request, method='POST',
+ data=image_data)
+ return self.ex_get_image(name)
+
def ex_create_route(self, name, dest_range, priority=500,
network="default", tags=None, next_hop=None,
description=None):
@@ -4738,53 +4792,6 @@ class GCENodeDriver(NodeDriver):
return None
return self._to_zone(response)
- def ex_copy_image(self, name, url, description=None, family=None,
- guest_os_features=None):
- """
- Copy an image to your image collection.
-
- :param name: The name of the image
- :type name: ``str``
-
- :param url: The URL to the image. The URL can start with `gs://`
- :param url: ``str``
-
- :param description: The description of the image
- :type description: ``str``
-
- :param family: The family of the image
- :type family: ``str``
-
- :param guest_os_features: The features of the guest operating system.
- :type guest_os_features: ``list`` of ``dict`` or ``None``
-
- :return: NodeImage object based on provided information or None if an
- image with that name is not found.
- :rtype: :class:`NodeImage` or ``None``
- """
-
- # The URL for an image can start with gs://
- if url.startswith('gs://'):
- url = url.replace('gs://', 'https://storage.googleapis.com/', 1)
-
- image_data = {
- 'name': name,
- 'description': description,
- 'family': family,
- 'sourceType': 'RAW',
- 'rawDisk': {
- 'source': url,
- },
- }
-
- if guest_os_features:
- image_data['guestOsFeatures'] = guest_os_features
-
- request = '/global/images'
- self.connection.async_request(request, method='POST',
- data=image_data)
- return self.ex_get_image(name)
-
def _ex_connection_class_kwargs(self):
return {'auth_type': self.auth_type,
'project': self.project,
http://git-wip-us.apache.org/repos/asf/libcloud/blob/a47a51e1/libcloud/test/compute/test_gce.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_gce.py b/libcloud/test/compute/test_gce.py
index f7c2a0c..0d6d625 100644
--- a/libcloud/test/compute/test_gce.py
+++ b/libcloud/test/compute/test_gce.py
@@ -477,6 +477,21 @@ class GCENodeDriverTest(GoogleTestCase, TestCaseMixin):
data=expected_data,
method='POST')
+ def test_ex_copy_image(self):
+ name = 'coreos'
+ url = 'gs://storage.core-os.net/coreos/amd64-generic/247.0.0/coreos_production_gce.tar.gz'
+ description = 'CoreOS beta 522.3.0'
+ family = 'coreos'
+ guest_os_features = ['VIRTIO_SCSI_MULTIQUEUE']
+ expected_features = [{'type': 'VIRTIO_SCSI_MULTIQUEUE'}]
+ image = self.driver.ex_copy_image(name, url, description=description,
+ family=family,
+ guest_os_features=guest_os_features)
+ self.assertTrue(image.name.startswith(name))
+ self.assertEqual(image.extra['description'], description)
+ self.assertEqual(image.extra['family'], family)
+ self.assertEqual(image.extra['guestOsFeatures'], expected_features)
+
def test_ex_create_firewall(self):
firewall_name = 'lcfirewall'
allowed = [{'IPProtocol': 'tcp', 'ports': ['4567']}]
@@ -1367,20 +1382,6 @@ class GCENodeDriverTest(GoogleTestCase, TestCaseMixin):
self.assertRaises(ResourceNotFoundError, self.driver.ex_get_image_from_family, 'nofamily')
- def test_ex_copy_image(self):
- name = 'coreos'
- url = 'gs://storage.core-os.net/coreos/amd64-generic/247.0.0/coreos_production_gce.tar.gz'
- description = 'CoreOS beta 522.3.0'
- family = 'coreos'
- guest_os_features = [{'type': 'VIRTIO_SCSI_MULTIQUEUE'}]
- image = self.driver.ex_copy_image(name, url, description=description,
- family=family,
- guest_os_features=guest_os_features)
- self.assertTrue(image.name.startswith(name))
- self.assertEqual(image.extra['description'], description)
- self.assertEqual(image.extra['family'], family)
- self.assertEqual(image.extra['guestOsFeatures'], guest_os_features)
-
def test_ex_get_route(self):
route_name = 'lcdemoroute'
route = self.driver.ex_get_route(route_name)