def environment_setting(req): if req.method == 'POST': Environment.set(**req.data) env = Environment.one() domain = INPUT.TEXT('domain', env.domain) cidr = INPUT.TEXT('cidr', env.cidr) gateway = INPUT.TEXT('gateway', env.gateway) noserv = INPUT.TEXT('netops', env.netops) dns_ext = INPUT.TEXT('dns_ext', env.dns_ext) return DIV().html( HEAD(1, STYLE='float:left;').html('Environment'), DIV(STYLE='float:right;margin:20px 0px 10px 20px;').html( netops.context( BUTTON(CLASS='btn-primary', STYLE='height:39px;').html('Save'), 'environment_setting', domain, cidr, gateway, noserv, dns_ext)), INPUT.GROUP().html(INPUT.LABEL_TOP('Domain'), domain), INPUT.GROUP().html(INPUT.LABEL_TOP('CIDR'), cidr), INPUT.GROUP().html(INPUT.LABEL_TOP('Network'), INPUT.DISPLAY().html(env.network)), INPUT.GROUP().html(INPUT.LABEL_TOP('Prepix'), INPUT.DISPLAY().html(env.prefix)), INPUT.GROUP().html(INPUT.LABEL_TOP('Netmask'), INPUT.DISPLAY().html(env.netmask)), INPUT.GROUP().html(INPUT.LABEL_TOP('Gateway'), gateway), INPUT.GROUP().html(INPUT.LABEL_TOP('NetOps (Internal DNS & NTP)'), noserv), INPUT.GROUP().html(INPUT.LABEL_TOP('External DNS'), dns_ext))
def netops_main_static_table(table, sr_id): if isinstance(sr_id, str): sr_id = int(sr_id) env = Environment.one() sr = StaticRange.get(sr_id) if sr: hosts = Host.list(Host.ip_num >= sr.stt_num, Host.ip_num <= sr.end_num) for host in hosts: sr_id = INPUT.HIDDEN('sr_id', str(sr.id)) host_id = INPUT.HIDDEN('host_id', str(host.id)) name = INPUT.TEXT('name', host.name, CLASS='page-input-in-table') mac = INPUT.TEXT('mac', host.mac, CLASS='page-input-in-table') model_list = [m for m in _host_models] model_list.remove(host.model) model_list.insert(0, host.model) model = INPUT.SELECT('model', *model_list, CLASS='page-input-in-table') serial = INPUT.TEXT('serial', host.serial, CLASS='page-input-in-table') desc = INPUT.TEXT('desc', host.desc, CLASS='page-input-in-table') submit = DIV(STYLE='width:100%;text-align:center;').html( netops.context( BUTTON(CLASS='btn-primary btn-xs', STYLE='margin:0px;padding:0px 5px;font-size:11px;'). html('Save'), 'netops_main_static_view::' + str(sr.id), sr_id, host_id, name, mac, model, serial, desc), netops.signal( BUTTON(CLASS='btn-danger btn-xs', STYLE='margin:0px;padding:0px 5px;font-size:11px;' ).html('Clear'), 'DELETE', 'netops_main_static_view::' + str(sr.id), str(sr.id), str(host.id)), sr_id, host_id) table.record(name, host.ip, mac, model, serial, desc, submit)
def api_getEnv(req): env = Environment.one() return { 'domain': env.domain, 'cidr': env.cidr, 'network': env.network, 'prefix': env.prefix, 'netmask': env.netmask, 'gateway': env.gateway, 'netops': env.netops, 'dns_external': env.dns_ext }
def netops_main_total_table(table): env = Environment.one() hosts = Host.list() for host in hosts: if host.name != '' and host.range_name != '' and env.domain != '': dns = '%s.%s.%s' % (host.name.replace( ' ', '-'), host.range_name.replace(' ', '-'), env.domain) else: dns = '' if host.model == 'Unknown': model = '' else: model = host.model table.record( host.name, ANCH(HREF='http://' + dns, TARGET='_blank').html(dns), '%s (%s)' % (host.range_name, host.range_type) if host.range_name != '' else host.range_name, host.ip, host.mac, model, host.serial, host.desc)