Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
services.ec2: Update the publisher to send messages to fedmsg
Browse files Browse the repository at this point in the history
Signed-off-by: Sayan Chowdhury <[email protected]>
  • Loading branch information
sayanchowdhury committed Jul 27, 2017
1 parent a1cf41b commit 7283f2e
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 7 deletions.
46 changes: 42 additions & 4 deletions fedimg/services/ec2/ec2imgpublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

from time import sleep

import fedimg.messenger

from fedimg.utils import external_run_command, get_item_from_regex
from fedimg.services.ec2.ec2base import EC2Base

Expand Down Expand Up @@ -120,6 +122,24 @@ def publish_images(self, region_image_mapping=None):
snapshot = self.get_snapshot_from_image_id(image)
is_snapshot_public = self._retry_till_snapshot_is_public(snapshot)

virt_type = image.virt_type
volume_type = image.volume_type

if self.push_notifications:
fedimg.messenger.notify(
topic='image.pull',
msg=dict(
image_name=image.name,
destination=self.region,
service='EC2',
compose=self.compose_id,
extra=dict(
virt_type=virt_type,
vol_type=volume_type
)
)
)

published_images.append((
image.id,
is_image_public,
Expand Down Expand Up @@ -153,17 +173,35 @@ def copy_images_to_other_regions(self, image_id=None, regions=None):
self.image_name
)
try:
image = self._connect().copy_image(
copied_image = self._connect().copy_image(
image,
name=self.image_name,
description=self.image_description)

copied_images.append((region, image.id))
virt_type = copied_image.virt_type
volume_type = copied_image.volume_type

if self.push_notifications:
fedimg.messenger.notify(
topic='image.copy',
msg=dict(
image_name=copied_image.name,
destination=self.region,
service='EC2',
compose=self.compose_id,
extra=dict(
virt_type=virt_type,
vol_type=volume_type
)
)
)

copied_images.append((region, copied_image.id))
break

except Exception as e:
log.info('Could not register'
' with name: %r' % self.image_name)
log.info('Could not register '
'with name: %r' % self.image_name)
if 'InvalidAMIName.Duplicate' in str(e):
counter = counter + 1
else:
Expand Down
20 changes: 20 additions & 0 deletions fedimg/services/ec2/ec2imguploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import re

import fedimg.messenger

from fedimg.utils import external_run_command, get_item_from_regex
from fedimg.services.ec2.ec2base import EC2Base

Expand Down Expand Up @@ -179,6 +181,24 @@ def _register_image(self, snapshot):
architecture=self.image_architecture,
block_device_mapping=block_device_map)

if self.push_notifications:
fedimg.messenger.notify(
topic='image.upload',
msg=dict(
image_url=self.image_url,
image_name=self.image_name,
destination=self.region,
service=self.service,
status='completed',
compose=self.compose_id,
extra=dict(
id=image.id,
virt_type=self.image_virtualization_type,
vol_type=self.image_volume_type
)
)
)

return image

except Exception as e:
Expand Down
29 changes: 26 additions & 3 deletions fedimg/services/ec2/ec2initiate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@

from itertools import product as itertools_product

import fedimg.messenger

from fedimg.services.ec2.config import AWS_VOLUME_TYPES, BASE_REGION
from fedimg.services.ec2.ec2imguploader import EC2ImageUploader
from fedimg.services.ec2.ec2imgpublisher import EC2ImagePublisher
from fedimg.utils import get_virt_types_from_url, get_source_for_image
from fedimg.utils import get_image_name_for_image


def main(image_urls,
Expand All @@ -36,7 +39,9 @@ def main(image_urls,
regions,
volume_types=None,
volume_via_s3=True,
ex_virt_types=None):
ex_virt_types=None,
push_notifications=False,
compose_id=None):

if volume_types is None:
volume_types = AWS_VOLUME_TYPES
Expand All @@ -49,8 +54,10 @@ def main(image_urls,
virt_types = ex_virt_types

source = get_source_for_image(image_url)
image_name = get_image_name_for_image(image_url)

uploader = EC2ImageUploader(
image_name=image_name,
access_key=access_id,
secret_key=secret_key,
volume_via_s3=volume_via_s3,
Expand All @@ -64,19 +71,35 @@ def main(image_urls,
log.debug('(uploader) Region is set to: %r' % base_region)

uploader.set_image_virt_type(virt_type)
log.debug('(uploader) Virtualization type is set to: %r' % virt_type)
log.debug('(uploader) Virtualization type '
'is set to: %r' % virt_type)

uploader.set_image_volume_type(volume_type)
log.debug('(uploader) Volume type is set to: %r' % volume_type)

if push_notifications:
fedimg.messenger.notify(
topic='image.upload',
msg=dict(
image_url=image_url,
image_name=image_name,
destination=base_region,
service='EC2',
status='started',
compose=compose_id,
extra=dict(
virt_type=virt_type,
vol_type=volume_type
)
)
)
image = uploader.create_image(source)

publisher = EC2ImagePublisher(
access_key=access_id,
secret_key=secret_key,
push_notifications=True,
)

remaining_regions = set(regions) - set(base_region)
copied_images = publisher.copy_images_to_other_regions(
image_id=image.id,
Expand Down

0 comments on commit 7283f2e

Please sign in to comment.