def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() b64name = param[1] if not (b64name and host_id): return web.badrequest() name = base64_decode(str(b64name)) (target, device) = name.split("@") net = NetworkAddress(target) ipaddr = net.ipaddr netmask = net.netmask netlen = net.netlen gateway = _('N/A') flags = _('N/A') ref = _('N/A') use = _('N/A') metric = _('N/A') parser = Parser() status = parser.do_status() for _k,_v in status.iteritems(): for _k2,_v2 in _v.iteritems(): if name == "%s@%s" % (_k2,_k,): gateway = _v2['gateway'] flags = _v2['flags'] ref = _v2['ref'] use = _v2['use'] metric = _v2['metric'] route = dict(name=name, ipaddr=ipaddr, netmask=netmask, netlen=netlen, device=device, gateway=gateway, flags=flags, ref=ref, use=use, metric=metric, ) self.view.route = route return True
def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() host = findbyhost1(self.orm, host_id) self.view.host_id = host_id # unremovable entries excludes = { "device": ["^peth","^virbr","^sit","^xenbr","^lo","^br"], "ipaddr": ["^0\.0\.0\.0$", "^169\.254\.0\.0$"], } devices = [] phydev_regex = re.compile(r"^eth[0-9]+") for dev,dev_info in get_ifconfig_info().iteritems(): if phydev_regex.match(dev): try: if dev_info['ipaddr'] is not None: devices.append(dev) net = NetworkAddress("%s/%s" % (dev_info['ipaddr'],dev_info['mask'],)) excludes['ipaddr'].append(net.network) except: pass self.view.devices = devices parser = Parser() status = parser.do_status() routes = {} for _k,_v in status.iteritems(): for _k2,_v2 in _v.iteritems(): name = base64_encode("%s@%s" % (_k2,_k,)) routes[name] = {} routes[name]['name'] = name routes[name]['device'] = _k routes[name]['gateway'] = _v2['gateway'] routes[name]['flags'] = _v2['flags'] routes[name]['ref'] = _v2['ref'] routes[name]['use'] = _v2['use'] net = NetworkAddress(_k2) routes[name]['ipaddr'] = net.ipaddr routes[name]['netlen'] = net.netlen routes[name]['netmask'] = net.netmask removable = True for _ex_key,_ex_val in excludes.iteritems(): ex_regex = "|".join(_ex_val) mm = re.search(ex_regex,routes[name][_ex_key]) if mm: removable = False routes[name]['removable'] = removable self.view.routes = routes if self.is_mode_input(): pass return True
def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() host = findbyhost1(self.orm, host_id) self.view.host_id = host_id # unremovable entries excludes = { "device": ["^peth", "^virbr", "^sit", "^xenbr", "^lo", "^br"], "ipaddr": ["^0\.0\.0\.0$", "^169\.254\.0\.0$"], } devices = [] phydev_regex = re.compile(r"^eth[0-9]+") for dev, dev_info in get_ifconfig_info().iteritems(): if phydev_regex.match(dev): try: if dev_info['ipaddr'] is not None: devices.append(dev) net = NetworkAddress("%s/%s" % ( dev_info['ipaddr'], dev_info['mask'], )) excludes['ipaddr'].append(net.network) except: pass self.view.devices = devices parser = Parser() status = parser.do_status() routes = {} for _k, _v in status.iteritems(): for _k2, _v2 in _v.iteritems(): name = base64_encode("%s@%s" % ( _k2, _k, )) routes[name] = {} routes[name]['name'] = name routes[name]['device'] = _k routes[name]['gateway'] = _v2['gateway'] routes[name]['flags'] = _v2['flags'] routes[name]['ref'] = _v2['ref'] routes[name]['use'] = _v2['use'] net = NetworkAddress(_k2) routes[name]['ipaddr'] = net.ipaddr routes[name]['netlen'] = net.netlen routes[name]['netmask'] = net.netmask removable = True for _ex_key, _ex_val in excludes.iteritems(): ex_regex = "|".join(_ex_val) mm = re.search(ex_regex, routes[name][_ex_key]) if mm: removable = False routes[name]['removable'] = removable self.view.routes = routes if self.is_mode_input(): pass return True