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 _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 IPtools.isIntermediateNets(lastnet, subnet): subnet_matrix.append(None) 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 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: meta = metaIP.MetaIP(host_nybbles_map[key]) ip = host_nybbles_map[key] matrix_cell = self.Cell( colspan=self._colspan(ip), color=meta.ipv6_color, 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: subnet_matrix.append(None) lastnet = 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=None, content=' ') ] subnet_matrix.append(matrix_row) subnet_matrix.extend( self._write_subnets(net[subnet], depth + 1)) return subnet_matrix
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 _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