def spawn_monitored_metadata_proxy(cls, monitor, ns_name, port, conf, bind_address="0.0.0.0", network_id=None, router_id=None, bind_address_v6=None, bind_interface=None): uuid = network_id or router_id callback = cls._get_metadata_proxy_callback( bind_address, port, conf, network_id=network_id, router_id=router_id, bind_address_v6=bind_address_v6, bind_interface=bind_interface) pm = cls._get_metadata_proxy_process_manager(uuid, conf, ns_name=ns_name, callback=callback) if bind_interface is not None and bind_address_v6 is not None: # HAProxy cannot bind() until IPv6 Duplicate Address Detection # completes. We must wait until the address leaves its 'tentative' # state. ip_lib.IpAddrCommand( parent=ip_lib.IPDevice(name=bind_interface, namespace=ns_name) ).wait_until_address_ready(address=bind_address_v6) pm.enable() monitor.register(uuid, METADATA_SERVICE_NAME, pm) cls.monitors[router_id] = pm
def _setup_interface_ip(self, ip, interface='lo'): """Sets up an IP address on the target interface Args: ip(String): ip address with cidr interface(String): network interface, 'lo' by default Return: None """ dev = ip_lib.IPDevice(interface) dev.addr = ip_lib.IpAddrCommand(dev) existing_addreses = ip_lib.get_devices_with_ip(None, name=dev.name) existing_ips = [addr['cidr'] for addr in existing_addreses] if ip not in existing_ips: LOG.info("Adding %s to %s interface" % (ip, dev.name)) dev.addr.add(cidr=ip) else: LOG.debug("%s interface already have %s ip" % (dev.name, ip))
def setUp(self): super(TestIpAddrCommand, self).setUp() self.parent.name = 'tap0' self.command = 'addr' self.addr_cmd = ip_lib.IpAddrCommand(self.parent)