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

Python utils.get_random_mac函数代码示例

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

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



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

示例1: test_set_port_mac

 def test_set_port_mac(self):
     attr = self.generate_device_details()
     self.manage_device(attr)
     plumber = trunk_plumber.Plumber(namespace=attr.namespace)
     # force it to return name of above
     plumber._get_tap_device_name = lambda x: attr.name
     new_mac = utils.get_random_mac('fa:16:3e:00:00:00'.split(':'))
     self.assertTrue(plumber.set_port_mac('port_id', new_mac))
     self.assertFalse(plumber.set_port_mac('port_id', new_mac))
     new_mac = utils.get_random_mac('fa:16:3e:00:00:00'.split(':'))
     self.assertTrue(plumber.set_port_mac('port_id', new_mac))
     self.assertFalse(plumber.set_port_mac('port_id', new_mac))
开发者ID:sebrandon1,项目名称:neutron,代码行数:12,代码来源:test_l2_lb_agent.py


示例2: _create_dvr_mac_address

 def _create_dvr_mac_address(self, context, host):
     """Create DVR mac address for a given host."""
     base_mac = cfg.CONF.dvr_base_mac.split(':')
     max_retries = cfg.CONF.mac_generation_retries
     for attempt in reversed(range(max_retries)):
         try:
             with context.session.begin(subtransactions=True):
                 mac_address = utils.get_random_mac(base_mac)
                 dvr_mac_binding = DistributedVirtualRouterMacAddress(
                     host=host, mac_address=mac_address)
                 context.session.add(dvr_mac_binding)
                 LOG.debug("Generated DVR mac for host %(host)s "
                           "is %(mac_address)s",
                           {'host': host, 'mac_address': mac_address})
             dvr_macs = self.get_dvr_mac_address_list(context)
             # TODO(vivek): improve scalability of this fanout by
             # sending a single mac address rather than the entire set
             self.notifier.dvr_mac_address_update(context, dvr_macs)
             return self._make_dvr_mac_address_dict(dvr_mac_binding)
         except db_exc.DBDuplicateEntry:
             LOG.debug("Generated DVR mac %(mac)s exists."
                       " Remaining attempts %(attempts_left)s.",
                       {'mac': mac_address, 'attempts_left': attempt})
     LOG.error(_LE("MAC generation error after %s attempts"), max_retries)
     raise ext_dvr.MacAddressGenerationFailure(host=host)
开发者ID:CloudA,项目名称:neutron,代码行数:25,代码来源:dvr_mac_db.py


示例3: generate_device_details

 def generate_device_details(self, name=None, ip_cidrs=None,
                             mac_address=None, namespace=None):
     return Device(name or base.get_rand_name(),
                   ip_cidrs or ["%s/24" % TEST_IP],
                   mac_address or
                   utils.get_random_mac('fa:16:3e:00:00:00'.split(':')),
                   namespace or base.get_rand_name())
开发者ID:kodarkI,项目名称:neutron,代码行数:7,代码来源:test_ip_lib.py


示例4: generate_device_details

 def generate_device_details(self, name=None, ip_cidr=None,
                             mac_address=None, namespace=None):
     return Device(name or base.get_rand_name(),
                   ip_cidr or '240.0.0.1/24',
                   mac_address or
                   utils.get_random_mac('fa:16:3e:00:00:00'.split(':')),
                   namespace or base.get_rand_name())
开发者ID:afori,项目名称:neutron,代码行数:7,代码来源:test_ip_lib.py


示例5: test_plug_with_namespace_sets_mtu_higher_than_bridge

    def test_plug_with_namespace_sets_mtu_higher_than_bridge(self):
        device_mtu = 1450

        # Create a new OVS bridge
        ovs_bridge = self.useFixture(net_helpers.OVSBridgeFixture()).bridge
        self.assertFalse(ovs_bridge.get_port_name_list())

        # Add a new linuxbridge port with reduced MTU to OVS bridge
        lb_bridge = self.useFixture(
            net_helpers.LinuxBridgeFixture()).bridge
        lb_bridge_port = self.useFixture(
            net_helpers.LinuxBridgePortFixture(lb_bridge))
        lb_bridge_port.port.link.set_mtu(device_mtu - 1)
        ovs_bridge.add_port(lb_bridge_port.port.name)

        # Now plug a device with intended MTU that is higher than for the port
        # above and validate that its MTU is not reduced to the least MTU on
        # the bridge
        device_name = utils.get_rand_name()
        mac_address = utils.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        namespace = self.useFixture(net_helpers.NamespaceFixture()).name
        self.interface.plug(network_id=uuidutils.generate_uuid(),
                            port_id=uuidutils.generate_uuid(),
                            device_name=device_name,
                            mac_address=mac_address,
                            bridge=ovs_bridge.br_name,
                            namespace=namespace,
                            mtu=device_mtu)

        self.assertIn(device_name, ovs_bridge.get_port_name_list())
        self.assertTrue(ip_lib.device_exists(device_name, namespace))
        self.assertEqual(
            device_mtu,
            ip_lib.IPDevice(device_name, namespace=namespace).link.mtu
        )
