r1680 + getIPAddress(): release PDO handle; return VS data for address
authorDenis Ovsienko <infrastation@yandex.ru>
Fri, 15 Feb 2008 13:22:07 +0000 (13:22 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Fri, 15 Feb 2008 13:22:07 +0000 (13:22 +0000)
+ renderIPAddress(): only render allocation data when necessary; render VS list same way

inc/functions.php
inc/interface.php

index 773dc3a0a516dd3dd056251a748b180b20652c08..26cc224e7a7dbd2f9be040c6e18cb75a44c66896 100644 (file)
@@ -548,29 +548,36 @@ function getIPAddress ($ip=0)
 {
        $ret = array();
        $ret['bonds'] = array();
+       // FIXME: below two aren't neither filled in with data nor rendered (ticket:23)
        $ret['outpf'] = array();
        $ret['inpf'] = array();
+       $ret['vslist'] = array();
+       $ret['rslist'] = array();
        $ret['exists'] = 0;
        $ret['name'] = '';
        $ret['reserved'] = 'no';
        global $dbxlink;
-       $query1 =
+       $query =
                "select ".
                "name, reserved ".
                "from IPAddress ".
                "where ip = INET_ATON('$ip') and (reserved = 'yes' or name != '')";
-       $result1 = $dbxlink->query ($query1);
-       if ($result1 == NULL)
+       $result = $dbxlink->query ($query);
+       if ($result == NULL)
+       {
+               showError ('Query #1 failed', __FUNCTION__);
                return NULL;
-       if ($row = $result1->fetch (PDO::FETCH_ASSOC))
+       }
+       if ($row = $result->fetch (PDO::FETCH_ASSOC))
        {
                $ret['exists'] = 1;
                $ret['name'] = $row['name'];
                $ret['reserved'] = $row['reserved'];
        }
-       $result1->closeCursor();
+       $result->closeCursor();
+       unset ($result);
 
-       $query2 =
+       $query =
                "select ".
                "IPBonds.object_id as object_id, ".
                "IPBonds.name as name, ".
@@ -582,9 +589,9 @@ function getIPAddress ($ip=0)
                "where IPBonds.ip=INET_ATON('$ip') ".
                "and chapter_name = 'RackObjectType' " .
                "order by RackObject.id, IPBonds.name";
-       $result2 = $dbxlink->query ($query2);
+       $result = $dbxlink->query ($query);
        $count=0;
-       while ($row = $result2->fetch (PDO::FETCH_ASSOC))
+       while ($row = $result->fetch (PDO::FETCH_ASSOC))
        {
                $ret['bonds'][$count]['object_id'] = $row['object_id'];
                $ret['bonds'][$count]['name'] = $row['name'];
@@ -597,7 +604,15 @@ function getIPAddress ($ip=0)
                $count++;
                $ret['exists'] = 1;
        }
-       $result2->closeCursor();
+       $result->closeCursor();
+       unset ($result);
+
+       $query = "select id, inet_ntoa(vip) as vip, vport, proto, name from IPVirtualService where vip = inet_aton('${ip}')";
+       $result = $dbxlink->query ($query);
+       while ($row = $result->fetch (PDO::FETCH_ASSOC))
+               $ret['vslist'][] = $row;
+       $result->closeCursor();
+       unset ($result);
 
        return $ret;
 }
index a7ee3512a81f8aa1d4c70305418f24ad9323f2d4..3163d547d016b69e34a5e2ee3a30da40bb235b91 100644 (file)
@@ -1909,46 +1909,59 @@ function renderIPAddress ()
 //     echo "<table width='100%' cesspadding=5 cellspacing=0 border=0 align='center'>";
 //     echo "<tr valign='top'><td>";
 
-       startPortlet ('Address assignment');
-       echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
-       echo "<tr><th>Object name</th><th>Interface name</th><th>Interface type</th></tr>\n";
-
        $numshared = countRefsOfType($address['bonds'], 'shared', 'eq');
        $numreg = countRefsOfType($address['bonds'], 'regular', 'eq');
        $numvirt = countRefsOfType($address['bonds'], 'virtual', 'eq');
 
-       
-       if ( ($numshared > 0 && $numreg > 0) || $numreg > 1 )
-               $class='trerror';
-       elseif ( $address['reserved'] == 'yes' and $numshared+$numreg+$numvirt > 0)
-               $class='trerror';
-       else
-               $class='';
-
+       if ($address['reserved'] == 'yes' or ($numshared + $numreg + $numvirt) > 0)
+       {
+               startPortlet ('Allocation');
+               echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
+               echo "<tr><th>Object name</th><th>Interface name</th><th>Interface type</th></tr>\n";
+               if ( ($numshared > 0 && $numreg > 0) || $numreg > 1 )
+                       $class='trerror';
+               elseif ( $address['reserved'] == 'yes' and $numshared+$numreg+$numvirt > 0)
+                       $class='trerror';
+               else
+                       $class='';
 
+               if ($address['reserved'] == 'yes')
+                       echo "<tr class='$class'><td colspan='3'><b>RESERVED</b></td></tr>";
+               foreach ($address['bonds'] as $bond)
+               {
+                       echo "<tr class='$class'><td><a href='${root}?page=object&object_id=${bond['object_id']}'>${bond['object_name']}</td><td>${bond['name']}</td><td><b>";
+                       switch ($bond['type'])
+                       {
+                               case 'virtual':
+                                       echo "Virtual";
+                                       break;
+                               case 'shared':
+                                       echo "Shared";
+                                       break;
+                               case 'regular':
+                                       echo "Regular";
+                                       break;
+                       }
+                       echo "</b></td></tr>\n";
+               }
+               echo "</table><br><br>";
+               finishPortlet();
+       }
 
-       if ($address['reserved'] == 'yes')
-               echo "<tr class='$class'><td colspan='3'><b>RESERVED</b></td></tr>";
-       foreach ($address['bonds'] as $bond)
+       if (count ($address['vslist']))
        {
-               echo "<tr class='$class'><td><a href='${root}?page=object&object_id=${bond['object_id']}'>${bond['object_name']}</td><td>${bond['name']}</td><td><b>";
-               switch ($bond['type'])
+               startPortlet ('Virtual services (' . count ($address['vslist']) . ')');
+               echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
+               echo "<tr><th>VS</th><th>name</th></tr>\n";
+               foreach ($address['vslist'] as $vsinfo)
                {
-                       case 'virtual':
-                               echo "Virtual";
-                               break;
-                       case 'shared':
-                               echo "Shared";
-                               break;
-                       case 'regular':
-                               echo "Regular";
-                               break;
+                       echo "<tr><td class=tdleft><a href='${root}?page=vservice&id=${vsinfo['id']}'>";
+                       echo buildVServiceName ($vsinfo) . "</a></td><td class=tdleft>";
+                       echo $vsinfo['name'] . "</td></tr>";
                }
-               echo "</b></td></tr>\n";
+               echo "</table><br><br>";
+               finishPortlet();
        }
-       echo "</table><br><br>";
-       finishPortlet();
-
 //     echo "</td><td>";
 //     echo "</td></tr></table>";
 }