|
|
@@ -275,12 +275,14 @@ class GCEImageService(BaseImageService):
|
|
|
super(GCEImageService, self).__init__(provider)
|
|
|
self._public_images = None
|
|
|
|
|
|
- PUBLIC_IMAGE_PROJECTS = ['centos-cloud', 'coreos-cloud', 'debian-cloud',
|
|
|
+ _PUBLIC_IMAGE_PROJECTS = ['centos-cloud', 'coreos-cloud', 'debian-cloud',
|
|
|
'opensuse-cloud', 'ubuntu-os-cloud']
|
|
|
|
|
|
def _retrieve_public_images(self):
|
|
|
+ if self._public_images is not None:
|
|
|
+ return
|
|
|
self._public_images = []
|
|
|
- for project in GCEImageService.PUBLIC_IMAGE_PROJECTS:
|
|
|
+ for project in GCEImageService._PUBLIC_IMAGE_PROJECTS:
|
|
|
try:
|
|
|
response = self.provider.gce_compute \
|
|
|
.images() \
|
|
|
@@ -298,8 +300,7 @@ class GCEImageService(BaseImageService):
|
|
|
"""
|
|
|
Returns an Image given its name
|
|
|
"""
|
|
|
- if self._public_images == None:
|
|
|
- self._retrieve_public_images()
|
|
|
+ self._retrieve_public_images()
|
|
|
try:
|
|
|
image = self.provider.gce_compute \
|
|
|
.images() \
|
|
|
@@ -313,30 +314,35 @@ class GCEImageService(BaseImageService):
|
|
|
# match the pattern "[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?".
|
|
|
print("TypeError: {0}".format(type_error))
|
|
|
except googleapiclient.errors.HttpError as http_error:
|
|
|
+ # If the image is not found in project-specific private images,
|
|
|
+ # look for this image in public images.
|
|
|
+ for public_image in self._public_images:
|
|
|
+ if public_image.name == image_name:
|
|
|
+ return public_image
|
|
|
print("googleapiclient.errors.HttpError: {0}".format(http_error))
|
|
|
- for public_image in self._public_images:
|
|
|
- if public_image.name == image_name:
|
|
|
- return public_image
|
|
|
return None
|
|
|
|
|
|
def find(self, name, limit=None, marker=None):
|
|
|
"""
|
|
|
Searches for an image by a given list of attributes
|
|
|
"""
|
|
|
- if self._public_images == None:
|
|
|
- self._retrieve_public_images()
|
|
|
+ self._retrieve_public_images()
|
|
|
filters = {'name': name}
|
|
|
images = []
|
|
|
- try:
|
|
|
- response = self.provider.gce_compute \
|
|
|
- .images() \
|
|
|
- .list(project=self.provider.project_name) \
|
|
|
- .execute()
|
|
|
- if 'items' in response:
|
|
|
- images = [GCEMachineImage(self.provider, image) for image
|
|
|
- in response['items']]
|
|
|
- except googleapiclient.errors.HttpError as http_error:
|
|
|
- print("googleapiclient.errors.HttpError: {0}".format(http_error))
|
|
|
+ if (self.provider.project_name not in
|
|
|
+ GCEImageService._PUBLIC_IMAGE_PROJECTS):
|
|
|
+ try:
|
|
|
+ response = self.provider \
|
|
|
+ .gce_compute \
|
|
|
+ .images() \
|
|
|
+ .list(project=self.provider.project_name) \
|
|
|
+ .execute()
|
|
|
+ if 'items' in response:
|
|
|
+ images = [GCEMachineImage(self.provider, image) for image
|
|
|
+ in response['items']]
|
|
|
+ except googleapiclient.errors.HttpError as http_error:
|
|
|
+ print(
|
|
|
+ "googleapiclient.errors.HttpError: {0}".format(http_error))
|
|
|
images.extend(self._public_images)
|
|
|
images = [image for image in images if image.name == filters['name']]
|
|
|
return ClientPagedResultList(self.provider, images,
|
|
|
@@ -346,19 +352,22 @@ class GCEImageService(BaseImageService):
|
|
|
"""
|
|
|
List all images.
|
|
|
"""
|
|
|
- if self._public_images == None:
|
|
|
- self._retrieve_public_images()
|
|
|
+ self._retrieve_public_images()
|
|
|
images = []
|
|
|
- try:
|
|
|
- response = self.provider.gce_compute \
|
|
|
- .images() \
|
|
|
- .list(project=self.provider.project_name) \
|
|
|
- .execute()
|
|
|
- if 'items' in response:
|
|
|
- images = [GCEMachineImage(self.provider, image) for image
|
|
|
- in response['items']]
|
|
|
- except googleapiclient.errors.HttpError as http_error:
|
|
|
- print("googleapiclient.errors.HttpError: {0}".format(http_error))
|
|
|
+ if (self.provider.project_name not in
|
|
|
+ GCEImageService._PUBLIC_IMAGE_PROJECTS):
|
|
|
+ try:
|
|
|
+ response = self.provider \
|
|
|
+ .gce_compute \
|
|
|
+ .images() \
|
|
|
+ .list(project=self.provider.project_name) \
|
|
|
+ .execute()
|
|
|
+ if 'items' in response:
|
|
|
+ images = [GCEMachineImage(self.provider, image) for image
|
|
|
+ in response['items']]
|
|
|
+ except googleapiclient.errors.HttpError as http_error:
|
|
|
+ print(
|
|
|
+ "googleapiclient.errors.HttpError: {0}".format(http_error))
|
|
|
images.extend(self._public_images)
|
|
|
return ClientPagedResultList(self.provider, images,
|
|
|
limit=limit, marker=marker)
|