开发者ID:sebrandon1,项目名称:neutron,代码行数:35,代码来源:test_interface.py


示例6: setUp

    def setUp(self):
        super(TestTaasPlugin, self).setUp()
        mock.patch.object(n_rpc, 'create_connection', auto_spec=True).start()
        mock.patch.object(taas_plugin, 'TaasCallbacks', auto_spec=True).start()
        mock.patch.object(taas_plugin, 'TaasAgentApi', auto_spec=True).start()
        self._plugin = taas_plugin.TaasPlugin()
        self._context = context.get_admin_context()

        self._tenant_id = 'tenant-X'
        self._network_id = uuidutils.generate_uuid()
        self._host_id = 'host-A'
        self._port_id = uuidutils.generate_uuid()
        self._port_details = {
            'tenant_id': self._tenant_id,
            'binding:host_id': self._host_id,
            'mac_address': n_utils.get_random_mac(
                'fa:16:3e:00:00:00'.split(':')),
        }
        self._tap_service = {
            'tenant_id': self._tenant_id,
            'name': 'MyTap',
            'description': 'This is my tap service',
            'port_id': self._port_id,
            'network_id': self._network_id,
        }
        self._tap_flow = {
            'description': 'This is my tap flow',
            'direction': 'BOTH',
            'name': 'MyTapFlow',
            'source_port': self._port_id,
            'tenant_id': self._tenant_id,
        }
开发者ID:svnyyad,项目名称:tap-as-a-service,代码行数:32,代码来源:test_taas_plugin.py


示例7: generate_router_info

 def generate_router_info(self):
     self.info = copy.deepcopy(FAKE_ROUTER)
     self.info["id"] = _uuid()
     self.info["_interfaces"] = [self._generate_private_interface_for_router(subnet) for subnet in self.private_nets]
     self.info["gw_port"]["id"] = _uuid()
     self.info["gw_port"]["fixed_ips"][0]["ip_address"] = str(self.public_net)
     self.info["gw_port"]["mac_address"] = common_utils.get_random_mac(MAC_BASE)
     self.info["ha"] = False
开发者ID:wywangsh,项目名称:neutron-vpnaas,代码行数:8,代码来源:test_scenario.py


示例8: setUp

 def setUp(self):
     super(TrunkParentPortTestCase, self).setUp()
     # Mock out connecting to ovsdb
     mock.patch(NATIVE_OVSDB_CONNECTION).start()
     trunk_id = uuidutils.generate_uuid()
     port_id = uuidutils.generate_uuid()
     trunk_mac = common_utils.get_random_mac('fa:16:3e:00:00:00'.split(':'))
     self.trunk = trunk_manager.TrunkParentPort(
         trunk_id, port_id, trunk_mac)
开发者ID:gotostack,项目名称:neutron,代码行数:9,代码来源:test_trunk_manager.py


示例9: _create_test_port_dict

 def _create_test_port_dict(self):
     return {'id': uuidutils.generate_uuid(),
             'mac_address': utils.get_random_mac(
                 'fa:16:3e:00:00:00'.split(':')),
             'fixed_ips': [{
                 'ip_address': '10.%d.%d.%d' % (
                      random.randint(3, 254),
                      random.randint(3, 254),
                      random.randint(3, 254))}],
             'vif_name': base.get_rand_name(
                 self.driver.DEV_NAME_LEN, self.driver.DEV_NAME_PREFIX)}
开发者ID:dhanunjaya,项目名称:neutron,代码行数:11,代码来源:base.py


