def process_vlan(self, lines, cur_idx, lineno): ifaceobj = iface() lines_consumed = self.parse_iface(lines, cur_idx, lineno, ifaceobj) range_val = utils.parse_iface_range(ifaceobj.name) if range_val: if len(range_val) == 3: for v in range(range_val[1], range_val[2] + 1): flags = iface.IFACERANGE_ENTRY if v == range_val[1]: flags |= iface.IFACERANGE_START ifaceobj_new = self._create_ifaceobj_clone( ifaceobj, '%s%d' % (range_val[0], v), ifaceType.BRIDGE_VLAN, flags) self.callbacks.get('iface_found')(ifaceobj_new) elif len(range_val) == 4: for v in range(range_val[1], range_val[2] + 1): flags = iface.IFACERANGE_ENTRY if v == range_val[1]: flags |= iface.IFACERANGE_START ifaceobj_new = self._create_ifaceobj_clone( ifaceobj, '%s%d%s' % (range_val[0], v, range_val[3]), ifaceType.BRIDGE_VLAN, flags) self.callbacks.get('iface_found')(ifaceobj_new) else: ifaceobj.type = ifaceType.BRIDGE_VLAN self.callbacks.get('iface_found')(ifaceobj) return lines_consumed # Return next index
def process_iface(self, lines, cur_idx, lineno): ifaceobj = iface() lines_consumed = self.parse_iface(lines, cur_idx, lineno, ifaceobj) range_val = utils.parse_iface_range(ifaceobj.name) if range_val: if len(range_val) == 3: for v in range(range_val[1], range_val[2]+1): ifacename = '%s%d' %(range_val[0], v) if utils.check_ifname_size_invalid(ifacename): self._parse_warn(self._currentfile, lineno, '%s: interface name too long' %ifacename) flags = iface.IFACERANGE_ENTRY if v == range_val[1]: flags |= iface.IFACERANGE_START ifaceobj_new = self._create_ifaceobj_clone(ifaceobj, ifacename, ifaceobj.type, flags) self.callbacks.get('iface_found')(ifaceobj_new) elif len(range_val) == 4: for v in range(range_val[1], range_val[2]+1): ifacename = '%s%d%s' %(range_val[0], v, range_val[3]) if utils.check_ifname_size_invalid(ifacename): self._parse_warn(self._currentfile, lineno, '%s: interface name too long' %ifacename) flags = iface.IFACERANGE_ENTRY if v == range_val[1]: flags |= iface.IFACERANGE_START ifaceobj_new = self._create_ifaceobj_clone(ifaceobj, ifacename, ifaceobj.type, flags) self.callbacks.get('iface_found')(ifaceobj_new) else: self.callbacks.get('iface_found')(ifaceobj) return lines_consumed # Return next index
def process_auto(self, lines, cur_idx, lineno): auto_ifaces = re.split(self._ws_split_regex, lines[cur_idx])[1:] if not auto_ifaces: #auto之后必须给接口名称 self._parse_error(self._currentfile, lineno, 'invalid auto line \'%s\''%lines[cur_idx]) return 0 for a in auto_ifaces: if a == 'all': self.auto_all = True break r = utils.parse_iface_range(a) if r: #支持range方式 if len(r) == 3: # eg swp1.[2-4], r = "swp1.", 2, 4) for i in range(r[1], r[2]+1): self.auto_ifaces.append('%s%d' %(r[0], i)) elif len(r) == 4: for i in range(r[1], r[2]+1): # eg swp[2-4].100, r = ("swp", 2, 4, ".100") self.auto_ifaces.append('%s%d%s' %(r[0], i, r[3])) #添加auto ifaces self.auto_ifaces.append(a) return 0
def process_vlan(self, lines, cur_idx, lineno): ifaceobj = iface() lines_consumed = self.parse_iface(lines, cur_idx, lineno, ifaceobj) range_val = utils.parse_iface_range(ifaceobj.name) if range_val: if len(range_val) == 3: for v in range(range_val[1], range_val[2]+1): flags = iface.IFACERANGE_ENTRY if v == range_val[1]: flags |= iface.IFACERANGE_START ifaceobj_new = self._create_ifaceobj_clone(ifaceobj, '%s%d' %(range_val[0], v), ifaceType.BRIDGE_VLAN, flags) self.callbacks.get('iface_found')(ifaceobj_new) elif len(range_val) == 4: for v in range(range_val[1], range_val[2]+1): flags = iface.IFACERANGE_ENTRY if v == range_val[1]: flags |= iface.IFACERANGE_START ifaceobj_new = self._create_ifaceobj_clone(ifaceobj, '%s%d%s' %(range_val[0], v, range_val[3]), ifaceType.BRIDGE_VLAN, flags) self.callbacks.get('iface_found')(ifaceobj_new) else: ifaceobj.type = ifaceType.BRIDGE_VLAN self.callbacks.get('iface_found')(ifaceobj) return lines_consumed # Return next index
def process_auto(self, lines, cur_idx, lineno): auto_ifaces = re.split(self._ws_split_regex, lines[cur_idx])[1:] if not auto_ifaces: self._parse_error(self._currentfile, lineno, 'invalid auto line \'%s\''%lines[cur_idx]) return 0 for a in auto_ifaces: if a == 'all': self.auto_all = True break r = utils.parse_iface_range(a) if r: if len(r) == 3: # eg swp1.[2-4], r = "swp1.", 2, 4) for i in range(r[1], r[2]+1): self.auto_ifaces.append('%s%d' %(r[0], i)) elif len(r) == 4: for i in range(r[1], r[2]+1): # eg swp[2-4].100, r = ("swp", 2, 4, ".100") self.auto_ifaces.append('%s%d%s' %(r[0], i, r[3])) self.auto_ifaces.append(a) return 0