Beispiel #1
0
def notifier(_id, transport, messages, wait_after_msg, timeout,
             service, action, project_id, resource_id, load_date):
    n1 = notify.Notifier(transport, topic="notifications").prepare(
        publisher_id='publisher-%d' % _id)
    # msg = 0
    for i in range(0, messages):
        # msg = 1 + msg
        ctxt = {}

        LOG.info("send msg")
        if service == 'nova':
            if action == 'create':
                n1.info(ctxt, 'compute.instance.create',
                        _instance_payload(project_id, resource_id, load_date))
            elif action == 'delete':
                n1.info(ctxt, 'compute.instance.delete',
                        _instance_payload(project_id, resource_id, load_date))
            else:
                LOG.exception('Action %s not create or delete' % (action))
                break
        elif service == 'cinder':
            if action == 'create':
                n1.info(ctxt, 'volume.create',
                        _volume_payload(project_id, resource_id, load_date))
            elif action == 'delete':
                n1.info(ctxt, 'volume.delete',
                        _volume_payload(project_id, resource_id, load_date))
            else:
                LOG.exception('Action %s not create or delete' % (action))
                break
        elif service == 'glance':
            if action == 'create':
                n1.info(ctxt, 'image.upload',
                        _image_payload(project_id, resource_id, load_date))
            elif action == 'delete':
                n1.info(ctxt, 'image.delete',
                        _image_payload(project_id, resource_id, load_date))
            else:
                LOG.exception('Action %s not create or delete' % (action))
                break
        else:
            LOG.exception('Service %s not nova, cinder or glance' % (action))
            break

        if wait_after_msg > 0:
            time.sleep(wait_after_msg)
Beispiel #2
0
 def __init__(self, client_id, transport, topic, wait_after_msg):
     client = notify.Notifier(transport, driver='messaging', topic=topic)
     client = client.prepare(publisher_id='publisher-%d' % client_id)
     method = _notify
     super(NotifyClient, self).__init__(client_id, client, method, False,
                                        wait_after_msg)