示例10: generate_router_info

 def generate_router_info(self):
     self.info = copy.deepcopy(FAKE_ROUTER)
     self.info['id'] = _uuid()
     self.info['_interfaces'] = [
         self._generate_private_interface_for_router(subnet)
         for subnet in self.private_nets]
     self.info['gw_port']['id'] = _uuid()
     self.info['gw_port']['fixed_ips'][0]['ip_address'] = str(
         self.public_net)
     self.info['gw_port']['mac_address'] = (
         common_utils.get_random_mac(MAC_BASE))
     self.info['ha'] = False
开发者ID:leftyLin,项目名称:neutron-vpnaas,代码行数:12,代码来源:test_scenario.py


示例11: _generate_info

 def _generate_info(self, public_ip, private_cidr, enable_ha=False):
     """Generate router info"""
     info = copy.deepcopy(FAKE_ROUTER)
     info['id'] = _uuid()
     info['_interfaces'][0]['id'] = _uuid()
     (info['_interfaces'][0]
      ['mac_address']) = common_utils.get_random_mac(MAC_BASE)
     (info['_interfaces'][0]['fixed_ips'][0]
      ['ip_address']) = str(private_cidr[4])
     info['_interfaces'][0]['subnets'][0].update({
         'cidr': str(private_cidr),
         'gateway_ip': str(private_cidr[1])})
     info['gw_port']['id'] = _uuid()
     info['gw_port']['fixed_ips'][0]['ip_address'] = str(public_ip)
     info['gw_port']['mac_address'] = common_utils.get_random_mac(MAC_BASE)
     if enable_ha:
         info['ha'] = True
         info['ha_vr_id'] = 1
         info[l3_constants.HA_INTERFACE_KEY] = (
             l3_test_common.get_ha_interface())
     else:
         info['ha'] = False
     return info
开发者ID:armando-migliaccio,项目名称:neutron-vpnaas,代码行数:23,代码来源:test_scenario.py


示例12: _create_dvr_mac_address_retry

 def _create_dvr_mac_address_retry(self, context, host, base_mac):
     with context.session.begin(subtransactions=True):
         mac_address = utils.get_random_mac(base_mac)
         dvr_mac_binding = dvr_models.DistributedVirtualRouterMacAddress(
             host=host, mac_address=mac_address)
         context.session.add(dvr_mac_binding)
         LOG.debug("Generated DVR mac for host %(host)s "
                   "is %(mac_address)s",
                   {'host': host, 'mac_address': mac_address})
     dvr_macs = self.get_dvr_mac_address_list(context)
     # TODO(vivek): improve scalability of this fanout by
     # sending a single mac address rather than the entire set
     self.notifier.dvr_mac_address_update(context, dvr_macs)
     return self._make_dvr_mac_address_dict(dvr_mac_binding)
开发者ID:cloudbase,项目名称:neutron,代码行数:14,代码来源:dvr_mac_db.py


示例13: test_arp_correct_protection_allowed_address_pairs

 def test_arp_correct_protection_allowed_address_pairs(self):
     smac = self.source.port.link.address
     port = {'mac_address': '00:11:22:33:44:55',
             'allowed_address_pairs': [{'mac_address': smac,
                                        'ip_address': self.source.ip}]}
     # make sure a large number of allowed address pairs works
     for i in range(100000):
         port['allowed_address_pairs'].append(
             {'mac_address': utils.get_random_mac(
                  'fa:16:3e:00:00:00'.split(':')),
              'ip_address': '10.10.10.10'})
     self._add_arp_protection(self.source, ['1.2.2.2'], port)
     self._add_arp_protection(self.destination, [self.destination.ip])
     arping(self.source.namespace, self.destination.ip)
     arping(self.destination.namespace, self.source.ip)
开发者ID:21atlas,项目名称:neutron,代码行数:15,代码来源:test_linuxbridge_arp_protect.py


示例14: test_arp_correct_protection_allowed_address_pairs

 def test_arp_correct_protection_allowed_address_pairs(self):
     smac = self.source.port.link.address
     port = {
         "mac_address": "00:11:22:33:44:55",
         "allowed_address_pairs": [{"mac_address": smac, "ip_address": self.source.ip}],
     }
     # make sure a large number of allowed address pairs works
     for i in range(100000):
         port["allowed_address_pairs"].append(
             {"mac_address": utils.get_random_mac("fa:16:3e:00:00:00".split(":")), "ip_address": "10.10.10.10"}
         )
     self._add_arp_protection(self.source, ["1.2.2.2"], port)
     self._add_arp_protection(self.destination, [self.destination.ip])
     arping(self.source.namespace, self.destination.ip)
     arping(self.destination.namespace, self.source.ip)
