class Subnet: def __init__(self, subnet, vlan): if APP_DEBUG is True: print "subnet:init subnet" self.subnet = subnet self.vlan = vlan self.r = IpRangeList(self.subnet) def get_subnet(self): if APP_DEBUG is True: print "subnet:get_subnet" return self.subnet def get_vlan(self): if APP_DEBUG is True: print "subnet:get_vlan" return self.vlan def get_ips(self): if APP_DEBUG is True: print "subnet:get_ips" return list(self.r.__iter__()) def get_ip_count(self): if APP_DEBUG is True: print "subnet:get_ip_count" return len(self.get_ips()) def get_display_columns(self): if APP_DEBUG is True: print "subnet:get_display_columns" return int(ceil(self.get_ip_count()/float(DISPLAY_HOSTS_PER_COL))) def get_subnet_url(self): return self.subnet.replace('/','%2F')
def get_actual_ips(net): # Make range object r = IpRangeList(net) # Generate list of all addresses ips = list(r.__iter__()) # Remove the broadcast ips.pop() # Remove the network ID ips = ips[1:] # Done return ips
def get_reserved_hosts(subnet): #res = dbconn.execute("SELECT address FROM ip.addresses WHERE api.get_address_range(address) IN (SELECT name FROM ip.ranges WHERE subnet = '"+subnet.get_subnet()+"' AND use='RESV') ORDER BY address") res = dbconn.execute("SELECT name,first_ip,last_ip FROM ip.ranges WHERE use='RESV' AND subnet='"+subnet.get_subnet()+"' ORDER BY first_ip") ips = [] for r in res.fetchall(): r = dict(r) range = IpRangeList((r['first_ip'],r['last_ip'])) ips += list(range.__iter__()) #if r['address'] not in ips: # ips.append(r['address']) return ips
def get_reserved_hosts(subnet): #res = dbconn.execute("SELECT address FROM ip.addresses WHERE api.get_address_range(address) IN (SELECT name FROM ip.ranges WHERE subnet = '"+subnet.get_subnet()+"' AND use='RESV') ORDER BY address") res = dbconn.execute( "SELECT name,first_ip,last_ip FROM ip.ranges WHERE use='RESV' AND subnet='" + subnet.get_subnet() + "' ORDER BY first_ip") ips = [] for r in res.fetchall(): r = dict(r) range = IpRangeList((r['first_ip'], r['last_ip'])) ips += list(range.__iter__()) #if r['address'] not in ips: # ips.append(r['address']) return ips