Changeset 733 for trunk/cgi-bin
- Timestamp:
- 05/25/15 18:25:20 (9 years ago)
- Location:
- trunk/cgi-bin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r732 r733 25 25 @EXPORT_OK = qw( 26 26 %disp_alloctypes %list_alloctypes %def_custids @citylist @poplist 27 %IPDBacl % aclmsg %rpcacl $maxfcgi27 %IPDBacl %merge_display %aclmsg %rpcacl $maxfcgi 28 28 $errstr 29 29 &initIPDBGlobals &connectDB &finish &checkDBSanity … … 41 41 %EXPORT_TAGS = ( ALL => [qw( 42 42 %disp_alloctypes %list_alloctypes %def_custids @citylist @poplist 43 %IPDBacl % aclmsg %rpcacl $maxfcgi43 %IPDBacl %merge_display %aclmsg %rpcacl $maxfcgi 44 44 $errstr 45 45 &initIPDBGlobals &connectDB &finish &checkDBSanity … … 67 67 # Mapping hash for pooltype -> poolip-as-netblock conversions 68 68 my %poolmap = (sd => 'en', cd => 'cn', dp => 'cn', mp => 'cn', wp => 'cn', ld => 'in', ad => 'in', bd => 'in'); 69 70 # Friendly display strings for merge scopes 71 our %merge_display = ( 72 keepall => "Keep mergeable allocations as suballocations of new block", 73 mergepeer => "Keep suballocations of mergeable allocations", 74 clearpeer => "Keep only suballocations of the selected block", 75 clearall => "Clear all suballocations" 76 ); 69 77 70 78 # mapping table for functional-area => error message … … 916 924 my $btype = shift || 'a'; 917 925 $btype = 'a' if $btype !~/^[af]$/; 926 my $incsub = shift; 927 $incsub = 1 if !defined($incsub); 918 928 919 929 my $sql; … … 929 939 } else { 930 940 ##fixme: Not sure about the casting hackery in "SELECT ?::integer AS id", but it works as intended 931 my $ret = $dbh->selectall_arrayref(q( 932 SELECT cidr,id FROM freeblocks 933 WHERE parent_id IN (SELECT ?::integer AS id UNION 934 SELECT id FROM allocations WHERE parent_id = ? AND cidr <<= ? 935 ) AND cidr <<= ? 936 ORDER BY cidr 937 ), 938 { Slice => {} }, $parent, $parent, $newblock, $newblock) or print $dbh->errstr; 941 my @dbargs = ($parent, "$newblock"); 942 push @dbargs, $parent, $newblock if $incsub; 943 my $ret = $dbh->selectall_arrayref(q{ 944 SELECT cidr,id FROM freeblocks 945 WHERE parent_id IN ( 946 }.($incsub ? "SELECT id FROM allocations WHERE parent_id = ? AND cidr <<= ? UNION " : '').q{ 947 SELECT ?::integer AS id 948 ) AND cidr <<= ? 949 ORDER BY cidr 950 }, 951 { Slice => {} }, @dbargs); 939 952 return $ret; 940 953 } 954 return; 941 955 } # end listForMerge() 942 956 … … 2003 2017 # Takes a "base" block ID and a hash with a mask length and a scope argument to decide 2004 2018 # how much existing allocation data to delete. 2019 # Returns a list starting with the new merged block, then the merged allocations with comment 2005 2020 ## Merge scope: 2006 2021 # Merge to container … … 2064 2079 $args{newtype} = $binfo->{type} if !$args{newtype}; 2065 2080 # if the "primary" block being changed is a master, it must remain one. 2066 $args{newtype} = 'mm' if $binfo->{type} eq 'mm'; 2081 # Also force the scope, since otherwise things get ugly. 2082 if ($binfo->{type} eq 'mm') { 2083 $args{newtype} = 'mm'; 2084 # don't want to make a peer master a sub of the existing one; too many special cases go explodey, 2085 # but want to retain all other allocations 2086 $args{scope} = 'mergepeer'; 2087 } 2067 2088 my ($newcontainerclass) = ($args{newtype} =~ /^(.).$/); 2068 2089 … … 2123 2144 ## Container 2124 2145 2125 # In case of merging a master block 2146 # In case of merging a master block. Somewhat redundant with calls to $fbreparentsth, 2147 # but not *quite* entirely. 2126 2148 my $mfbsth = $dbh->prepare("UPDATE freeblocks SET master_id = ? WHERE master_id = ?"); 2127 2149 … … 2131 2153 # and now retrieve the new parent ID 2132 2154 ($prime) = $dbh->selectrow_array("SELECT currval('allocations_id_seq')"); 2155 # snag the new parent info for the return list 2156 push @retlist, { block => "$newblock", type => $disp_alloctypes{$args{newtype}}, id => $prime }; 2133 2157 # Reparent the free blocks in the new block 2134 2158 $fbreparentsth->execute($prime, $binfo->{master_id}, $binfo->{city}, $newcontainerclass, $binfo->{vrf}, 2135 2159 $binfo->{parent_id}, $newblock); 2136 2160 # keep existing allocations (including the original primary), just push them down a level 2137 while (my ($p cidr,$peer_id,$ptype,$m_id) = $peersth->fetchrow_array) {2161 while (my ($peercidr, $peer_id, $peertype, $m_id) = $peersth->fetchrow_array) { 2138 2162 $reparentsth->execute($prime, $binfo->{master_id}, $peer_id); 2139 2163 # Fix up master_id on free blocks if we're merging a master block 2140 $mfbsth->execute($binfo->{master_id}, $m_id) if $ptype eq 'mm'; 2164 $mfbsth->execute($binfo->{master_id}, $m_id) if $peertype eq 'mm'; 2165 # capture block for return 2166 push @retlist, { block => $peercidr, mtype => $disp_alloctypes{$peertype} }; 2141 2167 } 2142 2168 2143 2169 } elsif ($args{scope} =~ /^clear/) { 2144 2170 # clearpeer and clearall share a starting point 2171 # snag the new parent info for the return list 2172 push @retlist, { block => "$newblock", type => $disp_alloctypes{$args{newtype}}, id => $prime }; 2145 2173 # update the primary allocation info 2146 2174 $dbh->do("UPDATE allocations SET cidr = ?, type = ? WHERE id = ?", undef, ($newblock, $args{newtype}, $prime) ); … … 2153 2181 $binfo->{master_id}); 2154 2182 } 2155 # delete the peers 2156 while (my ($p cidr,$peer_id) = $peersth->fetchrow_array) {2183 # delete the peers. 2184 while (my ($peercidr, $peer_id, $peertype, $m_id) = $peersth->fetchrow_array) { 2157 2185 next if $peer_id == $prime; 2158 2186 # push existing allocations down a level before deleting, … … 2163 2191 # aren't special cases fun? 2164 2192 $dbh->do("INSERT INTO freeblocks (cidr,routed,parent_id,master_id) values (?,?,?,?)", 2165 undef, ($pcidr, 'm', $prime, $prime) ) if $binfo->{type} eq 'mm'; 2193 undef, ($peercidr, 'm', $prime, $prime) ) if $binfo->{type} eq 'mm'; 2194 # capture block for return 2195 push @retlist, { block => $peercidr, mtype => $disp_alloctypes{$peertype} }; 2166 2196 } 2167 2197 if ($args{scope} eq 'clearall') { … … 2182 2212 } elsif ($args{scope} eq 'mergepeer') { # should this just be an else? 2183 2213 # Default case. Merge "peer" blocks, but keep all suballocations 2214 # snag the new parent info for the return list 2215 push @retlist, {block => "$newblock", type => $disp_alloctypes{$args{newtype}}, id => $prime}; 2184 2216 my $substh = $dbh->prepare("UPDATE allocations SET parent_id = ? WHERE parent_id = ?"); 2185 2217 my $delsth = $dbh->prepare("DELETE FROM allocations WHERE id = ?"); … … 2202 2234 $binfo->{master_id}) if $peertype =~ /.[enr]/; 2203 2235 # Convert pool IPs into allocations or aggregated free blocks 2204 _poolToAllocations($dbh, $peerfull, $pinfo, newparent => $prime) if $peertype =~ /.[dp] ;2236 _poolToAllocations($dbh, $peerfull, $pinfo, newparent => $prime) if $peertype =~ /.[dp]/; 2205 2237 # Fix up master_id on free blocks if we're merging a master block 2206 2238 $mfbsth->execute($binfo->{master_id}, $m_id) if $peertype eq 'mm'; 2239 # capture block for return 2240 push @retlist, { block => $peercidr, mtype => $disp_alloctypes{$peertype} }; 2207 2241 } # merge peers 2208 2242 # update the primary allocation info. Do this last so we don't stomp extra data-retrieval in the loop above -
trunk/cgi-bin/main.cgi
r727 r733 1221 1221 $page->param(typelist => getTypeList($ip_dbh, 'n', $binfo->{type})); # down the rabbit hole we go... 1222 1222 1223 # Strings for scope; do this way so we don't have to edit them many places 1224 $page->param(vis_keepall => $merge_display{keepall}); 1225 $page->param(vis_mergepeer => $merge_display{mergepeer}); 1226 $page->param(vis_clearpeer => $merge_display{clearpeer}); 1227 $page->param(vis_clearall => $merge_display{clearall}); 1228 1223 1229 # Tree navigation 1224 1230 my $crumbs = getBreadCrumbs($ip_dbh, $binfo->{parent_id}); … … 1265 1271 $page->param(mergefree => $fb_list); 1266 1272 1267 ##fixme: push this up the stack somewhere so the labels can be fed to the relevant templates when/as needed 1268 # scope 1269 my %merge_friendly = ( 1270 keepall => "Keep mergeable allocations as suballocations of new block", 1271 mergepeer => "Keep suballocations of mergeable allocations", 1272 clearpeer => "Keep only suballocations of $binfo->{block}", 1273 clearall => "Clear all suballocations" 1274 ); 1275 $page->param(vis_scope => $merge_friendly{$webvar{scope}}); 1273 $page->param(vis_scope => $merge_display{$webvar{scope}}); 1276 1274 $page->param(scope => $webvar{scope}); 1277 1275 } # confMerge()
Note:
See TracChangeset
for help on using the changeset viewer.