• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python api.notify函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中neutron.openstack.common.notifier.api.notify函数的典型用法代码示例。如果您正苦于以下问题:Python notify函数的具体用法?Python notify怎么用?Python notify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了notify函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: delete

    def delete(self, request, id, **kwargs):
        """Deletes the specified entity."""
        notifier_api.notify(request.context,
                            self._publisher_id,
                            self._resource + '.delete.start',
                            notifier_api.CONF.default_notification_level,
                            {self._resource + '_id': id})
        action = self._plugin_handlers[self.DELETE]

        # Check authz
        parent_id = kwargs.get(self._parent_id_name)
        obj = self._item(request, id, parent_id=parent_id)
        try:
            policy.enforce(request.context,
                           action,
                           obj)
        except exceptions.PolicyNotAuthorized:
            # To avoid giving away information, pretend that it
            # doesn't exist
            msg = _('The resource could not be found.')
            raise webob.exc.HTTPNotFound(msg)

        obj_deleter = getattr(self._plugin, action)
        obj_deleter(request.context, id, **kwargs)
        notifier_method = self._resource + '.delete.end'
        notifier_api.notify(request.context,
                            self._publisher_id,
                            notifier_method,
                            notifier_api.CONF.default_notification_level,
                            {self._resource + '_id': id})
        result = {self._resource: self._view(request.context, obj)}
        self._send_dhcp_notification(request.context,
                                     result,
                                     notifier_method)
开发者ID:ChengZuo,项目名称:neutron,代码行数:34,代码来源:base.py


示例2: remove_router_interface

    def remove_router_interface(self, context, router_id, interface_info):
        if not interface_info:
            msg = _("Either subnet_id or port_id must be specified")
            raise n_exc.BadRequest(resource='router', msg=msg)
        port_id = interface_info.get('port_id')
        subnet_id = interface_info.get('subnet_id')
        device_owner = self._get_device_owner(context, router_id)
        if port_id:
            port, subnet = self._remove_interface_by_port(context, router_id,
                                                          port_id, subnet_id,
                                                          device_owner)
        elif subnet_id:
            port, subnet = self._remove_interface_by_subnet(
                context, router_id, subnet_id, device_owner)

        self.l3_rpc_notifier.routers_updated(
            context, [router_id], 'remove_router_interface')
        info = {'id': router_id,
                'tenant_id': port['tenant_id'],
                'port_id': port['id'],
                'subnet_id': subnet['id']}
        notifier_api.notify(context,
                            notifier_api.publisher_id('network'),
                            'router.interface.delete',
                            notifier_api.CONF.default_notification_level,
                            {'router_interface': info})
        return info
开发者ID:KumarAcharya,项目名称:neutron,代码行数:27,代码来源:l3_db.py


示例3: update

    def update(self, request, id, body=None, **kwargs):
        """Updates the specified entity's attributes."""
        parent_id = kwargs.get(self._parent_id_name)
        try:
            payload = body.copy()
        except AttributeError:
            msg = _("Invalid format: %s") % request.body
            raise exceptions.BadRequest(resource='body', msg=msg)
        payload['id'] = id
        notifier_api.notify(request.context,
                            self._publisher_id,
                            self._resource + '.update.start',
                            notifier_api.CONF.default_notification_level,
                            payload)
        body = Controller.prepare_request_body(request.context, body, False,
                                               self._resource, self._attr_info,
                                               allow_bulk=self._allow_bulk)
        action = self._plugin_handlers[self.UPDATE]
        # Load object to check authz
        # but pass only attributes in the original body and required
        # by the policy engine to the policy 'brain'
        field_list = [name for (name, value) in self._attr_info.iteritems()
                      if (value.get('required_by_policy') or
                          value.get('primary_key') or
                          'default' not in value)]
        # Ensure policy engine is initialized
        policy.init()
        orig_obj = self._item(request, id, field_list=field_list,
                              parent_id=parent_id)
        orig_object_copy = copy.copy(orig_obj)
        orig_obj.update(body[self._resource])
        try:
            policy.enforce(request.context,
                           action,
                           orig_obj)
        except exceptions.PolicyNotAuthorized:
            # To avoid giving away information, pretend that it
            # doesn't exist
            msg = _('The resource could not be found.')
            raise webob.exc.HTTPNotFound(msg)

        obj_updater = getattr(self._plugin, action)
        kwargs = {self._resource: body}
        if parent_id:
            kwargs[self._parent_id_name] = parent_id
        obj = obj_updater(request.context, id, **kwargs)
        result = {self._resource: self._view(request.context, obj)}
        notifier_method = self._resource + '.update.end'
        notifier_api.notify(request.context,
                            self._publisher_id,
                            notifier_method,
                            notifier_api.CONF.default_notification_level,
                            result)
        self._send_dhcp_notification(request.context,
                                     result,
                                     notifier_method)
        self._nova_notifier.send_network_change(
            action, orig_object_copy, result)
        return result