开发者ID:klmitch,项目名称:neutron,代码行数:15,代码来源:test_linuxbridge_arp_protect.py


示例15: _generate_private_interface_for_router

 def _generate_private_interface_for_router(self, subnet):
     subnet_id = _uuid()
     return {
         "id": _uuid(),
         "admin_state_up": True,
         "network_id": _uuid(),
         "mac_address": common_utils.get_random_mac(MAC_BASE),
         "subnets": [
             {
                 "ipv6_ra_mode": None,
                 "cidr": str(subnet),
                 "gateway_ip": str(subnet[1]),
                 "id": subnet_id,
                 "ipv6_address_mode": None,
             }
         ],
         "fixed_ips": [{"subnet_id": subnet_id, "prefixlen": 24, "ip_address": str(subnet[4])}],
     }
开发者ID:wywangsh,项目名称:neutron-vpnaas,代码行数:18,代码来源:test_scenario.py


示例16: _get_ovn_dhcpv4_opts

    def _get_ovn_dhcpv4_opts(self, subnet, network, server_mac=None):
        if not subnet['gateway_ip']:
            return {}

        default_lease_time = str(config.get_ovn_dhcp_default_lease_time())
        mtu = network['mtu']
        options = {
            'server_id': subnet['gateway_ip'],
            'lease_time': default_lease_time,
            'mtu': str(mtu),
            'router': subnet['gateway_ip']
        }

        if server_mac:
            options['server_mac'] = server_mac
        else:
            options['server_mac'] = n_utils.get_random_mac(
                cfg.CONF.base_mac.split(':'))

        if subnet['dns_nameservers']:
            dns_servers = '{'
            for dns in subnet["dns_nameservers"]:
                dns_servers += dns + ', '
            dns_servers = dns_servers.strip(', ')
            dns_servers += '}'
            options['dns_server'] = dns_servers

        # If subnet hostroutes are defined, add them in the
        # 'classless_static_route' dhcp option
        classless_static_routes = "{"
        for route in subnet['host_routes']:
            classless_static_routes += ("%s,%s, ") % (
                route['destination'], route['nexthop'])

        if classless_static_routes != "{":
            # if there are static routes, then we need to add the
            # default route in this option. As per RFC 3442 dhcp clients
            # should ignore 'router' dhcp option (option 3)
            # if option 121 is present.
            classless_static_routes += "0.0.0.0/0,%s}" % (subnet['gateway_ip'])
            options['classless_static_route'] = classless_static_routes

        return options
开发者ID:doonhammer,项目名称:networking-ovn,代码行数:43,代码来源:mech_driver.py


示例17: _create_dvr_mac_for_extern_ip

 def _create_dvr_mac_for_extern_ip(self, context, host):
     """Create dvr mac address for a extern net ip."""
     base_mac = cfg.CONF.dvr_base_mac.split(':')
     max_retries = cfg.CONF.mac_generation_retries
     for attempt in reversed(range(max_retries)):
         try:
             with context.session.begin(subtransactions=True):
                 mac_address = utils.get_random_mac(base_mac)
                 dvr_mac_binding = DistributedVirtualRouterMacAddress(
                     host=host, mac_address=mac_address)
                 context.session.add(dvr_mac_binding)
                 LOG.debug("Generated dvr mac for host %(host)s "
                           "is %(mac_address)s",
                           {'host': host, 'mac_address': mac_address})
             return self._make_dvr_mac_address_dict(dvr_mac_binding)
         except db_exc.DBDuplicateEntry:
             LOG.debug("Generated dvr mac %(mac)s exists."
                       " Remaining attempts %(attempts_left)s.",
                       {'mac': mac_address, 'attempts_left': attempt})
     LOG.error(_("MAC generation error after %s attempts"), max_retries)
     raise ext_dvr.MacAddressGenerationFailure(host=host)
开发者ID:joey5678,项目名称:tricircle,代码行数:21,代码来源:dvr_mac_db.py


