def _get(vdsmnets=None): """ Generate a networking report for all devices. In case vdsmnets is provided, it is used in the report instead of retrieving data from the running config. :return: Dict of networking devices with all their details. """ ipaddrs = getIpAddrs() routes = get_routes() devices_info = _devices_report(ipaddrs, routes) nets_info = _networks_report(vdsmnets, routes, ipaddrs, devices_info) add_qos_info_to_devices(nets_info, devices_info) flat_devs_info = _get_flat_devs_info(devices_info) devices = _get_dev_names(nets_info, flat_devs_info) extra_info = _create_default_extra_info(devices) current_state = nmstate.get_current_state() extra_info.update( _get_devices_info_from_nmstate( current_state.filtered_interfaces(devices))) _update_caps_info(nets_info, flat_devs_info, extra_info) networking_report = {'networks': nets_info} networking_report.update(devices_info) networking_report['nameservers'] = current_state.dns_state networking_report['supportsIPv6'] = ipv6_supported() return networking_report
def test_remove_net_with_static_source_route(self, bridged, current_state_mock): running_network = create_network_config( 'nic', IFACE0, bridged, static_ip_configuration=create_static_ip_configuration( IPv4_ADDRESS1, IPv4_NETMASK1, ipv6_address=None, ipv6_prefix_length=None, ), gateway=IPv4_GATEWAY1, ) routes_state, rules_state = create_source_routes_and_rules_state( TESTNET1 if bridged else IFACE0, IPv4_ADDRESS1, IPv4_NETMASK1, IPv4_GATEWAY1, ) _mock_routes_and_rules(current_state_mock, routes_state, rules_state) source_routes = route.SourceRoutes( NetworkConfig(TESTNET1, {'remove': True}), NetworkConfig(TESTNET1, running_network), nmstate.get_current_state(), ) _add_absent_to_state(routes_state, nmstate.Route) _add_absent_to_state(rules_state, nmstate.RouteRule) assert routes_state == source_routes.routes_state assert rules_state == source_routes.rules_state
def netinfo(vdsmnets=None, compatibility=None): # TODO: Version requests by engine to ease handling of compatibility. running_config = RunningConfig() _netinfo = netinfo_get(vdsmnets, compatibility) ovs_nets, _ = util.split_switch_type( running_config.networks, running_config={} ) ovs_bonds = util.split_switch_type(running_config.bonds, running_config={}) if ovs_nets or ovs_bonds: state = nmstate.get_current_state() nmstate.ovs_netinfo(_netinfo, running_config.networks, state) _set_bond_type_by_usage(_netinfo, running_config.bonds) return _netinfo
def test_switch_from_dynamic_to_static(self, bridged, current_state_mock): running_network = create_network_config( 'nic', IFACE0, bridged, dynamic_ip_configuration=create_dynamic_ip_configuration( dhcpv4=True, dhcpv6=False, ipv6autoconf=False), ) routes_state, rules_state = create_source_routes_and_rules_state( TESTNET1 if bridged else IFACE0, IPv4_ADDRESS2, IPv4_NETMASK2, IPv4_GATEWAY2, ) _mock_routes_and_rules(current_state_mock, routes_state, rules_state) network = create_network_config( 'nic', IFACE0, bridged, static_ip_configuration=create_static_ip_configuration( IPv4_ADDRESS1, IPv4_NETMASK1, ipv6_address=None, ipv6_prefix_length=None, ), gateway=IPv4_GATEWAY1, ) source_routes = route.SourceRoutes( NetworkConfig(TESTNET1, network), NetworkConfig(TESTNET1, running_network), nmstate.get_current_state(), ) _add_absent_to_state(routes_state, nmstate.Route) _add_absent_to_state(rules_state, nmstate.RouteRule) new_routes, new_rules = create_source_routes_and_rules_state( TESTNET1 if bridged else IFACE0, IPv4_ADDRESS1, IPv4_NETMASK1, IPv4_GATEWAY1, ) routes_state.extend(new_routes) rules_state.extend(new_rules) assert routes_state == source_routes.routes_state assert rules_state == source_routes.rules_state
def test_add_gateway(self, bridged, current_state_mock): running_network = create_network_config( 'nic', IFACE0, bridged, static_ip_configuration=create_static_ip_configuration( IPv4_ADDRESS1, IPv4_NETMASK1, ipv6_address=None, ipv6_prefix_length=None, ), ) network = create_network_config( 'nic', IFACE0, bridged, static_ip_configuration=create_static_ip_configuration( IPv4_ADDRESS1, IPv4_NETMASK1, ipv6_address=None, ipv6_prefix_length=None, ), gateway=IPv4_GATEWAY1, ) source_routes = route.SourceRoutes( NetworkConfig(TESTNET1, network), NetworkConfig(TESTNET1, running_network), nmstate.get_current_state(), ) routes_state, rules_state = create_source_routes_and_rules_state( TESTNET1 if bridged else IFACE0, IPv4_ADDRESS1, IPv4_NETMASK1, IPv4_GATEWAY1, ) assert routes_state == source_routes.routes_state assert rules_state == source_routes.rules_state