开发者ID:Zemeio,项目名称:neutron,代码行数:59,代码来源:base.py


示例4: notify

 def notify(create_result):
     notifier_method = self._resource + '.create.end'
     notifier_api.notify(request.context,
                         self._publisher_id,
                         notifier_method,
                         notifier_api.CONF.default_notification_level,
                         create_result)
     self._send_dhcp_notification(request.context,
                                  create_result,
                                  notifier_method)
     return create_result
开发者ID:ChengZuo,项目名称:neutron,代码行数:11,代码来源:base.py


示例5: allocate_ip_address

    def allocate_ip_address(self, context, net_id, port_id, reuse_after,
                            version=None, ip_address=None):
        elevated = context.elevated()
        if ip_address:
            ip_address = netaddr.IPAddress(ip_address)

        new_addresses = []
        realloc_ips = self.attempt_to_reallocate_ip(context, net_id,
                                                    port_id, reuse_after,
                                                    version=None,
                                                    ip_address=None)
        if self.is_strategy_satisfied(realloc_ips):
            return realloc_ips
        new_addresses.extend(realloc_ips)
        with context.session.begin(subtransactions=True):
            subnets = self._choose_available_subnet(
                elevated, net_id, version, ip_address=ip_address,
                reallocated_ips=realloc_ips)
            for subnet in subnets:
                ip_policy_rules = models.IPPolicy.get_ip_policy_rule_set(
                    subnet)
                # Creating this IP for the first time
                next_ip = None
                if ip_address:
                    next_ip = ip_address
                    address = db_api.ip_address_find(
                        elevated, network_id=net_id, ip_address=next_ip,
                        used_by_tenant_id=elevated.tenant_id, scope=db_api.ONE)
                    if address:
                        raise exceptions.IpAddressGenerationFailure(
                            net_id=net_id)
                else:
                    next_ip = self._iterate_until_available_ip(
                        elevated, subnet, net_id, ip_policy_rules)

                context.session.add(subnet)
                address = db_api.ip_address_create(
                    elevated, address=next_ip, subnet_id=subnet["id"],
                    version=subnet["ip_version"], network_id=net_id)
                address["deallocated"] = 0
                new_addresses.append(address)

        for addr in new_addresses:
            payload = dict(used_by_tenant_id=addr["used_by_tenant_id"],
                           ip_block_id=addr["subnet_id"],
                           ip_address=addr["address_readable"],
                           device_ids=[p["device_id"] for p in addr["ports"]],
                           created_at=addr["created_at"])
            notifier_api.notify(context,
                                notifier_api.publisher_id("network"),
                                "ip_block.address.create",
                                notifier_api.CONF.default_notification_level,
                                payload)
        return new_addresses
开发者ID:blamarvt,项目名称:quark,代码行数:54,代码来源:ipam.py


示例6: process_request

    def process_request(self, request):
        request.environ['HTTP_X_SERVICE_NAME'] = \
            self.service_name or request.host
        payload = {
            'request': self.environ_to_dict(request.environ),
        }

        api.notify(context.get_admin_context(),
                   api.publisher_id(os.path.basename(sys.argv[0])),
                   'http.request',
                   api.INFO,
                   payload)
开发者ID:50infivedays,项目名称:neutron,代码行数:12,代码来源:notifier.py


示例7: _notify_new_addresses

 def _notify_new_addresses(self, context, new_addresses):
     for addr in new_addresses:
         payload = dict(used_by_tenant_id=addr["used_by_tenant_id"],
                        ip_block_id=addr["subnet_id"],
                        ip_address=addr["address_readable"],
                        device_ids=[p["device_id"] for p in addr["ports"]],
                        created_at=addr["created_at"])
         notifier_api.notify(context,
                             notifier_api.publisher_id("network"),
                             "ip_block.address.create",
                             notifier_api.CONF.default_notification_level,
                             payload)
