def test_bond(self): manager = if_mgr() ifs_list = manager.interface_name_list() test_ifs_name = get_net_if() if test_ifs_name == "": return self.assertTrue(test_ifs_name in ifs_list) ifs = manager.get_interface_by_name( test_ifs_name) # last interface to test ip, mask, gateway = ifs.get_ip_config() bond_manager = bond_mgr() bond_name = bond_manager.add_group(80, 1, [test_ifs_name], ip, mask, gateway) bond_list = bond_manager.get_group_list() self.assertTrue(True, isinstance(bond_list, list)) self.assertGreater(len(bond_list), 0) bond_ifs = bond_manager.get_group_by_name(bond_name) self.assertEqual(bond_ifs.miimon, 80) self.assertEqual(bond_ifs.mode, 1) self.assertTrue(test_ifs_name in bond_ifs.slaves) self.assertEqual((ip, mask, gateway), bond_ifs.get_ip_config()) bond_manager.del_group(bond_name) ifs = manager.get_interface_by_name(test_ifs_name) self.assertEqual((ip, mask, gateway), ifs.get_ip_config())
def test_bond(self): manager = if_mgr() ifs_list = manager.interface_name_list() test_ifs_name = get_net_if() if test_ifs_name == "": return self.assertTrue(test_ifs_name in ifs_list) ifs = manager.get_interface_by_name(test_ifs_name) # last interface to test ip, mask, gateway = ifs.get_ip_config() bond_manager = bond_mgr() bond_name = bond_manager.add_group(80, 1, [test_ifs_name], ip, mask, gateway) bond_list = bond_manager.get_group_list() self.assertTrue(True, isinstance(bond_list, list)) self.assertGreater(len(bond_list), 0) bond_ifs = bond_manager.get_group_by_name(bond_name) self.assertEqual(bond_ifs.miimon, 80) self.assertEqual(bond_ifs.mode, 1) self.assertTrue(test_ifs_name in bond_ifs.slaves) self.assertEqual((ip, mask, gateway), bond_ifs.get_ip_config()) bond_manager.del_group(bond_name) ifs = manager.get_interface_by_name(test_ifs_name) self.assertEqual((ip, mask, gateway), ifs.get_ip_config())
def network_get(request): eth_face = ifmgr.if_mgr() eth_list = eth_face.interface_name_list() eth_list_dict = [] for port_name in eth_list: netif_info = eth_face.get_interface_by_name(port_name) port_info = get_port_info(netif_info) eth_list_dict.append(port_info) return eth_list_dict
def post_port_op(request): op_info = get_params_from_request(request, port_op_schema) port_name = request.matchdict['port_name'] eth_face = ifmgr.if_mgr() eth = eth_face.get_interface_by_name(port_name) if op_info["opcode"] == "enable": eth.up(user=request.client_addr) elif op_info["opcode"] == "disable": eth.down(user=request.client_addr) return Response(status=200)
def modify_single_port(request): port_info = get_params_from_request(request, port_mod_schema) port_name = request.matchdict['port_name'] eth_face = ifmgr.if_mgr() eth = eth_face.get_interface_by_name(port_name) eth.set_ip_config(ip=port_info.get("ip", None), netmask=port_info.get("netmask", None), gateway=port_info.get("gateway", None), user=request.client_addr) return Response(status=200)
def test_interface_ip(self): manager = if_mgr() ifs_list = manager.interface_name_list() test_ifs_name = get_net_if() if test_ifs_name == "": return self.assertTrue(test_ifs_name in ifs_list) ifs = manager.get_interface_by_name(test_ifs_name) # last interface to test ip, mask, gateway = ifs.get_ip_config() ifs.set_ip_config("", "", "") new_ip, new_mask, new_gateway = ifs.get_ip_config() self.assertEqual("", new_ip) self.assertEqual("", new_mask) self.assertEqual("", new_gateway) ifs.set_ip_config(ip, mask, gateway)
def test_interface_ip(self): manager = if_mgr() ifs_list = manager.interface_name_list() test_ifs_name = get_net_if() if test_ifs_name == "": return self.assertTrue(test_ifs_name in ifs_list) ifs = manager.get_interface_by_name( test_ifs_name) # last interface to test ip, mask, gateway = ifs.get_ip_config() ifs.set_ip_config("", "", "") new_ip, new_mask, new_gateway = ifs.get_ip_config() self.assertEqual("", new_ip) self.assertEqual("", new_mask) self.assertEqual("", new_gateway) ifs.set_ip_config(ip, mask, gateway)
def test_interface_updown(self): manager = if_mgr() ifs_list = manager.interface_name_list() test_ifs_name = get_net_if() if test_ifs_name == "": return self.assertTrue(test_ifs_name in ifs_list) ifs = manager.get_interface_by_name(test_ifs_name) # last interface to test org_up = ifs.property_info["up"] if org_up: ifs.down() self.assertEqual(False, ifs.property_info["up"]) ifs.up() self.assertEqual(True, ifs.property_info["up"]) else: ifs.up() self.assertEqual(True, ifs.property_info["up"]) ifs.down() self.assertEqual(False, ifs.property_info["up"])
def test_interface_updown(self): manager = if_mgr() ifs_list = manager.interface_name_list() test_ifs_name = get_net_if() if test_ifs_name == "": return self.assertTrue(test_ifs_name in ifs_list) ifs = manager.get_interface_by_name( test_ifs_name) # last interface to test org_up = ifs.property_info["up"] if org_up: ifs.down() self.assertEqual(False, ifs.property_info["up"]) ifs.up() self.assertEqual(True, ifs.property_info["up"]) else: ifs.up() self.assertEqual(True, ifs.property_info["up"]) ifs.down() self.assertEqual(False, ifs.property_info["up"])
def get_port_stat(request): port_name = request.matchdict['port_name'] eth_face = ifmgr.if_mgr() netif_info = eth_face.get_interface_by_name(port_name) stat_info = netif_info.statistic_info return stat_info
def get_single_port(request): port_name = request.matchdict['port_name'] eth_face = ifmgr.if_mgr() netif_info = eth_face.get_interface_by_name(port_name) port_info = get_port_info(netif_info) return port_info
def add_group(self, miimon, mode, ifs=[], ip="", netmask="", gateway="", user="******"): """ add a bond group parameters: miimon, int, link detect interval in ms mode, int, bond mode ifs, Array of string, the array of the slave interface name return the new bond group name (bond interface name) """ if mode not in modeMap: StorLeverError("mdoe(%d) is not supported" % mode, 400) # get mutex with self.lock: # check slave ifs exist and not slave exist_if_list = if_mgr().interface_name_list() for slave_if in ifs: if slave_if not in exist_if_list: raise StorLeverError("%s not found" % slave_if, 404) if ifconfig.Interface(slave_if).is_slave(): raise StorLeverError("%s is already a slave of other bond group" % slave_if, 400) # find the available bond name max_index = self._find_max_index() bond_name = "bond%d" % (max_index + 1) # change bond.conf self._add_bond_to_conf(bond_name) # create ifcfg-bond* conf = properties(DEVICE=bond_name, IPADDR="", NETMASK="", GATEWAY="", BOOTPROTO="none", NM_CONTROLLED="no", ONBOOT="yes", BONDING_OPTS='"miimon=%d, mode=%d"' % (miimon, mode)) ifcfg_name = "ifcfg-%s" % bond_name conf.apply_to(os.path.join(IF_CONF_PATH, ifcfg_name)) # modify the slave's ifcfg for slave_if in ifs: slave_object = EthInterface(slave_if) slave_object.conf.delete("IPADDR") slave_object.conf.delete("NETMASK") slave_object.conf.delete("GATEWAY") slave_object.conf["BOOTPROTO"] = "none" slave_object.conf["ONBOOT"] = "yes" slave_object.conf["MASTER"] = bond_name slave_object.conf["SLAVE"] = "yes" slave_object.save_conf() # remove the if's ip avoid ip conflict # for slave_if in ifs: # check_output([IFDOWN, slave_if]) # ifconfig.Interface(slave_if).set_ip("0.0.0.0") # check_output([IFUP, slave_if]) # restart network check_output([IFUP, bond_name]) # set real ip if ip != "" or netmask != "" or gateway != "": with self.lock: conf = properties(IPADDR=ip, NETMASK=netmask, GATEWAY=gateway) conf.apply_to(os.path.join(IF_CONF_PATH, ifcfg_name)) check_output([IFDOWN, bond_name]) check_output([IFUP, bond_name]) logger.log(logging.INFO, logger.LOG_TYPE_CONFIG, "New bond group %s (mode:%d, miimon:%d, slaves:[%s]) " "is added by user(%s)" % (bond_name, mode, miimon, ",".join(ifs), user)) return bond_name
def test_interface_list(self): manager = if_mgr() ifs_list = manager.get_interface_list() self.assertTrue(isinstance(ifs_list, list)) self.assertGreater(len(ifs_list), 0)