def create_netinfo(ovs_info): addresses = getIpAddrs() routes = get_routes() _netinfo = {'networks': {}} for bridge, bridge_attrs in six.iteritems(ovs_info.bridges): ports = bridge_attrs['ports'] southbound = ovs_info.southbound_port(ports) # northbound ports represents networks stp = bridge_attrs['stp'] for northbound_port in ovs_info.northbound_ports(ports): _netinfo['networks'][northbound_port] = _get_network_info( northbound_port, bridge, southbound, ports, stp, addresses, routes, ) return _netinfo
def test_add_ipv4_address_with_gateway(self): ip = address.IPv4(address=IPV4_A_ADDRESS, netmask=IPV4_NETMASK, gateway=IPV4_GATEWAY, defaultRoute=True) with dummy_device() as nic: with preserve_default_route(): address.add(nic, ipv4=ip, ipv6=None) self.assertTrue(routes.is_default_route( IPV4_GATEWAY, routes.get_routes()))
def test_add_ipv6_gateway_given_existing_ipv4_and_ipv6_gateways( self, nic0, ipv4_address, ipv6_address): with preserve_default_route(): address.add(nic0, ipv4=ipv4_address, ipv6=None) address.add(nic0, ipv4=None, ipv6=ipv6_address) address.add(nic0, ipv4=None, ipv6=ipv6_address) assert routes.is_default_route(IPV4_GATEWAY, routes.get_routes()) assert routes.is_ipv6_default_route(IPV6_GATEWAY)
def test_add_ipv4_address_with_gateway(self): ip = address.IPv4(address=IPV4_A_ADDRESS, netmask=IPV4_NETMASK, gateway=IPV4_GATEWAY, defaultRoute=True) with dummy_device() as nic: with preserve_default_route(): address.add(nic, ipv4=ip, ipv6=None) self.assertTrue( routes.is_default_route(IPV4_GATEWAY, routes.get_routes()))
def bondings_caps(running_config): ovs_bonding_caps = {} routes = netinfo_routes.get_routes() for bonding, attrs in iter_ovs_bonds(running_config.bonds): options = parse_bond_options(attrs.get('options'), keep_custom=True) net_info = _get_net_info(bonding, routes) net_info['slaves'] = attrs.get('nics') net_info['active_slave'] = _get_active_slave(bonding) net_info['opts'] = options ovs_bonding_caps[bonding] = net_info return ovs_bonding_caps
def test_add_ipv4_and_ipv6_address_with_gateways(self): ipv4 = address.IPv4(address=IPV4_A_ADDRESS, netmask=IPV4_NETMASK, gateway=IPV4_GATEWAY, defaultRoute=True) ipv6 = address.IPv6(address=IPV6_A_WITH_PREFIXLEN, gateway=IPV6_GATEWAY, defaultRoute=True) with dummy_device() as nic: with preserve_default_route(): address.add(nic, ipv4=ipv4, ipv6=ipv6) addr, netmask, _, ipv6addresses = address.addrs_info(nic) self.assertTrue(routes.is_default_route( IPV4_GATEWAY, routes.get_routes())) self.assertTrue(routes.is_ipv6_default_route(IPV6_GATEWAY))
def vlans_caps(running_config): ovs_vlans_caps = {} routes = netinfo_routes.get_routes() for network, attrs in iter_ovs_nets(running_config.networks): vlan = attrs.get('vlan') if vlan is not None: net_info = _get_net_info(network, routes) iface = attrs.get('bonding') or attrs.get('nic') net_info['iface'] = iface net_info['bridged'] = attrs.get('bridged') net_info['vlanid'] = int(vlan) ovs_vlans_caps['%s.%s' % (iface, vlan)] = net_info return ovs_vlans_caps
def bridges_caps(running_config): ovs_bridges_caps = {} routes = netinfo_routes.get_routes() for network, attrs in iter_ovs_nets(running_config.networks): # report the network to be bridgeless if this is what Engine expects if attrs.get('bridged'): interface = network if 'vlan' in attrs else BRIDGE_NAME net_info = _get_net_info(interface, routes) net_info['bridged'] = True net_info['ports'] = _get_ports(network, attrs) # TODO netinfo._bridge_options does not work here net_info['opts'] = {} net_info['stp'] = _get_stp(interface) ovs_bridges_caps[network] = net_info return ovs_bridges_caps
def test_add_ipv4_and_ipv6_address_with_gateways(self): ipv4 = address.IPv4(address=IPV4_A_ADDRESS, netmask=IPV4_NETMASK, gateway=IPV4_GATEWAY, defaultRoute=True) ipv6 = address.IPv6(address=IPV6_A_WITH_PREFIXLEN, gateway=IPV6_GATEWAY, defaultRoute=True) with dummy_device() as nic: with preserve_default_route(): address.add(nic, ipv4=ipv4, ipv6=ipv6) addr, netmask, _, ipv6addresses = address.addrs_info(nic) self.assertTrue( routes.is_default_route(IPV4_GATEWAY, routes.get_routes())) self.assertTrue(routes.is_ipv6_default_route(IPV6_GATEWAY))
def preserve_default_route(): ipv4_dg_data = routes.getDefaultGateway() ipv4_gateway = ipv4_dg_data.via if ipv4_dg_data else None ipv4_device = ipv4_dg_data.device if ipv4_dg_data else None ipv6_dg_data = routes.ipv6_default_gateway() ipv6_gateway = ipv6_dg_data.via if ipv6_dg_data else None ipv6_device = ipv6_dg_data.device if ipv6_dg_data else None try: yield finally: if ipv4_gateway and not routes.is_default_route( ipv4_gateway, routes.get_routes()): address.set_default_route(ipv4_gateway, family=4, dev=ipv4_device) if ipv6_gateway and not routes.is_ipv6_default_route(ipv6_gateway): address.set_default_route(ipv6_gateway, family=6, dev=ipv6_device)
def create_netinfo(ovs_info): addresses = getIpAddrs() routes = get_routes() _netinfo = {'networks': {}} for bridge, bridge_attrs in six.iteritems(ovs_info.bridges): ports = bridge_attrs['ports'] southbound = ovs_info.southbound_port(ports) # northbound ports represents networks stp = bridge_attrs['stp'] for northbound_port in ovs_info.northbound_ports(ports): _netinfo['networks'][northbound_port] = _get_network_info( northbound_port, bridge, southbound, ports, stp, addresses, routes) return _netinfo
def networks_caps(running_config): def get_engine_expected_top_dev(net, attrs): """Return top device (iface) expected by Engine.""" nic_bond = attrs.get('bonding') or attrs.get('nic') vlan = attrs.get('vlan') return (net if attrs.get('bridged', True) else '%s.%s' % (nic_bond, vlan) if vlan is not None else nic_bond) ovs_networks_caps = {} routes = netinfo_routes.get_routes() for network, attrs in iter_ovs_nets(running_config.networks): actual_top_dev = network if 'vlan' in attrs else BRIDGE_NAME expected_top_dev = get_engine_expected_top_dev(network, attrs) net_info = _get_net_info(actual_top_dev, routes) net_info['iface'] = expected_top_dev # report the network to be bridgeless if this is what Engine expects net_info['bridged'] = attrs.get('bridged') net_info['ports'] = _get_ports(network, attrs) net_info['stp'] = _get_stp(actual_top_dev) ovs_networks_caps[network] = net_info return ovs_networks_caps
def test_add_ipv6_gateway_given_existing_ipv4_and_ipv6_gateways(self): ipv4 = address.IPv4( address=IPV4_A_ADDRESS, netmask=IPV4_NETMASK, gateway=IPV4_GATEWAY, defaultRoute=True, ) ipv6 = address.IPv6( address=IPV6_A_WITH_PREFIXLEN, gateway=IPV6_GATEWAY, defaultRoute=True, ) with dummy_device() as nic: with preserve_default_route(): address.add(nic, ipv4=ipv4, ipv6=None) address.add(nic, ipv4=None, ipv6=ipv6) address.add(nic, ipv4=None, ipv6=ipv6) self.assertTrue( routes.is_default_route(IPV4_GATEWAY, routes.get_routes())) self.assertTrue(routes.is_ipv6_default_route(IPV6_GATEWAY))
def _analyze_netinfo_nets(self, netinfo): _routes = routes.get_routes() for net, net_attr in six.viewitems(netinfo.networks): attrs = _translate_netinfo_net(net, net_attr, netinfo, _routes) yield net, attrs
def test_add_ipv4_and_ipv6_address_with_gateways(self, nic0, ipv4_address, ipv6_address): with preserve_default_route(): address.add(nic0, ipv4=ipv4_address, ipv6=ipv6_address) assert routes.is_default_route(IPV4_GATEWAY, routes.get_routes()) assert routes.is_ipv6_default_route(IPV6_GATEWAY)