def attach_interface(self, context, instance, image_meta, vif): self.vif_driver.plug(instance, vif) self.firewall_driver.setup_basic_filtering(instance, vif) profile = self.client.profiles.get(instance.name) interfaces = [] for key, val in profile.devices.items(): if key.startswith('eth'): interfaces.append(key) net_device = 'eth{}'.format(len(interfaces)) network_config = lxd_vif.get_config(vif) if 'bridge' in network_config: config_update = { net_device: { 'nictype': 'bridged', 'hwaddr': vif['address'], 'parent': network_config['bridge'], 'type': 'nic', } } else: config_update = { net_device: { 'nictype': 'p2p', 'hwaddr': vif['address'], 'type': 'nic', } } profile.devices.update(config_update) profile.save(wait=True)
def attach_interface(self, context, instance, image_meta, vif): self.vif_driver.plug(instance, vif) self.firewall_driver.setup_basic_filtering(instance, vif) profile = self.client.profiles.get(instance.name) network_config = lxd_vif.get_config(vif) # XXX(jamespage): Refactor into vif module so code is shared # across hotplug and instance creation. if 'bridge' in network_config: net_device = network_config['bridge'] config_update = { net_device: { 'nictype': 'bridged', 'hwaddr': vif['address'], 'parent': network_config['bridge'], 'type': 'nic', } } else: net_device = lxd_vif.get_vif_devname(vif) config_update = { net_device: { 'nictype': 'physical', 'hwaddr': vif['address'], 'parent': lxd_vif.get_vif_internal_devname(vif), 'type': 'nic', } } profile.devices.update(config_update) profile.save(wait=True)
def test_get_config_bridge(self): expected = {'bridge': 'br0', 'mac_address': 'ca:fe:de:ad:be:ef'} an_vif = network_model.VIF( id='0123456789abcdef', address='ca:fe:de:ad:be:ef', network=NETWORK, type='bridge', devname='tap-012-345-678', ovs_interfaceid='9abc-def-000') config = vif.get_config(an_vif) self.assertEqual(expected, config)
def test_get_config_tap(self): expected = {'mac_address': 'ca:fe:de:ad:be:ef'} an_vif = network_model.VIF( id='da5cc4bf-f16c-4807-a0b6-911c7c67c3f8', address='ca:fe:de:ad:be:ef', network=NETWORK, type='tap', devname='tapda5cc4bf-f1', ovs_interfaceid='7b6812a6-b044-4596-b3c5-43a8ec431638') config = vif.get_config(an_vif) self.assertEqual(expected, config)
def test_get_config_ovs_hybrid(self): self.CONF.firewall_driver = 'AnFirewallDriver' expected = { 'bridge': 'qbr0123456789a', 'mac_address': 'ca:fe:de:ad:be:ef'} an_vif = network_model.VIF( id='0123456789abcdef', address='ca:fe:de:ad:be:ef', network=NETWORK, type='ovs', devname='tap-012-345-678', ovs_interfaceid='9abc-def-000') config = vif.get_config(an_vif) self.assertEqual(expected, config)
def test_get_config_ovs_hybrid(self): self.CONF.firewall_driver = 'AnFirewallDriver' expected = { 'bridge': 'qbrda5cc4bf-f1', 'mac_address': 'ca:fe:de:ad:be:ef'} an_vif = network_model.VIF( id='da5cc4bf-f16c-4807-a0b6-911c7c67c3f8', address='ca:fe:de:ad:be:ef', network=NETWORK, type='ovs', devname='tapda5cc4bf-f1', ovs_interfaceid='7b6812a6-b044-4596-b3c5-43a8ec431638') config = vif.get_config(an_vif) self.assertEqual(expected, config)
def _network(instance, _, network_info, __): if not network_info: return devices = {} for vifaddr in network_info: cfg = vif.get_config(vifaddr) if 'bridge' in cfg: key = str(cfg['bridge']) devices[key] = { 'nictype': 'bridged', 'hwaddr': str(cfg['mac_address']), 'parent': str(cfg['bridge']), 'type': 'nic' } else: key = 'unbridged' devices[key] = { 'nictype': 'p2p', 'hwaddr': str(cfg['mac_address']), 'type': 'nic' } host_device = vif.get_vif_devname(vifaddr) if host_device: devices[key]['host_name'] = host_device specs = instance.flavor.extra_specs # Since LXD does not implement average NIC IO and number of burst # bytes, we take the max(vif_*_average, vif_*_peak) to set the peak # network IO and simply ignore the burst bytes. # Align values to MBit/s (8 * powers of 1000 in this case), having # in mind that the values are recieved in Kilobytes/s. vif_inbound_limit = max( int(specs.get('quota:vif_inbound_average', 0)), int(specs.get('quota:vif_inbound_peak', 0)), ) if vif_inbound_limit: devices[key]['limits.ingress'] = '{}Mbit'.format( vif_inbound_limit * units.k * 8 / units.M) vif_outbound_limit = max( int(specs.get('quota:vif_outbound_average', 0)), int(specs.get('quota:vif_outbound_peak', 0)), ) if vif_outbound_limit: devices[key]['limits.egress'] = '{}Mbit'.format( vif_outbound_limit * units.k * 8 / units.M) return devices
def _network(instance, _, network_info, __): if not network_info: return devices = {} for vifaddr in network_info: cfg = vif.get_config(vifaddr) devname = vif.get_vif_devname(vifaddr) key = devname devices[key] = { 'nictype': 'physical', 'hwaddr': str(cfg['mac_address']), 'parent': vif.get_vif_internal_devname(vifaddr), 'type': 'nic' } specs = instance.flavor.extra_specs # Since LXD does not implement average NIC IO and number of burst # bytes, we take the max(vif_*_average, vif_*_peak) to set the peak # network IO and simply ignore the burst bytes. # Align values to MBit/s (8 * powers of 1000 in this case), having # in mind that the values are recieved in Kilobytes/s. vif_inbound_limit = max( int(specs.get('quota:vif_inbound_average', 0)), int(specs.get('quota:vif_inbound_peak', 0)), ) if vif_inbound_limit: devices[key]['limits.ingress'] = '{}Mbit'.format( vif_inbound_limit * units.k * 8 // units.M) vif_outbound_limit = max( int(specs.get('quota:vif_outbound_average', 0)), int(specs.get('quota:vif_outbound_peak', 0)), ) if vif_outbound_limit: devices[key]['limits.egress'] = '{}Mbit'.format( vif_outbound_limit * units.k * 8 // units.M) return devices