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_vif_devname_devname_nonexistent(self): an_vif = { 'id': 'da5cc4bf-f16c-4807-a0b6-911c7c67c3f8', } devname = vif.get_vif_devname(an_vif) self.assertEqual('nicda5cc4bf-f1', devname)
def test_get_vif_devname_devname_nonexistent(self): an_vif = { 'id': '0123456789abcdef', } devname = vif.get_vif_devname(an_vif) self.assertEqual('nic0123456789a', devname)
def test_get_vif_devname_devname_exists(self): an_vif = { 'id': 'da5cc4bf-f16c-4807-a0b6-911c7c67c3f8', 'devname': 'oth1', } devname = vif.get_vif_devname(an_vif) self.assertEqual('oth1', devname)
def test_get_vif_devname_devname_exists(self): an_vif = { 'id': '0123456789abcdef', 'devname': 'oth1', } devname = vif.get_vif_devname(an_vif) self.assertEqual('oth1', devname)
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 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) 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 detach_interface(self, context, instance, vif): profile = self.client.profiles.get(instance.name) devname = lxd_vif.get_vif_devname(vif) # NOTE(jamespage): Attempt to remove device using # new style tap naming if devname in profile.devices: del profile.devices[devname] profile.save(wait=True) else: # NOTE(jamespage): For upgrades, scan devices # and attempt to identify # using mac address as the # device will *not* have a # consistent name for key, val in profile.devices.items(): if val.get('hwaddr') == vif['address']: del profile.devices[key] profile.save(wait=True) break self.vif_driver.unplug(instance, vif)
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