开发者ID:blamarvt,项目名称:quark-1,代码行数:12,代码来源:ipam.py


示例8: _deallocate_ip_address

 def _deallocate_ip_address(self, context, address):
     address["deallocated"] = 1
     payload = dict(used_by_tenant_id=address["used_by_tenant_id"],
                    ip_block_id=address["subnet_id"],
                    ip_address=address["address_readable"],
                    device_ids=[p["device_id"] for p in address["ports"]],
                    created_at=address["created_at"],
                    deleted_at=timeutils.utcnow())
     notifier_api.notify(context,
                         notifier_api.publisher_id("network"),
                         "ip_block.address.delete",
                         notifier_api.CONF.default_notification_level,
                         payload)
开发者ID:blamarvt,项目名称:quark,代码行数:13,代码来源:ipam.py


示例9: remove_router_interface

    def remove_router_interface(self, context, router_id, interface_info):
        if not interface_info:
            msg = _("Either subnet_id or port_id must be specified")
            raise q_exc.BadRequest(resource="router", msg=msg)
        if "port_id" in interface_info:
            port_id = interface_info["port_id"]
            port_db = self._core_plugin._get_port(context, port_id)
            if not (port_db["device_owner"] == DEVICE_OWNER_ROUTER_INTF and port_db["device_id"] == router_id):
                raise l3.RouterInterfaceNotFound(router_id=router_id, port_id=port_id)
            if "subnet_id" in interface_info:
                port_subnet_id = port_db["fixed_ips"][0]["subnet_id"]
                if port_subnet_id != interface_info["subnet_id"]:
                    raise q_exc.SubnetMismatchForPort(port_id=port_id, subnet_id=interface_info["subnet_id"])
            subnet_id = port_db["fixed_ips"][0]["subnet_id"]
            subnet = self._core_plugin._get_subnet(context, subnet_id)
            self._confirm_router_interface_not_in_use(context, router_id, subnet_id)
            self._core_plugin.delete_port(context, port_db["id"], l3_port_check=False)
        elif "subnet_id" in interface_info:
            subnet_id = interface_info["subnet_id"]
            self._confirm_router_interface_not_in_use(context, router_id, subnet_id)

            subnet = self._core_plugin._get_subnet(context, subnet_id)
            found = False

            try:
                rport_qry = context.session.query(models_v2.Port)
                ports = rport_qry.filter_by(
                    device_id=router_id, device_owner=DEVICE_OWNER_ROUTER_INTF, network_id=subnet["network_id"]
                )

                for p in ports:
                    if p["fixed_ips"][0]["subnet_id"] == subnet_id:
                        port_id = p["id"]
                        self._core_plugin.delete_port(context, p["id"], l3_port_check=False)
                        found = True
                        break
            except exc.NoResultFound:
                pass

            if not found:
                raise l3.RouterInterfaceNotFoundForSubnet(router_id=router_id, subnet_id=subnet_id)
        self.l3_rpc_notifier.routers_updated(context, [router_id], "remove_router_interface")
        info = {"id": router_id, "tenant_id": subnet["tenant_id"], "port_id": port_id, "subnet_id": subnet_id}
        notifier_api.notify(
            context,
            notifier_api.publisher_id("network"),
            "router.interface.delete",
            notifier_api.CONF.default_notification_level,
            {"router.interface": info},
        )
        return info
开发者ID:Ahmed-Azri,项目名称:Cloud-Networking-SDN,代码行数:51,代码来源:l3_db.py


示例10: _metering_notification

    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_api.notify(self.context,
                                notifier_api.publisher_id('metering'),
                                'l3.meter',
                                notifier_api.CONF.default_notification_level,
                                data)
            info['pkts'] = 0
            info['bytes'] = 0
            info['time'] = 0
开发者ID:uramanan,项目名称:neutron,代码行数:20,代码来源:metering_agent.py


