Skip to content

Commit

Permalink
[google compute] allow bypassing image search in standard project list
Browse files Browse the repository at this point in the history
Support not using standard projects on images get and support families from copy image.

Signed-off-by: Eric Johnson <erjohnso@google.com>
  • Loading branch information
illfelder authored and erjohnso committed Feb 24, 2016
1 parent 1ba38fa commit 7013b6a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ General
Compute
~~~~~~~

- [google compute] allow bypassing image search in standard project list
(GITHUB-713)
[Max Illfelder]

- Add support for requesting a MKS token for accessing the remote console in VMware
vCloud driver
(GITHUB-706)
Expand Down
25 changes: 19 additions & 6 deletions libcloud/compute/drivers/gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -4060,14 +4060,23 @@ def ex_get_forwarding_rule(self, name, region=None, global_rule=False):
response = self.connection.request(request, method='GET').object
return self._to_forwarding_rule(response)

def ex_get_image(self, partial_name, ex_project_list=None):
def ex_get_image(self, partial_name, ex_project_list=None,
ex_standard_projects=True):
"""
Return an GCENodeImage object based on the name or link provided.
:param partial_name: The name, partial name, or full path of a GCE
image.
:type partial_name: ``str``
:param ex_project_list: The name of the project to list for images.
Examples include: 'debian-cloud'.
:type ex_project_List: ``str``, ``list`` of ``str``, or ``None``
:param ex_standard_projects: If true, check in standard projects if
the image is not found.
:type ex_standard_projects: ``bool``
:return: GCENodeImage object based on provided information or None if
an image with that name is not found.
:rtype: :class:`GCENodeImage` or raise ``ResourceNotFoundError``
Expand All @@ -4076,7 +4085,7 @@ def ex_get_image(self, partial_name, ex_project_list=None):
response = self.connection.request(partial_name, method='GET')
return self._to_node_image(response.object)
image = self._match_images(ex_project_list, partial_name)
if not image:
if not image and ex_standard_projects:
for img_proj, short_list in self.IMAGE_PROJECTS.items():
for short_name in short_list:
if partial_name.startswith(short_name):
Expand Down Expand Up @@ -4319,7 +4328,7 @@ def ex_get_zone(self, name):
return None
return self._to_zone(response)

def ex_copy_image(self, name, url, description=None):
def ex_copy_image(self, name, url, description=None, family=None):
"""
Copy an image to your image collection.
Expand All @@ -4332,6 +4341,9 @@ def ex_copy_image(self, name, url, description=None):
:param description: The description of the image
:type description: ``str``
:param family: The family of the image
:type family: ``str``
:return: NodeImage object based on provided information or None if an
image with that name is not found.
:rtype: :class:`NodeImage` or ``None``
Expand All @@ -4344,6 +4356,7 @@ def ex_copy_image(self, name, url, description=None):
image_data = {
'name': name,
'description': description,
'family': family,
'sourceType': 'RAW',
'rawDisk': {
'source': url,
Expand Down Expand Up @@ -4490,9 +4503,9 @@ def _match_images(self, project, partial_name):
supplied project. If no project is given, it will search your own
project.
:param project: The name of the project to search for images.
Examples include: 'debian-cloud' and 'centos-cloud'.
:type project: ``str`` or ``None``
:param project: The name of the project to search for images.
Examples include: 'debian-cloud' and 'centos-cloud'.
:type project: ``str``, ``list`` of ``str``, or ``None``
:param partial_name: The full name or beginning of a name for an
image.
Expand Down
10 changes: 9 additions & 1 deletion libcloud/test/compute/test_gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,13 +1139,21 @@ def test_ex_get_image(self):
image = self.driver.ex_get_image(partial_name, ['debian-cloud'])
self.assertEqual(image.name, 'debian-7-wheezy-v20131120')

partial_name = 'debian-7'
self.assertRaises(ResourceNotFoundError, self.driver.ex_get_image,
partial_name, 'suse-cloud',
ex_standard_projects=False)

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'
image = self.driver.ex_copy_image(name, url, description)
family = 'coreos'
image = self.driver.ex_copy_image(name, url, description=description,
family=family)
self.assertTrue(image.name.startswith(name))
self.assertEqual(image.extra['description'], description)
self.assertEqual(image.extra['family'], family)

def test_ex_get_route(self):
route_name = 'lcdemoroute'
Expand Down

0 comments on commit 7013b6a

Please sign in to comment.