def get_network_config_from_conf(config, use_system_devices=True, configure=False, osfamily=None): nicConfigurator = NicConfigurator(config.nics, use_system_devices) nics_cfg_list = nicConfigurator.generate(configure, osfamily) return get_network_config(nics_cfg_list, config.name_servers, config.dns_suffixes)
def get_network_config_from_conf(config, use_system_devices=True, configure=False, osfamily=None): nicConfigurator = NicConfigurator(config.nics, use_system_devices) nics_cfg_list = nicConfigurator.generate(configure, osfamily) return get_network_config(nics_cfg_list, config.name_servers, config.dns_suffixes)
def test_get_nics_list_dhcp(self): """Tests if NicConfigurator properly calculates network subnets for a configuration with a list of DHCP NICs""" cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg") config = Config(cf) nicConfigurator = NicConfigurator(config.nics, False) nics_cfg_list = nicConfigurator.generate() self.assertEqual(2, len(nics_cfg_list), "number of config elements") nic1 = {'name': 'NIC1'} nic2 = {'name': 'NIC2'} for cfg in nics_cfg_list: if cfg.get('name') == nic1.get('name'): nic1.update(cfg) elif cfg.get('name') == nic2.get('name'): nic2.update(cfg) self.assertEqual('physical', nic1.get('type'), 'type of NIC1') self.assertEqual('NIC1', nic1.get('name'), 'name of NIC1') self.assertEqual('00:50:56:a6:8c:08', nic1.get('mac_address'), 'mac address of NIC1') subnets = nic1.get('subnets') self.assertEqual(1, len(subnets), 'number of subnets for NIC1') subnet = subnets[0] self.assertEqual('dhcp', subnet.get('type'), 'DHCP type for NIC1') self.assertEqual('auto', subnet.get('control'), 'NIC1 Control type') self.assertEqual('physical', nic2.get('type'), 'type of NIC2') self.assertEqual('NIC2', nic2.get('name'), 'name of NIC2') self.assertEqual('00:50:56:a6:5a:de', nic2.get('mac_address'), 'mac address of NIC2') subnets = nic2.get('subnets') self.assertEqual(1, len(subnets), 'number of subnets for NIC2') subnet = subnets[0] self.assertEqual('dhcp', subnet.get('type'), 'DHCP type for NIC2') self.assertEqual('auto', subnet.get('control'), 'NIC2 Control type')
def test_get_nics_list_dhcp(self): """Tests if NicConfigurator properly calculates network subnets for a configuration with a list of DHCP NICs""" cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg") config = Config(cf) nicConfigurator = NicConfigurator(config.nics, False) nics_cfg_list = nicConfigurator.generate() self.assertEqual(2, len(nics_cfg_list), "number of config elements") nic1 = {"name": "NIC1"} nic2 = {"name": "NIC2"} for cfg in nics_cfg_list: if cfg.get("name") == nic1.get("name"): nic1.update(cfg) elif cfg.get("name") == nic2.get("name"): nic2.update(cfg) self.assertEqual("physical", nic1.get("type"), "type of NIC1") self.assertEqual("NIC1", nic1.get("name"), "name of NIC1") self.assertEqual("00:50:56:a6:8c:08", nic1.get("mac_address"), "mac address of NIC1") subnets = nic1.get("subnets") self.assertEqual(1, len(subnets), "number of subnets for NIC1") subnet = subnets[0] self.assertEqual("dhcp", subnet.get("type"), "DHCP type for NIC1") self.assertEqual("auto", subnet.get("control"), "NIC1 Control type") self.assertEqual("physical", nic2.get("type"), "type of NIC2") self.assertEqual("NIC2", nic2.get("name"), "name of NIC2") self.assertEqual("00:50:56:a6:5a:de", nic2.get("mac_address"), "mac address of NIC2") subnets = nic2.get("subnets") self.assertEqual(1, len(subnets), "number of subnets for NIC2") subnet = subnets[0] self.assertEqual("dhcp", subnet.get("type"), "DHCP type for NIC2") self.assertEqual("auto", subnet.get("control"), "NIC2 Control type")
def test_get_nics_list_dhcp(self): """Tests if NicConfigurator properly calculates network subnets for a configuration with a list of DHCP NICs""" cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg") config = Config(cf) nicConfigurator = NicConfigurator(config.nics, False) nics_cfg_list = nicConfigurator.generate() self.assertEqual(2, len(nics_cfg_list), "number of config elements") nic1 = {'name': 'NIC1'} nic2 = {'name': 'NIC2'} for cfg in nics_cfg_list: if cfg.get('name') == nic1.get('name'): nic1.update(cfg) elif cfg.get('name') == nic2.get('name'): nic2.update(cfg) self.assertEqual('physical', nic1.get('type'), 'type of NIC1') self.assertEqual('NIC1', nic1.get('name'), 'name of NIC1') self.assertEqual('00:50:56:a6:8c:08', nic1.get('mac_address'), 'mac address of NIC1') subnets = nic1.get('subnets') self.assertEqual(1, len(subnets), 'number of subnets for NIC1') subnet = subnets[0] self.assertEqual('dhcp', subnet.get('type'), 'DHCP type for NIC1') self.assertEqual('auto', subnet.get('control'), 'NIC1 Control type') self.assertEqual('physical', nic2.get('type'), 'type of NIC2') self.assertEqual('NIC2', nic2.get('name'), 'name of NIC2') self.assertEqual('00:50:56:a6:5a:de', nic2.get('mac_address'), 'mac address of NIC2') subnets = nic2.get('subnets') self.assertEqual(1, len(subnets), 'number of subnets for NIC2') subnet = subnets[0] self.assertEqual('dhcp', subnet.get('type'), 'DHCP type for NIC2') self.assertEqual('auto', subnet.get('control'), 'NIC2 Control type')
def test_get_nics_list_static(self): """Tests if NicConfigurator properly calculates network subnets for a configuration with 2 static NICs""" cf = ConfigFile("tests/data/vmware/cust-static-2nic.cfg") config = Config(cf) nicConfigurator = NicConfigurator(config.nics, False) nics_cfg_list = nicConfigurator.generate() self.assertEqual(2, len(nics_cfg_list), "number of elements") nic1 = {'name': 'NIC1'} nic2 = {'name': 'NIC2'} route_list = [] for cfg in nics_cfg_list: cfg_type = cfg.get('type') if cfg_type == 'physical': if cfg.get('name') == nic1.get('name'): nic1.update(cfg) elif cfg.get('name') == nic2.get('name'): nic2.update(cfg) self.assertEqual('physical', nic1.get('type'), 'type of NIC1') self.assertEqual('NIC1', nic1.get('name'), 'name of NIC1') self.assertEqual('00:50:56:a6:8c:08', nic1.get('mac_address'), 'mac address of NIC1') subnets = nic1.get('subnets') self.assertEqual(2, len(subnets), 'Number of subnets') static_subnet = [] static6_subnet = [] for subnet in subnets: subnet_type = subnet.get('type') if subnet_type == 'static': static_subnet.append(subnet) elif subnet_type == 'static6': static6_subnet.append(subnet) else: self.assertEqual(True, False, 'Unknown type') if 'route' in subnet: for route in subnet.get('routes'): route_list.append(route) self.assertEqual(1, len(static_subnet), 'Number of static subnet') self.assertEqual(1, len(static6_subnet), 'Number of static6 subnet') subnet = static_subnet[0] self.assertEqual('10.20.87.154', subnet.get('address'), 'IPv4 address of static subnet') self.assertEqual('255.255.252.0', subnet.get('netmask'), 'NetMask of static subnet') self.assertEqual('auto', subnet.get('control'), 'control for static subnet') subnet = static6_subnet[0] self.assertEqual('fc00:10:20:87::154', subnet.get('address'), 'IPv6 address of static subnet') self.assertEqual('64', subnet.get('netmask'), 'NetMask of static6 subnet') route_set = set(['10.20.87.253', '10.20.87.105', '192.168.0.10']) for route in route_list: self.assertEqual(10000, route.get('metric'), 'metric of route') gateway = route.get('gateway') if gateway in route_set: route_set.discard(gateway) else: self.assertEqual(True, False, 'invalid gateway %s' % (gateway)) self.assertEqual('physical', nic2.get('type'), 'type of NIC2') self.assertEqual('NIC2', nic2.get('name'), 'name of NIC2') self.assertEqual('00:50:56:a6:ef:7d', nic2.get('mac_address'), 'mac address of NIC2') subnets = nic2.get('subnets') self.assertEqual(1, len(subnets), 'Number of subnets for NIC2') subnet = subnets[0] self.assertEqual('static', subnet.get('type'), 'Subnet type') self.assertEqual('192.168.6.102', subnet.get('address'), 'Subnet address') self.assertEqual('255.255.0.0', subnet.get('netmask'), 'Subnet netmask')
def test_get_nics_list_static(self): """Tests if NicConfigurator properly calculates network subnets for a configuration with 2 static NICs""" cf = ConfigFile("tests/data/vmware/cust-static-2nic.cfg") config = Config(cf) nicConfigurator = NicConfigurator(config.nics, False) nics_cfg_list = nicConfigurator.generate() self.assertEqual(2, len(nics_cfg_list), "number of elements") nic1 = {"name": "NIC1"} nic2 = {"name": "NIC2"} route_list = [] for cfg in nics_cfg_list: cfg_type = cfg.get("type") if cfg_type == "physical": if cfg.get("name") == nic1.get("name"): nic1.update(cfg) elif cfg.get("name") == nic2.get("name"): nic2.update(cfg) self.assertEqual("physical", nic1.get("type"), "type of NIC1") self.assertEqual("NIC1", nic1.get("name"), "name of NIC1") self.assertEqual("00:50:56:a6:8c:08", nic1.get("mac_address"), "mac address of NIC1") subnets = nic1.get("subnets") self.assertEqual(2, len(subnets), "Number of subnets") static_subnet = [] static6_subnet = [] for subnet in subnets: subnet_type = subnet.get("type") if subnet_type == "static": static_subnet.append(subnet) elif subnet_type == "static6": static6_subnet.append(subnet) else: self.assertEqual(True, False, "Unknown type") if "route" in subnet: for route in subnet.get("routes"): route_list.append(route) self.assertEqual(1, len(static_subnet), "Number of static subnet") self.assertEqual(1, len(static6_subnet), "Number of static6 subnet") subnet = static_subnet[0] self.assertEqual( "10.20.87.154", subnet.get("address"), "IPv4 address of static subnet", ) self.assertEqual("255.255.252.0", subnet.get("netmask"), "NetMask of static subnet") self.assertEqual("auto", subnet.get("control"), "control for static subnet") subnet = static6_subnet[0] self.assertEqual( "fc00:10:20:87::154", subnet.get("address"), "IPv6 address of static subnet", ) self.assertEqual("64", subnet.get("netmask"), "NetMask of static6 subnet") route_set = set(["10.20.87.253", "10.20.87.105", "192.168.0.10"]) for route in route_list: self.assertEqual(10000, route.get("metric"), "metric of route") gateway = route.get("gateway") if gateway in route_set: route_set.discard(gateway) else: self.assertEqual(True, False, "invalid gateway %s" % (gateway)) self.assertEqual("physical", nic2.get("type"), "type of NIC2") self.assertEqual("NIC2", nic2.get("name"), "name of NIC2") self.assertEqual("00:50:56:a6:ef:7d", nic2.get("mac_address"), "mac address of NIC2") subnets = nic2.get("subnets") self.assertEqual(1, len(subnets), "Number of subnets for NIC2") subnet = subnets[0] self.assertEqual("static", subnet.get("type"), "Subnet type") self.assertEqual("192.168.6.102", subnet.get("address"), "Subnet address") self.assertEqual("255.255.0.0", subnet.get("netmask"), "Subnet netmask")
def test_get_nics_list_static(self): """Tests if NicConfigurator properly calculates network subnets for a configuration with 2 static NICs""" cf = ConfigFile("tests/data/vmware/cust-static-2nic.cfg") config = Config(cf) nicConfigurator = NicConfigurator(config.nics, False) nics_cfg_list = nicConfigurator.generate() self.assertEqual(2, len(nics_cfg_list), "number of elements") nic1 = {'name': 'NIC1'} nic2 = {'name': 'NIC2'} route_list = [] for cfg in nics_cfg_list: cfg_type = cfg.get('type') if cfg_type == 'physical': if cfg.get('name') == nic1.get('name'): nic1.update(cfg) elif cfg.get('name') == nic2.get('name'): nic2.update(cfg) self.assertEqual('physical', nic1.get('type'), 'type of NIC1') self.assertEqual('NIC1', nic1.get('name'), 'name of NIC1') self.assertEqual('00:50:56:a6:8c:08', nic1.get('mac_address'), 'mac address of NIC1') subnets = nic1.get('subnets') self.assertEqual(2, len(subnets), 'Number of subnets') static_subnet = [] static6_subnet = [] for subnet in subnets: subnet_type = subnet.get('type') if subnet_type == 'static': static_subnet.append(subnet) elif subnet_type == 'static6': static6_subnet.append(subnet) else: self.assertEqual(True, False, 'Unknown type') if 'route' in subnet: for route in subnet.get('routes'): route_list.append(route) self.assertEqual(1, len(static_subnet), 'Number of static subnet') self.assertEqual(1, len(static6_subnet), 'Number of static6 subnet') subnet = static_subnet[0] self.assertEqual('10.20.87.154', subnet.get('address'), 'IPv4 address of static subnet') self.assertEqual('255.255.252.0', subnet.get('netmask'), 'NetMask of static subnet') self.assertEqual('auto', subnet.get('control'), 'control for static subnet') subnet = static6_subnet[0] self.assertEqual('fc00:10:20:87::154', subnet.get('address'), 'IPv6 address of static subnet') self.assertEqual('64', subnet.get('netmask'), 'NetMask of static6 subnet') route_set = set(['10.20.87.253', '10.20.87.105', '192.168.0.10']) for route in route_list: self.assertEqual(10000, route.get('metric'), 'metric of route') gateway = route.get('gateway') if gateway in route_set: route_set.discard(gateway) else: self.assertEqual(True, False, 'invalid gateway %s' % (gateway)) self.assertEqual('physical', nic2.get('type'), 'type of NIC2') self.assertEqual('NIC2', nic2.get('name'), 'name of NIC2') self.assertEqual('00:50:56:a6:ef:7d', nic2.get('mac_address'), 'mac address of NIC2') subnets = nic2.get('subnets') self.assertEqual(1, len(subnets), 'Number of subnets for NIC2') subnet = subnets[0] self.assertEqual('static', subnet.get('type'), 'Subnet type') self.assertEqual('192.168.6.102', subnet.get('address'), 'Subnet address') self.assertEqual('255.255.0.0', subnet.get('netmask'), 'Subnet netmask')