示例11: add_router_interface

    def add_router_interface(self, context, router_id, interface_info):
        add_by_port, add_by_sub = self._validate_interface_info(interface_info)
        device_owner = self._get_device_owner(context, router_id)

        if add_by_port:
            port = self._add_interface_by_port(
                context, router_id, interface_info['port_id'], device_owner)
        elif add_by_sub:
            port = self._add_interface_by_subnet(
                context, router_id, interface_info['subnet_id'], device_owner)

        self.l3_rpc_notifier.routers_updated(
            context, [router_id], 'add_router_interface')
        info = {'id': router_id,
                'tenant_id': port['tenant_id'],
                'port_id': port['id'],
                'subnet_id': port['fixed_ips'][0]['subnet_id']}
        notifier_api.notify(context,
                            notifier_api.publisher_id('network'),
                            'router.interface.create',
                            notifier_api.CONF.default_notification_level,
                            {'router_interface': info})
        return info
开发者ID:KumarAcharya,项目名称:neutron,代码行数:23,代码来源:l3_db.py


示例12: process_response

    def process_response(self, request, response,
                         exception=None, traceback=None):
        payload = {
            'request': self.environ_to_dict(request.environ),
        }

        if response:
            payload['response'] = {
                'status': response.status,
                'headers': response.headers,
            }

        if exception:
            payload['exception'] = {
                'value': repr(exception),
                'traceback': tb.format_tb(traceback)
            }

        api.notify(context.get_admin_context(),
                   api.publisher_id(os.path.basename(sys.argv[0])),
                   'http.response',
                   api.INFO,
                   payload)
开发者ID:50infivedays,项目名称:neutron,代码行数:23,代码来源:notifier.py


示例13: delete_subnet

def delete_subnet(context, id):
    """Delete a subnet.

    : param context: neutron api request context
    : param id: UUID representing the subnet to delete.
    """
    LOG.info("delete_subnet %s for tenant %s" % (id, context.tenant_id))
    with context.session.begin():
        subnet = db_api.subnet_find(context, id=id, scope=db_api.ONE)
        if not subnet:
            raise exceptions.SubnetNotFound(subnet_id=id)

        payload = dict(tenant_id=subnet["tenant_id"],
                       ip_block_id=subnet["id"],
                       created_at=subnet["created_at"],
                       deleted_at=timeutils.utcnow())

        _delete_subnet(context, subnet)

        notifier_api.notify(context,
                            notifier_api.publisher_id("network"),
                            "ip_block.delete",
                            notifier_api.CONF.default_notification_level,
                            payload)
开发者ID:mohanraj1311,项目名称:quark,代码行数:24,代码来源:subnets.py


示例14: main

def main():
    cfg.CONF(project='neutron')
    config.setup_logging(cfg.CONF)

    cxt = context.get_admin_context()
    plugin = manager.NeutronManager.get_plugin()
    for network in plugin.get_networks(cxt):
        notifier_api.notify(cxt,
                            notifier_api.publisher_id('network'),
                            'network.exists',
                            notifier_api.INFO,
                            {'network': network})
    for subnet in plugin.get_subnets(cxt):
        notifier_api.notify(cxt,
                            notifier_api.publisher_id('network'),
                            'subnet.exists',
                            notifier_api.INFO,
                            {'subnet': subnet})
    for port in plugin.get_ports(cxt):
        notifier_api.notify(cxt,
                            notifier_api.publisher_id('network'),
                            'port.exists',
                            notifier_api.INFO,
                            {'port': port})
    for router in plugin.get_routers(cxt):
        notifier_api.notify(cxt,
                            notifier_api.publisher_id('network'),
                            'router.exists',
                            notifier_api.INFO,
                            {'router': router})
    for floatingip in plugin.get_floatingips(cxt):
        notifier_api.notify(cxt,
                            notifier_api.publisher_id('network'),
                            'floatingip.exists',
                            notifier_api.INFO,
                            {'floatingip': floatingip})
开发者ID:50infivedays,项目名称:neutron,代码行数:36,代码来源:usage_audit.py


示例15: _metering_notification

    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_api.notify(
                self.context,
                notifier_api.publisher_id("metering"),
                "l3.meter",
                notifier_api.CONF.default_notification_level,
                data,
            )
            info["pkts"] = 0
            info["bytes"] = 0
            info["time"] = 0
开发者ID:gjholler,项目名称:neutron,代码行数:24,代码来源:metering_agent.py