示例18: _get_ovn_dhcpv4_opts

    def _get_ovn_dhcpv4_opts(self, subnet, network):
        if not subnet["gateway_ip"]:
            return {}

        default_lease_time = str(config.get_ovn_dhcp_default_lease_time())
        mtu = network["mtu"]
        options = {
            "server_id": subnet["gateway_ip"],
            "server_mac": n_utils.get_random_mac(cfg.CONF.base_mac.split(":")),
            "lease_time": default_lease_time,
            "mtu": str(mtu),
            "router": subnet["gateway_ip"],
        }

        if subnet["dns_nameservers"]:
            dns_servers = "{"
            for dns in subnet["dns_nameservers"]:
                dns_servers += dns + ", "
            dns_servers = dns_servers.strip(", ")
            dns_servers += "}"
            options["dns_server"] = dns_servers

        # If subnet hostroutes are defined, add them in the
        # 'classless_static_route' dhcp option
        classless_static_routes = "{"
        for route in subnet["host_routes"]:
            classless_static_routes += ("%s,%s, ") % (route["destination"], route["nexthop"])

        if classless_static_routes != "{":
            # if there are static routes, then we need to add the
            # default route in this option. As per RFC 3442 dhcp clients
            # should ignore 'router' dhcp option (option 3)
            # if option 121 is present.
            classless_static_routes += "0.0.0.0/0,%s}" % (subnet["gateway_ip"])
            options["classless_static_route"] = classless_static_routes

        return options
开发者ID:hzhou8,项目名称:networking-ovn,代码行数:37,代码来源:mech_driver.py


示例19: _generate_private_interface_for_router

 def _generate_private_interface_for_router(self, subnet):
     subnet_id = _uuid()
     return {
         'id': _uuid(),
         'admin_state_up': True,
         'network_id': _uuid(),
         'mac_address': common_utils.get_random_mac(MAC_BASE),
         'subnets': [
             {
                 'ipv6_ra_mode': None,
                 'cidr': str(subnet),
                 'gateway_ip': str(subnet[1]),
                 'id': subnet_id,
                 'ipv6_address_mode': None
             }
         ],
         'fixed_ips': [
             {
                 'subnet_id': subnet_id,
                 'prefixlen': 24,
                 'ip_address': str(subnet[4])
             }
         ]
     }
开发者ID:leftyLin,项目名称:neutron-vpnaas,代码行数:24,代码来源:test_scenario.py


示例20: _setup_port_binding

    def _setup_port_binding(self, **kwargs):
        with self.ctx.session.begin(subtransactions=True):
            mac = utils.get_random_mac('fa:16:3e:00:00:00'.split(':'))
            port_id = uuidutils.generate_uuid()
            network_id = kwargs.get('network_id', TEST_NETWORK_ID)
            device_owner = kwargs.get('device_owner', '')
            device_id = kwargs.get('device_id', '')
            host = kwargs.get('host', helpers.HOST)

            self.ctx.session.add(models_v2.Port(
                id=port_id, network_id=network_id, mac_address=mac,
                admin_state_up=True, status=constants.PORT_STATUS_ACTIVE,
                device_id=device_id, device_owner=device_owner))

            port_binding_cls = models.PortBinding
            binding_kwarg = {'port_id': port_id,
                             'host': host,
                             'vif_type': portbindings.VIF_TYPE_UNBOUND,
                             'vnic_type': portbindings.VNIC_NORMAL}

            if device_owner == constants.DEVICE_OWNER_DVR_INTERFACE:
                port_binding_cls = models.DistributedPortBinding
                binding_kwarg['router_id'] = TEST_ROUTER_ID
                binding_kwarg['status'] = constants.PORT_STATUS_DOWN

            self.ctx.session.add(port_binding_cls(**binding_kwarg))

            if network_id == TEST_HA_NETWORK_ID:
                agent = self.get_l3_agent_by_host(host)
                haport_bindings_cls = l3ha_model.L3HARouterAgentPortBinding
                habinding_kwarg = {'port_id': port_id,
                                   'router_id': device_id,
                                   'l3_agent_id': agent['id'],
                                   'state': kwargs.get('host_state',
                                       n_const.HA_ROUTER_STATE_ACTIVE)}
                self.ctx.session.add(haport_bindings_cls(**habinding_kwarg))
开发者ID:sebrandon1,项目名称:neutron,代码行数:36,代码来源:test_db.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python utils.get_random_string函数代码示例发布时间:2022-05-27
下一篇:
Python utils.get_rand_name函数代码示例发布时间: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