~cprov/core-image-publisher/fake-home

« back to all changes in this revision

Viewing changes to core_image_publisher/worker.py

  • Committer: Ubuntu CI Bot
  • Author(s): Thomi Richards
  • Date: 2015-03-30 21:32:23 UTC
  • mfrom: (12.3.4 trunk-publish-messages)
  • Revision ID: ubuntu_ci_bot-20150330213223-8svznrcowc0f93g0
Publish result messages to the next micro-service. [r=Francis Ginther]

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import subprocess
23
23
import tempfile
24
24
 
25
 
from core_image_publisher.queue import (
26
 
    enqueue_message,
27
 
    MessageActions,
28
 
)
 
25
from core_image_publisher.queue import MessageActions
29
26
from core_image_publisher.cloud import get_glance_client
30
27
from core_image_publisher.utils import check_call
31
28
 
36
33
 
37
34
    """A worker callable that contains all our main logic."""
38
35
 
39
 
    def __init__(self, config):
 
36
    def __init__(self, config, publisher):
40
37
        self._config = config
 
38
        self.publish_results = publisher
41
39
 
42
40
    def __call__(self, payload):
43
41
        logger.info("Got %r", payload, extra=payload)
83
81
            logger.info("Image uploaded to glance OK.", extra=payload)
84
82
 
85
83
        payload['nova_image'] = glance_image_name
86
 
        enqueue_message(payload)
 
84
        self.publish_results(payload)
87
85
        logger.info("Processing completed.", extra=payload)
88
86
        return MessageActions.Acknowledge
89
87
 
126
124
    """
127
125
    glance = get_glance_client(config)
128
126
    image_name = os.path.basename(nova_image_path)
129
 
    image = glance.images.create(
 
127
    glance.images.create(
130
128
        name=image_name,
131
129
        data=open(nova_image_path, 'rb'),
132
130
        disk_format='qcow2',