示例16: add_router_interface

    def add_router_interface(self, context, router_id, interface_info):
        if not interface_info:
            msg = _("Either subnet_id or port_id must be specified")
            raise q_exc.BadRequest(resource="router", msg=msg)

        if "port_id" in interface_info:
            # make sure port update is committed
            with context.session.begin(subtransactions=True):
                if "subnet_id" in interface_info:
                    msg = _("Cannot specify both subnet-id and port-id")
                    raise q_exc.BadRequest(resource="router", msg=msg)

                port = self._get_port(context, interface_info["port_id"])
                if port["device_id"]:
                    raise q_exc.PortInUse(net_id=port["network_id"], port_id=port["id"], device_id=port["device_id"])
                fixed_ips = [ip for ip in port["fixed_ips"]]
                if len(fixed_ips) != 1:
                    msg = _("Router port must have exactly one fixed IP")
                    raise q_exc.BadRequest(resource="router", msg=msg)
                subnet_id = fixed_ips[0]["subnet_id"]
                subnet = self._get_subnet(context, subnet_id)
                self._check_for_dup_router_subnet(context, router_id, port["network_id"], subnet["id"], subnet["cidr"])
                port.update({"device_id": router_id, "device_owner": DEVICE_OWNER_ROUTER_INTF})
        elif "subnet_id" in interface_info:
            subnet_id = interface_info["subnet_id"]
            subnet = self._get_subnet(context, subnet_id)
            # Ensure the subnet has a gateway
            if not subnet["gateway_ip"]:
                msg = _("Subnet for router interface must have a gateway IP")
                raise q_exc.BadRequest(resource="router", msg=msg)
            self._check_for_dup_router_subnet(context, router_id, subnet["network_id"], subnet_id, subnet["cidr"])
            fixed_ip = {"ip_address": subnet["gateway_ip"], "subnet_id": subnet["id"]}
            port = self.create_port(
                context,
                {
                    "port": {
                        "tenant_id": subnet["tenant_id"],
                        "network_id": subnet["network_id"],
                        "fixed_ips": [fixed_ip],
                        "mac_address": attributes.ATTR_NOT_SPECIFIED,
                        "admin_state_up": True,
                        "device_id": router_id,
                        "device_owner": DEVICE_OWNER_ROUTER_INTF,
                        "name": "",
                    }
                },
            )

        l3_rpc_agent_api.L3AgentNotify.routers_updated(context, [router_id], "add_router_interface")
        info = {
            "id": router_id,
            "tenant_id": subnet["tenant_id"],
            "port_id": port["id"],
            "subnet_id": port["fixed_ips"][0]["subnet_id"],
        }
        notifier_api.notify(
            context,
            notifier_api.publisher_id("network"),
            "router.interface.create",
            notifier_api.CONF.default_notification_level,
            {"router.interface": info},
        )
        return info
开发者ID:nitinnain,项目名称:neutron,代码行数:63,代码来源:l3_db.py


