示例#1
0
文件: tagging.py 项目: thh/neutron
def notify_tag_action(context, action, parent, parent_id, tags=None):
    notifier = n_rpc.get_notifier('network')
    tag_event = 'tag.%s' % action
    # TODO(hichihara): Add 'updated_at' into payload
    payload = {'parent_resource': parent, 'parent_resource_id': parent_id}
    if tags is not None:
        payload['tags'] = tags
    notifier.info(context, tag_event, payload)
示例#2
0
    def test_get_notifier_null_publisher(self):
        rpc.NOTIFIER = mock.Mock()
        mock_prep = mock.Mock()
        mock_prep.return_value = 'notifier'
        rpc.NOTIFIER.prepare = mock_prep

        notifier = rpc.get_notifier('service', host='bar')

        mock_prep.assert_called_once_with(publisher_id='service.bar')
        self.assertEqual('notifier', notifier)
示例#3
0
 def __init__(self,
              plugin,
              collection,
              resource,
              attr_info,
              allow_bulk=False,
              member_actions=None,
              parent=None,
              allow_pagination=False,
              allow_sorting=False):
     if member_actions is None:
         member_actions = []
     self._plugin = plugin
     self._collection = collection.replace('-', '_')
     self._resource = resource.replace('-', '_')
     self._attr_info = attr_info
     self._allow_bulk = allow_bulk
     self._allow_pagination = allow_pagination
     self._allow_sorting = allow_sorting
     self._native_bulk = self._is_native_bulk_supported()
     self._native_pagination = self._is_native_pagination_supported()
     self._native_sorting = self._is_native_sorting_supported()
     self._filter_validation = self._is_filter_validation_supported()
     self._policy_attrs = self._init_policy_attrs()
     self._notifier = n_rpc.get_notifier('network')
     self._member_actions = member_actions
     self._primary_key = self._get_primary_key()
     if self._allow_pagination and self._native_pagination:
         # Native pagination need native sorting support
         if not self._native_sorting:
             raise exceptions.Invalid(
                 _("Native pagination depend on native sorting"))
         if not self._allow_sorting:
             LOG.info("Allow sorting is enabled because native "
                      "pagination requires native sorting")
             self._allow_sorting = True
     self.parent = parent
     if parent:
         self._parent_id_name = '%s_id' % parent['member_name']
         parent_part = '_%s' % parent['member_name']
     else:
         self._parent_id_name = None
         parent_part = ''
     self._plugin_handlers = {
         self.LIST: 'get%s_%s' % (parent_part, self._collection),
         self.SHOW: 'get%s_%s' % (parent_part, self._resource)
     }
     for action in [self.CREATE, self.UPDATE, self.DELETE]:
         self._plugin_handlers[action] = '%s%s_%s' % (action, parent_part,
                                                      self._resource)
示例#4
0
    def _metering_notification(self):
        for label_id, info in self.metering_infos.items():
            data = {'label_id': label_id,
                    'tenant_id': self.label_tenant_id.get(label_id),
                    'pkts': info['pkts'],
                    'bytes': info['bytes'],
                    'time': info['time'],
                    'first_update': info['first_update'],
                    'last_update': info['last_update'],
                    'host': self.host}

            LOG.debug("Send metering report: %s", data)
            notifier = n_rpc.get_notifier('metering')
            notifier.info(self.context, 'l3.meter', data)
            info['pkts'] = 0
            info['bytes'] = 0
            info['time'] = 0
示例#5
0
    def _metering_notification(self):
        for key, info in self.metering_infos.items():
            data = self.create_notification_message_data(info, key)

            traffic_meter_event = 'l3.meter'

            granularity = info.get('traffic-counter-granularity')
            if granularity:
                traffic_meter_event = 'l3.meter.%s' % granularity

            LOG.debug("Send metering report [%s] via event [%s].", data,
                      traffic_meter_event)

            notifier = n_rpc.get_notifier('metering')
            notifier.info(self.context, traffic_meter_event, data)

            info['pkts'] = 0
            info['bytes'] = 0
            info['time'] = 0
def main():
    config.init(sys.argv[1:])
    config.setup_logging()

    cxt = context.get_admin_context()
    manager.init()
    plugin = directory.get_plugin()
    l3_plugin = directory.get_plugin(constants.L3)
    notifier = n_rpc.get_notifier('network')
    for network in plugin.get_networks(cxt):
        notifier.info(cxt, 'network.exists', {'network': network})
    for subnet in plugin.get_subnets(cxt):
        notifier.info(cxt, 'subnet.exists', {'subnet': subnet})
    for port in plugin.get_ports(cxt):
        notifier.info(cxt, 'port.exists', {'port': port})
    for router in l3_plugin.get_routers(cxt):
        notifier.info(cxt, 'router.exists', {'router': router})
    for floatingip in l3_plugin.get_floatingips(cxt):
        notifier.info(cxt, 'floatingip.exists', {'floatingip': floatingip})
示例#7
0
def notify(context, action, router_id, agent_id):
    info = {'id': agent_id, 'router_id': router_id}
    notifier = n_rpc.get_notifier('router')
    notifier.info(context, action, {'agent': info})
def notify(context, action, network_id, agent_id):
    info = {'id': agent_id, 'network_id': network_id}
    notifier = n_rpc.get_notifier('network')
    notifier.info(context, action, {'agent': info})
示例#9
0
 def _notifier(self):
     if not hasattr(self, '_notifier_inst'):
         self._notifier_inst = n_rpc.get_notifier('network')
     return self._notifier_inst
示例#10
0
 def _notify_firewall_updates(self, context, resource, update_info):
     notifier = n_rpc.get_notifier('network')
     notifier.info(context, resource, update_info)
示例#11
0
def notify(context, action, network_id, agent_id):
    info = {'id': agent_id, 'network_id': network_id}
    notifier = n_rpc.get_notifier('network')
    notifier.info(context, action, {'agent': info})
示例#12
0
 def _notifier(self):
     if not hasattr(self, '_notifier_inst'):
         self._notifier_inst = n_rpc.get_notifier('network')
     return self._notifier_inst
示例#13
0
def notify(context, action, router_id, agent_id):
    info = {'id': agent_id, 'router_id': router_id}
    notifier = n_rpc.get_notifier('router')
    notifier.info(context, action, {'agent': info})