def plug(self, instance_id, hyper_vif): LOG.debug("hyper_vif=%s" % hyper_vif) vnic_veth = self.create_br_vnic(instance_id, hyper_vif) for subnet in hyper_vif['network']['subnets']: LOG.debug("subnet: %s" % subnet) if subnet['version'] == 4: # set the IP/mac on the vnic h_cidr = subnet['cidr'] h_ip = subnet['ips'][0]['address'] h_cidr_ip = h_ip + '/' + h_cidr.split('/')[1] hu.set_mac_ip(vnic_veth, hyper_vif['address'], h_cidr_ip) # remove default route hu.execute('ip', 'route', 'del', '0/0', check_exit_code=False, run_as_root=True) # set the default route if defined h_gw = None if subnet.get('gateway'): h_gw = subnet['gateway'].get('address') if h_gw: hu.execute('ip', 'route', 'add', 'default', 'via', h_gw, run_as_root=True) # set MTU hu.set_device_mtu(vnic_veth, True)
def plug(self, instance_id, hyper_vif): LOG.debug("hyper_vif=%s" % hyper_vif) vnic_veth = self.create_br_vnic(instance_id, hyper_vif) if cfg.CONF.hyperagent.ip_tables: tap1 = "lvo%s" % vnic_veth[3:] tap2 = "lvb%s" % vnic_veth[3:] br = "obr%s" % vnic_veth[3:] if not hu.device_exists(tap1): hu.create_veth_pair(tap1, tap2) hu.create_linux_bridge(br, [vnic_veth, tap1]) vnic_veth = tap2 # set MTU hu.set_device_mtu(br, True) hu.set_device_mtu(tap1, True) # set mac address on device hu.execute('ip', 'link', 'set', vnic_veth, 'address', hyper_vif['address'], run_as_root=True) # set MTU hu.set_device_mtu(vnic_veth, True) container_nic_name = self._container_device_name(hyper_vif) eth_vif_config = { 'devices': { container_nic_name: { 'type': 'nic', 'nictype': 'physical', 'parent': vnic_veth } } } self.lxd.container_update(self.container_name, eth_vif_config)
def _execute(self, *cmd, **kwargs): if API.run_as_root: kwargs['run_as_root'] = True return hu.execute(*cmd, **kwargs)
} if lxd.container_defined(container): print ('container %s is defined' % container) else: print ('container %s is not defined' % container) if lxd.container_running(container): print ('container %s is running' % container) else: print ('container %s is not running' % container) lxd.container_init(container_config) if lxd.container_defined(container): print ('container %s is defined' % container) else: print ('container %s is not defined' % container) print('container initialized') hu.execute('ip', 'link', 'add', 'vvv1', 'type', 'veth', 'peer', 'name', 'vvv2', check_exit_code=False) for dev in ['vvv1', 'vvv2']: hu.execute('ip', 'link', 'set', dev, 'up') eth_vif_config = { 'devices': { 'eth0': { 'type': 'nic', 'nictype': 'physical', 'parent': 'vvv2' } } } lxd.container_update(container, eth_vif_config) print('container updated')