示例17: add_router_interface

    def add_router_interface(self, context, router_id, interface_info):
        LOG.debug(_("add_router_interface called in l3_db.py context: %s"), context)
        LOG.debug(_("add_router_interface called in l3_db.py router: %s"), router_id)
        LOG.debug(_("add_router_interface called in l3_db.py interface: %s"), interface_info)

        if not interface_info:
            msg = _("Either subnet_id or port_id must be specified")
            raise q_exc.BadRequest(resource="router", msg=msg)

        if "port_id" in interface_info:
            # make sure port update is committed
            LOG.debug(_("add_router_interface called in l3_db.py portid given"))
            with context.session.begin(subtransactions=True):
                if "subnet_id" in interface_info:
                    msg = _("Cannot specify both subnet-id and port-id")
                    raise q_exc.BadRequest(resource="router", msg=msg)

                port = self._core_plugin._get_port(context, interface_info["port_id"])
                LOG.debug(_("add_router_interface called in l3_db.py port returned by plugin: %s"), port)
                if port["device_id"]:
                    raise q_exc.PortInUse(net_id=port["network_id"], port_id=port["id"], device_id=port["device_id"])
                fixed_ips = [ip for ip in port["fixed_ips"]]
                if len(fixed_ips) != 1:
                    msg = _("Router port must have exactly one fixed IP")
                    raise q_exc.BadRequest(resource="router", msg=msg)
                subnet_id = fixed_ips[0]["subnet_id"]
                subnet = self._core_plugin._get_subnet(context, subnet_id)
                LOG.debug(_("add_router_interface called in l3_db.py subnet returned by plugin: %s"), subnet)
                self._check_for_dup_router_subnet(context, router_id, port["network_id"], subnet["id"], subnet["cidr"])
                LOG.debug(_("add_router_interface called in l3_db.py port.update going to be called"))
                port.update({"device_id": router_id, "device_owner": DEVICE_OWNER_ROUTER_INTF})
                LOG.debug(_("add_router_interface called in l3_db.py port.update going to be called over"))
        elif "subnet_id" in interface_info:
            LOG.debug(_("add_router_interface called in l3_db.py subnetid given"))
            subnet_id = interface_info["subnet_id"]
            subnet = self._core_plugin._get_subnet(context, subnet_id)
            LOG.debug(_("add_router_interface called in l3_db.py subnet returned by plugin: %s"), subnet)

            # Ensure the subnet has a gateway
            if not subnet["gateway_ip"]:
                msg = _("Subnet for router interface must have a gateway IP")
                raise q_exc.BadRequest(resource="router", msg=msg)
            self._check_for_dup_router_subnet(context, router_id, subnet["network_id"], subnet_id, subnet["cidr"])
            fixed_ip = {"ip_address": subnet["gateway_ip"], "subnet_id": subnet["id"]}
            port = self._core_plugin.create_port(
                context,
                {
                    "port": {
                        "tenant_id": subnet["tenant_id"],
                        "network_id": subnet["network_id"],
                        "fixed_ips": [fixed_ip],
                        "mac_address": attributes.ATTR_NOT_SPECIFIED,
                        "admin_state_up": True,
                        "device_id": router_id,
                        "device_owner": DEVICE_OWNER_ROUTER_INTF,
                        "name": "",
                    }
                },
            )
            LOG.debug(_("add_router_interface called in l3_db.py port returned by plugin: %s"), port)

        LOG.debug(_("add_router_interface called in l3_db.py router_updated being called context: %s"), context)
        LOG.debug(_("add_router_interface called in l3_db.py l3_rpc_notifier.update_routers being called"))
        """
	self.l3_rpc_notifier.routers_updated(
            context, [router_id], 'add_router_interface')
        """
        # inform ML2 plugin on creation of router ports
        self._core_plugin.update_router_interface(context, router_id)
        info = {
            "id": router_id,
            "tenant_id": subnet["tenant_id"],
            "port_id": port["id"],
            "subnet_id": port["fixed_ips"][0]["subnet_id"],
        }
        LOG.debug(_("add_router_interface called in l3_db.py info: %s"), info)
        LOG.debug(_("add_router_interface called in l3_db.py notify_api called"))

        notifier_api.notify(
            context,
            notifier_api.publisher_id("network"),
            "router.interface.create",
            notifier_api.CONF.default_notification_level,
            {"router.interface": info},
        )

        LOG.debug(_("add_router_interface called in l3_db.py notify_api called over"))
        return info
开发者ID:Ahmed-Azri,项目名称:Cloud-Networking-SDN,代码行数:88,代码来源:l3_db.py


示例18: create

    def create(self, request, body=None, **kwargs):
        """Creates a new instance of the requested entity."""
        parent_id = kwargs.get(self._parent_id_name)
        notifier_api.notify(request.context,
                            self._publisher_id,
                            self._resource + '.create.start',
                            notifier_api.CONF.default_notification_level,
                            body)
        body = Controller.prepare_request_body(request.context, body, True,
                                               self._resource, self._attr_info,
                                               allow_bulk=self._allow_bulk)
        action = self._plugin_handlers[self.CREATE]
        # Check authz
        if self._collection in body:
            # Have to account for bulk create
            items = body[self._collection]
            deltas = {}
            bulk = True
        else:
            items = [body]
            bulk = False
        for item in items:
            self._validate_network_tenant_ownership(request,
                                                    item[self._resource])
            policy.enforce(request.context,
                           action,
                           item[self._resource])
            try:
                tenant_id = item[self._resource]['tenant_id']
                count = quota.QUOTAS.count(request.context, self._resource,
                                           self._plugin, self._collection,
                                           tenant_id)
                if bulk:
                    delta = deltas.get(tenant_id, 0) + 1
                    deltas[tenant_id] = delta
                else:
                    delta = 1
                kwargs = {self._resource: count + delta}
            except exceptions.QuotaResourceUnknown as e:
                # We don't want to quota this resource
                LOG.debug(e)
            else:
                quota.QUOTAS.limit_check(request.context,
                                         item[self._resource]['tenant_id'],
                                         **kwargs)

        def notify(create_result):
            notifier_method = self._resource + '.create.end'
            notifier_api.notify(request.context,
                                self._publisher_id,
                                notifier_method,
                                notifier_api.CONF.default_notification_level,
                                create_result)
            self._send_dhcp_notification(request.context,
                                         create_result,
                                         notifier_method)
            return create_result

        kwargs = {self._parent_id_name: parent_id} if parent_id else {}
        if self._collection in body and self._native_bulk:
            # plugin does atomic bulk create operations
            obj_creator = getattr(self._plugin, "%s_bulk" % action)
            objs = obj_creator(request.context, body, **kwargs)
            return notify({self._collection: [self._view(request.context, obj)
                                              for obj in objs]})
        else:
            obj_creator = getattr(self._plugin, action)
            if self._collection in body:
                # Emulate atomic bulk behavior
                objs = self._emulate_bulk_create(obj_creator, request,
                                                 body, parent_id)
                return notify({self._collection: objs})
            else:
                kwargs.update({self._resource: body})
                obj = obj_creator(request.context, **kwargs)
                return notify({self._resource: self._view(request.context,
                                                          obj)})
