r3032 - maintenance->trunk sync of changesets 3019,3030,3031
authorDenis Ovsienko <infrastation@yandex.ru>
Tue, 4 Aug 2009 09:37:06 +0000 (09:37 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Tue, 4 Aug 2009 09:37:06 +0000 (09:37 +0000)
ChangeLog
inc/database.php
inc/interface.php

index 4103bd3bed9750c76cbe35c6c12a8985d66f31a3..763773f31fb625a8efa8e062e0a705472b4da2f3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
        update: even better search function (ticket:20)
        new feature: tags quick list on "Tags" tab (ticket:259)
        bugfix: removed PHP warnings on "Rackspace" tab
+       bugfix: improve usage counters for IPv4 networks
        bugfix: rack row removal sometimes failed (by Marcin Suchocki)
 0.17.2 2009-07-22
        new feature: configure default SNMP community (by jthurman)
index 19004ede4126897dafd15cc574689ba1461946ee..e6c7d24e9808afa09ae262ad5964ee9ee90b274e 100644 (file)
@@ -52,6 +52,7 @@ $SQLSchema = array
                        'mask' => 'mask',
                        'name' => 'name',
                        'comment' => 'comment',
+                       'parent_id' => '(SELECT id FROM IPv4Network AS subt WHERE IPv4Network.ip & (4294967295 >> (32 - subt.mask)) << (32 - subt.mask) = subt.ip and subt.mask < IPv4Network.mask ORDER BY subt.mask DESC limit 1)',
                ),
                'keycolumn' => 'id',
                'ordcolumns' => array ('ip', 'mask'),
@@ -420,9 +421,6 @@ function amplifyCell (&$record, $dummy = NULL)
                $record['ipv4rspools'] = getRSPoolsForObject ($record['id']);
                $record['files'] = getFilesOfEntity ($record['realm'], $record['id']);
                break;
-       case 'ipv4net':
-               $record['parent_id'] = getIPv4AddressNetworkId ($record['ip'], $record['mask']);
-               break;
        case 'file':
                $record['links'] = getFileLinks ($record['id']);
                break;
index bdca27164ee780b9d54428dc198abc4206ebda24..8130aa108a76f8357e183d727ba2e0166e825400 100644 (file)
@@ -1905,17 +1905,16 @@ function renderIPv4SpaceRecords ($tree, $baseurl, $target = 0, $level = 1)
        $self = __FUNCTION__;
        foreach ($tree as $item)
        {
-               $total = $item['addrt'];
                if (getConfigVar ('IPV4_TREE_SHOW_USAGE') == 'yes')
-               {
                        loadIPv4AddrList ($item); // necessary to compute router list and address counter
-                       $used = $item['addrc'];
-               }
                else
                {
                        $item['addrlist'] = array();
                        $item['addrc'] = 0;
                }
+               $used = $item['addrc'];
+               $maxdirect = $item['addrt'];
+               $maxtotal = binInvMaskFromDec ($item['mask']) + 1;
                if (isset ($item['id']))
                {
                        if ($item['symbol'] == 'node-collapsed')
@@ -1931,11 +1930,11 @@ function renderIPv4SpaceRecords ($tree, $baseurl, $target = 0, $level = 1)
                                echo "<a name=netid${target}></a>";
                        if (getConfigVar ('IPV4_TREE_SHOW_USAGE') == 'yes')
                        {
-                               renderProgressBar ($total ? $used/$total : 0);
-                               echo "<br><small>${used}/${total}</small>";
+                               renderProgressBar ($maxdirect ? $used/$maxdirect : 0);
+                               echo "<br><small>${used}/${maxdirect}" . ($maxdirect == $maxtotal ? '' : "/${maxtotal}") . '</small>';
                        }
                        else
-                               echo "<small>${total}</small>";
+                               echo "<small>${maxdirect}</small>";
                        echo "</td>";
                        if (getConfigVar ('EXT_IPV4_VIEW') == 'yes')
                                printRoutersTD (findRouters ($item['addrlist']));
@@ -1950,11 +1949,11 @@ function renderIPv4SpaceRecords ($tree, $baseurl, $target = 0, $level = 1)
                        echo "<td class=tdcenter>";
                        if (getConfigVar ('IPV4_TREE_SHOW_USAGE') == 'yes')
                        {
-                               renderProgressBar ($used/$total, 'sparenetwork');
-                               echo "<br><small>${used}/${total}</small>";
+                               renderProgressBar ($used/$maxtotal, 'sparenetwork');
+                               echo "<br><small>${used}/${maxtotal}</small>";
                        }
                        else
-                               echo "<small>${total}</small>";
+                               echo "<small>${maxtotal}</small>";
                        echo "</td><td>&nbsp;</td></tr>";
                }
        }
@@ -2107,10 +2106,22 @@ function renderIPv4SpaceEditor ()
        {
                startPortlet ('Manage existing (' . count ($addrspaceList) . ')');
                echo "<table class='widetable' border=0 cellpadding=5 cellspacing=0 align='center'>\n";
-               echo "<tr><th>&nbsp;</th><th>prefix</th><th>name</th></tr>";
+               echo "<tr><th>&nbsp;</th><th>prefix</th><th>name</th><th>capacity</th></tr>";
+               if (getConfigVar ('IPV4_JAYWALK') != 'yes')
+               {
+                       array_walk ($addrspaceList, 'amplifyCell');
+                       $tree = prepareIPv4Tree ($addrspaceList, 'ALL');
+                       // this is only called for having "trace" set
+                       treeFromList ($addrspaceList);
+               }
                foreach ($addrspaceList as $netinfo)
                {
-                       amplifyCell ($netinfo);
+                       $netinfo = peekNode ($tree, $netinfo['trace'], $netinfo['id']);
+                       // now we have all subnets listed in netinfo
+                       loadIPv4AddrList ($netinfo);
+                       $used = $netinfo['addrc'];
+                       $maxdirect = $netinfo['addrt'];
+                       $maxtotal = binInvMaskFromDec ($netinfo['mask']) + 1;
                        echo "<tr valign=top><td>";
                        if (getConfigVar ('IPV4_JAYWALK') == 'yes')
                        {
@@ -2120,7 +2131,6 @@ function renderIPv4SpaceEditor ()
                        }
                        else // only render clickable image for empty networks
                        {
-                               loadIPv4AddrList ($netinfo);
                                if (count ($netinfo['addrlist']))
                                        printImageHREF ('nodestroy', 'There are ' . count ($netinfo['addrlist']) . ' allocations inside');
                                else
@@ -2133,7 +2143,10 @@ function renderIPv4SpaceEditor ()
                        }
                        echo '</td><td class=tdleft><a href="' . makeHref (array ('page' => 'ipv4net', 'id' => $netinfo['id'])) . '">';
                        echo "${netinfo['ip']}/${netinfo['mask']}</a></td>";
-                       echo '<td class=tdleft>' . htmlspecialchars ($netinfo['name']) . '</td></tr>';
+                       echo '<td class=tdleft>' . htmlspecialchars ($netinfo['name']) . '</td><td>';
+                       renderProgressBar ($maxdirect ? $used/$maxdirect : 0);
+                       echo "<br><small>${used}/${maxdirect}" . ($maxdirect == $maxtotal ? '' : "/${maxtotal}") . '</small></td>';
+                       echo '</tr>';
                }
                echo "</table>";
                finishPortlet();