当前位置: 首页>>代码示例>>Python>>正文


Python utils.create_port函数代码示例

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


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

示例1: _port_action

 def _port_action(self, plugin, context, port, action):
     """Perform port operations taking care of concurrency issues."""
     try:
         if action == 'create_port':
             return p_utils.create_port(plugin, context, port)
         elif action == 'update_port':
             return plugin.update_port(context, port['id'], port)
         else:
             msg = _('Unrecognized action')
             raise exceptions.Invalid(message=msg)
     except (db_exc.DBError,
             exceptions.NetworkNotFound,
             exceptions.SubnetNotFound,
             exceptions.IpAddressGenerationFailure) as e:
         with excutils.save_and_reraise_exception(reraise=False) as ctxt:
             if isinstance(e, exceptions.IpAddressGenerationFailure):
                 # Check if the subnet still exists and if it does not,
                 # this is the reason why the ip address generation failed.
                 # In any other unlikely event re-raise
                 try:
                     subnet_id = port['port']['fixed_ips'][0]['subnet_id']
                     plugin.get_subnet(context, subnet_id)
                 except exceptions.SubnetNotFound:
                     pass
                 else:
                     ctxt.reraise = True
             net_id = port['port']['network_id']
             LOG.warning(_LW("Action %(action)s for network %(net_id)s "
                             "could not complete successfully: %(reason)s"),
                         {"action": action, "net_id": net_id, 'reason': e})
开发者ID:biruce-openstack,项目名称:neutron,代码行数:30,代码来源:dhcp_rpc.py

示例2: _add_csnat_router_interface_port

    def _add_csnat_router_interface_port(
            self, context, router, network_id, subnet_id, do_pop=True):
        """Add SNAT interface to the specified router and subnet."""
        port_data = {'tenant_id': '',
                     'network_id': network_id,
                     'fixed_ips': [{'subnet_id': subnet_id}],
                     'device_id': router.id,
                     'device_owner': const.DEVICE_OWNER_ROUTER_SNAT,
                     'admin_state_up': True,
                     'name': ''}
        snat_port = p_utils.create_port(self._core_plugin, context,
                                        {'port': port_data})
        if not snat_port:
            msg = _("Unable to create the SNAT Interface Port")
            raise n_exc.BadRequest(resource='router', msg=msg)

        with context.session.begin(subtransactions=True):
            router_port = l3_db.RouterPort(
                port_id=snat_port['id'],
                router_id=router.id,
                port_type=const.DEVICE_OWNER_ROUTER_SNAT
            )
            context.session.add(router_port)

        if do_pop:
            return self._populate_mtu_and_subnets_for_ports(context,
                                                            [snat_port])
        return snat_port
开发者ID:andreitira,项目名称:neutron,代码行数:28,代码来源:l3_dvr_db.py

示例3: create_fip_agent_gw_port_if_not_exists

    def create_fip_agent_gw_port_if_not_exists(
        self, context, network_id, host):
        """Function to return the FIP Agent GW port.

        This function will create a FIP Agent GW port
        if required. If the port already exists, it
        will return the existing port and will not
        create a new one.
        """
        l3_agent_db = self._get_agent_by_type_and_host(
            context, l3_const.AGENT_TYPE_L3, host)
        if l3_agent_db:
            LOG.debug("Agent ID exists: %s", l3_agent_db['id'])
            f_port = self._get_agent_gw_ports_exist_for_network(
                context, network_id, host, l3_agent_db['id'])
            if not f_port:
                LOG.info(_LI('Agent Gateway port does not exist,'
                             ' so create one: %s'), f_port)
                port_data = {'tenant_id': '',
                             'network_id': network_id,
                             'device_id': l3_agent_db['id'],
                             'device_owner': l3_const.DEVICE_OWNER_AGENT_GW,
                             'binding:host_id': host,
                             'admin_state_up': True,
                             'name': ''}
                agent_port = p_utils.create_port(self._core_plugin, context,
                                                 {'port': port_data})
                if agent_port:
                    self._populate_subnets_for_ports(context, [agent_port])
                    return agent_port
                msg = _("Unable to create the Agent Gateway Port")
                raise n_exc.BadRequest(resource='router', msg=msg)
            else:
                self._populate_subnets_for_ports(context, [f_port])
                return f_port
开发者ID:glove747,项目名称:liberty-neutron,代码行数:35,代码来源:l3_dvr_db.py

示例4: add_ha_port

    def add_ha_port(self, context, router_id, network_id, tenant_id):
        # NOTE(kevinbenton): we have to block any ongoing transactions because
        # our exception handling will try to delete the port using the normal
        # core plugin API. If this function is called inside of a transaction
        # the exception will mangle the state, cause the delete call to fail,
        # and end up relying on the DB rollback to remove the port instead of
        # proper delete_port call.
        if context.session.is_active:
            raise RuntimeError(_('add_ha_port cannot be called inside of a '
                                 'transaction.'))
        args = {'tenant_id': '',
                'network_id': network_id,
                'admin_state_up': True,
                'device_id': router_id,
                'device_owner': constants.DEVICE_OWNER_ROUTER_HA_INTF,
                'name': constants.HA_PORT_NAME % tenant_id}
        port = p_utils.create_port(self._core_plugin, context,
                                 {'port': args})

        try:
            return self._create_ha_port_binding(context, port['id'], router_id)
        except Exception:
            with excutils.save_and_reraise_exception():
                self._core_plugin.delete_port(context, port['id'],
                                              l3_port_check=False)
开发者ID:dlundquist,项目名称:neutron,代码行数:25,代码来源:l3_hamode_db.py

示例5: add_ha_port

    def add_ha_port(self, context, router_id, network_id, tenant_id):
        args = {'tenant_id': '',
                'network_id': network_id,
                'admin_state_up': True,
                'device_id': router_id,
                'device_owner': constants.DEVICE_OWNER_ROUTER_HA_INTF,
                'name': constants.HA_PORT_NAME % tenant_id}
        port = p_utils.create_port(self._core_plugin, context,
                                 {'port': args})

        try:
            return self._create_ha_port_binding(context, port['id'], router_id)
        except Exception:
            with excutils.save_and_reraise_exception():
                self._core_plugin.delete_port(context, port['id'],
                                              l3_port_check=False)
开发者ID:glove747,项目名称:liberty-neutron,代码行数:16,代码来源:l3_hamode_db.py

示例6: add_ha_port

    def add_ha_port(self, context, router_id, network_id, tenant_id):
        args = {
            "tenant_id": "",
            "network_id": network_id,
            "admin_state_up": True,
            "device_id": router_id,
            "device_owner": constants.DEVICE_OWNER_ROUTER_HA_INTF,
            "name": constants.HA_PORT_NAME % tenant_id,
        }
        port = p_utils.create_port(self._core_plugin, context, {"port": args})

        try:
            return self._create_ha_port_binding(context, port["id"], router_id)
        except Exception:
            with excutils.save_and_reraise_exception():
                self._core_plugin.delete_port(context, port["id"], l3_port_check=False)
开发者ID:tal-nino,项目名称:neutron,代码行数:16,代码来源:l3_hamode_db.py


注:本文中的neutron.plugins.common.utils.create_port函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。