开发者ID:ChengZuo,项目名称:neutron,代码行数:77,代码来源:base.py


示例19: add_router_interface

    def add_router_interface(self, context, router_id, interface_info):
        if not interface_info:
            msg = _("Either subnet_id or port_id must be specified")
            raise n_exc.BadRequest(resource='router', msg=msg)

        if 'port_id' in interface_info:
            # make sure port update is committed
            with context.session.begin(subtransactions=True):
                if 'subnet_id' in interface_info:
                    msg = _("Cannot specify both subnet-id and port-id")
                    raise n_exc.BadRequest(resource='router', msg=msg)

                port = self._core_plugin._get_port(context,
                                                   interface_info['port_id'])
                if port['device_id']:
                    raise n_exc.PortInUse(net_id=port['network_id'],
                                          port_id=port['id'],
                                          device_id=port['device_id'])
                fixed_ips = [ip for ip in port['fixed_ips']]
                if len(fixed_ips) != 1:
                    msg = _('Router port must have exactly one fixed IP')
                    raise n_exc.BadRequest(resource='router', msg=msg)
                subnet_id = fixed_ips[0]['subnet_id']
                subnet = self._core_plugin._get_subnet(context, subnet_id)
                self._check_for_dup_router_subnet(context, router_id,
                                                  port['network_id'],
                                                  subnet['id'],
                                                  subnet['cidr'])
                port.update({'device_id': router_id,
                             'device_owner': DEVICE_OWNER_ROUTER_INTF})
        elif 'subnet_id' in interface_info:
            subnet_id = interface_info['subnet_id']
            subnet = self._core_plugin._get_subnet(context, subnet_id)
            # Ensure the subnet has a gateway
            if not subnet['gateway_ip']:
                msg = _('Subnet for router interface must have a gateway IP')
                raise n_exc.BadRequest(resource='router', msg=msg)
            self._check_for_dup_router_subnet(context, router_id,
                                              subnet['network_id'],
                                              subnet_id,
                                              subnet['cidr'])
            fixed_ip = {'ip_address': subnet['gateway_ip'],
                        'subnet_id': subnet['id']}
            port = self._core_plugin.create_port(context, {
                'port':
                {'tenant_id': subnet['tenant_id'],
                 'network_id': subnet['network_id'],
                 'fixed_ips': [fixed_ip],
                 'mac_address': attributes.ATTR_NOT_SPECIFIED,
                 'admin_state_up': True,
                 'device_id': router_id,
                 'device_owner': DEVICE_OWNER_ROUTER_INTF,
                 'name': ''}})

        self.l3_rpc_notifier.routers_updated(
            context, [router_id], 'add_router_interface')
        info = {'id': router_id,
                'tenant_id': subnet['tenant_id'],
                'port_id': port['id'],
                'subnet_id': port['fixed_ips'][0]['subnet_id']}
        notifier_api.notify(context,
                            notifier_api.publisher_id('network'),
                            'router.interface.create',
                            notifier_api.CONF.default_notification_level,
                            {'router_interface': info})
        return info
开发者ID:kbijon,项目名称:OpenStack-CVRM,代码行数:66,代码来源:l3_db.py


示例20: remove_router_interface


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python api.publisher_id函数代码示例发布时间:2022-05-27
下一篇:
Python log.getLogger函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap