Ejemplo n.º 1
0
        def _inner():
            if initial_delay:
                greenthread.sleep(initial_delay)

            try:
                while self._running:
                    start = timeutils.utcnow()
                    self.f(*self.args, **self.kw)
                    end = timeutils.utcnow()
                    if not self._running:
                        break
                    delay = interval - timeutils.delta_seconds(start, end)
                    if delay <= 0:
                        LOG.warn(_LW('task run outlasted interval by %s sec') %
                                 -delay)
                    greenthread.sleep(delay if delay > 0 else 0)
            except LoopingCallDone as e:
                self.stop()
                done.send(e.retvalue)
            except Exception:
                LOG.exception(_LE('in fixed duration looping call'))
                done.send_exception(*sys.exc_info())
                return
            else:
                done.send(True)
Ejemplo n.º 2
0
def notify(context, publisher_id, event_type, priority, payload):
    """Sends a notification using the specified driver

    :param publisher_id: the source worker_type.host of the message
    :param event_type:   the literal type of event (ex. Instance Creation)
    :param priority:     patterned after the enumeration of Python logging
                         levels in the set (DEBUG, WARN, INFO, ERROR, CRITICAL)
    :param payload:       A python dictionary of attributes

    Outgoing message format includes the above parameters, and appends the
    following:

    message_id
      a UUID representing the id for this notification

    timestamp
      the GMT timestamp the notification was sent at

    The composite message will be constructed as a dictionary of the above
    attributes, which will then be sent via the transport mechanism defined
    by the driver.

    Message example::

        {'message_id': str(uuid.uuid4()),
         'publisher_id': 'compute.host1',
         'timestamp': timeutils.utcnow(),
         'priority': 'WARN',
         'event_type': 'compute.create_instance',
         'payload': {'instance_id': 12, ... }}

    """
    if priority not in log_levels:
        raise BadPriorityException(_('%s not in valid priorities') % priority)

    # Ensure everything is JSON serializable.
    payload = jsonutils.to_primitive(payload, convert_instances=True)

    msg = dict(message_id=str(uuid.uuid4()),
               publisher_id=publisher_id,
               event_type=event_type,
               priority=priority,
               payload=payload,
               timestamp=str(timeutils.utcnow()))

    for driver in _get_drivers():
        try:
            driver.notify(context, msg)
        except Exception as e:
            LOG.exception(
                _LE("Problem '%(e)s' attempting to "
                    "send to notification system. "
                    "Payload=%(payload)s") % dict(e=e, payload=payload))
Ejemplo n.º 3
0
def _vcenter_format(vcenter_id, **values):
    """ Returns default vCenter data """
    dt = timeutils.utcnow()
    vcenter = {
        'id': vcenter_id,
        'name': None,
        'ip_address': None,
        'username': None,
        'password': None,
        'password_id': None,
        'created_at': dt,
        'updated_at': dt,
        'deleted_at': None,
        'deleted': False,
    }
    vcenter.update(values)
    return vcenter
Ejemplo n.º 4
0
def _ippool_format(pool_id, **values):
    """
    Return default ippool data.
    """
    dt = timeutils.utcnow()
    ippool = {
        'id': pool_id,
        'pool_type': None,
        'ips': [],
        'created_at': dt,
        'updated_at': dt,
        'deleted_at': None,
        'deleted': False,
    }
    ippool.update(values)

    return ippool
Ejemplo n.º 5
0
def _esx_proxy_format(esx_proxy_id, **values):
    """Return default esx proxy data"""
    dt = timeutils.utcnow()
    esx_proxy = {
        'id': esx_proxy_id,
        'active': None,
        'name': None,
        'ip_address': None,
        'vcenter_id': None,
        'routing_key': None,
        'created_at': dt,
        'updated_at': dt,
        'deleted_at': None,
        'deleted': False,
    }
    esx_proxy.update(values)

    return esx_proxy
Ejemplo n.º 6
0
def _ip_format(ip_id, **values):
    """
    Return default ip data.
    """
    dt = timeutils.utcnow()
    ip = {
        'id': ip_id,
        'ipaddress': None,
        'pool_id': None,
        'esx_proxy_id': None,
        'created_at': dt,
        'updated_at': dt,
        'deleted_at': None,
        'deleted': False,
    }
    ip.update(values)

    return ip