def _add_large_subnet(self, subnet, matrix_row): """Adds correct rowspan to cell for large nets """ meta = metaIP.MetaIP(subnet) rowspan = 2**(self._get_row_size() - subnet.prefixlen()) matrix_row.append(self._create_cell(subnet, meta, rowspan=rowspan)) # Return the number of extra rows that need to be made return rowspan - 1
def _netlink(ip, append_term_and_prefix=False): nip = metaIP.MetaIP(ip).getTreeNet() if append_term_and_prefix: url = reverse('report-matrix-scope', kwargs={'scope': ip.strNormal().replace('/', '%2F')}) text = ip.strNormal() else: url = reverse('report-prefix-netaddr', kwargs={'netaddr': nip + '.%'}) text = nip return '<a href="{0}">{1}</a>'.format(url, text)
def _create_index_cell(self, subnet, link=True): """Creates the cell for the first column in the matrix This cell typically displays the subnet :param link: If the cell should contain a link to subnet or not """ if link: return Cell(link=self._netlink(subnet)) else: return Cell(content=metaIP.MetaIP(subnet).getTreeNet())
def _netlink(ip, append_term_and_prefix=False): nip = metaIP.MetaIP(ip).getTreeNet() if append_term_and_prefix: url = reverse( 'report-matrix-scope', kwargs={'scope': ip.strNormal().replace('/', '%2F')}, ) text = ip.strNormal() else: url = report("prefix", netaddr=nip + ".*", op_netaddr="like") text = nip return Link(url, text, 'Go to prefix report')
def _matrixlink(nybble, ip): meta = metaIP.MetaIP(ip) report_url = reverse('report-prefix-prefix', kwargs={'prefix_id': meta.prefixid}) machinetracker_url = reverse('machinetracker-prefixid_search_active', kwargs={'prefix_id': meta.prefixid}) return """ <a href="{0}">.{1}/{2}</a> <a href="{3}" title="{4}/{5}">({6}%)</a> """.format(report_url, nybble, ip.prefixlen(), machinetracker_url, meta.active_ip_cnt, meta.max_ip_cnt, meta.usage_percent)
def _create_data_row(self, subnet): """Create a data row containing a list of cells :rtype: list[Cell] """ if self.has_too_small_nets(subnet): return [self._create_too_small_subnets_cell()] elif self.matrix_nets[subnet]: # this subnet is divided into parts host_nybbles_map = IPtools.getLastbitsIpMap( self.matrix_nets[subnet].keys()) return self._add_child_nets(host_nybbles_map) else: # this subnet spans the whole row meta = metaIP.MetaIP(subnet) return [self._create_cell(subnet, meta)]
def _add_child_nets(self, host_nybbles_map): next_header_idx = -1 cells = [] for i in self.column_headings: if self.column_headings.index(i) < next_header_idx: continue key = i.lower() if key in host_nybbles_map: ip = host_nybbles_map[key] meta = metaIP.MetaIP(ip) matrix_cell = self._create_cell(ip, meta, key=key) next_header_idx = (self.column_headings.index(i) + int(self._colspan(ip))) else: matrix_cell = Cell(is_empty=True) cells.append(matrix_cell) return cells
def _netlink(ip, append_term_and_prefix=False): """Creates the content for the index row""" ip = metaIP.MetaIP(ip).getTreeNet() url = reverse('report-prefix-netaddr', kwargs={'netaddr': ip + '*'}) text = ip + 'x' return Link(url, text, 'Go to prefix report')
def _netlink(ip, append_term_and_prefix=False): """Creates the content for the index row""" ip = metaIP.MetaIP(ip).getTreeNet() url = report("prefix", netaddr=ip + '*', op_netaddr="like") text = ip + 'x' return Link(url, text, 'Go to prefix report')
def _write_subnets(self, net, depth): nodes = IPtools.sort_nets_by_address(net.keys()) lastnet = None subnet_matrix = [] for subnet in nodes: if lastnet is None: lastnet = subnet if subnet in self.matrix_nets: if self.show_unused_addresses: subnet_matrix.extend( self._nets_in_range(lastnet, subnet, depth)) lastnet = subnet matrix_row = [ self.Cell(colspan=1, color=None, content='{0} {1}'.format( Matrix.print_depth(depth), _netlink(subnet))) ] host_nybbles_map = IPtools.getLastbitsIpMap( self.matrix_nets[subnet].keys()) next_header_idx = -1 if self.has_too_small_nets(subnet): matrix_row.append( self.Cell(colspan=self.num_columns, color=self._load_color(0, 'large'), content='Too many small nets')) elif host_nybbles_map is None: # i.e. there exist a net with no # subnets <==> net spans whole row ip = IPy.IP(subnet) meta = metaIP.MetaIP(ip) matrix_row.append( self.Cell(colspan=self.num_columns, color=self._load_color( meta.usage_percent, meta.nettype), content=_matrixlink(0, ip))) else: # The net exists and have subnets for i in self.column_headings: if self.column_headings.index(i) < next_header_idx: continue key = i.lower() if key in host_nybbles_map: ip = host_nybbles_map[key] meta = metaIP.MetaIP(ip) matrix_cell = self.Cell( colspan=self._colspan(ip), color=self._load_color(meta.usage_percent, meta.nettype), content=_matrixlink(key, ip)) next_header_idx = (self.column_headings.index(i) + int(self._colspan(ip))) else: matrix_cell = self.Cell(colspan=1, color=None, content=' ') matrix_row.append(matrix_cell) subnet_matrix.append(matrix_row) else: if (self.matrix_nets and lastnet.prefixlen() < self.matrix_nets.keys()[0].prefixlen()): mnets = self.generate_matrix_nets(lastnet) subnet_extended = IPy.IP('/'.join([ subnet.net().strNormal(), str(self.matrix_nets.keys()[0].prefixlen()) ])) subnet_matrix.extend( self._nets_in_range(mnets[-1], subnet_extended, depth)) lastnet = subnet meta = metaIP.MetaIP(subnet) matrix_row = [ self.Cell(colspan=1, color=None, content='{0} {1}'.format( Matrix.print_depth(depth), _netlink(subnet, True))), self.Cell(colspan=self.num_columns, color=self._load_color(meta.usage_percent, meta.nettype), content=_supernet_matrixlink(subnet)) ] subnet_matrix.append(matrix_row) subnet_matrix.extend( self._write_subnets(net[subnet], depth + 1)) subnet_matrix.extend( self._remaining_blank_nets(subnet, depth + 1)) return subnet_matrix
def _supernet_matrixlink(ip): meta = metaIP.MetaIP(ip) url = reverse('machinetracker-prefixid_search_active', kwargs={'prefix_id': meta.prefixid}) return '<a href="{0}" title="{1}/{2}">({3}%)</a>'.format( url, meta.active_ip_cnt, meta.max_ip_cnt, meta.usage_percent)