r1482 + getVServiceInfo() seems to be working
authorDenis Ovsienko <infrastation@yandex.ru>
Fri, 11 Jan 2008 12:08:40 +0000 (12:08 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Fri, 11 Jan 2008 12:08:40 +0000 (12:08 +0000)
+ renderVirtualService() looks much better

inc/database.php
inc/interface.php

index 6d152e1..0d3aaec 100644 (file)
@@ -2011,28 +2011,50 @@ function getSLBSummary ()
 function getVServiceInfo ($vsid = 0)
 {
        global $dbxlink;
-       $query = "select inet_ntoa(vip) as vip, vport, proto, name, vsconfig, default_rsconfig, " .
-               "rs.id as rsid, inet_ntoa(rs.rsip) as rsip, rsport as rsport from " .
-               "IPVirtualService as vs inner join IPRealServer as rs on vs.vsid = rs.vsid " .
-               "where vs.vsid = ${vsid} order by rsip, rsport";
-       $result = $dbxlink->query ($query);
-       if ($result == NULL)
+       $query1 = "select inet_ntoa(vip) as vip, vport, proto, name, vsconfig, rsconfig " .
+               "from IPVirtualService where id = ${vsid}";
+       $result1 = $dbxlink->query ($query1);
+       if ($result1 == NULL)
        {
-               showError ('SQL query failed', __FUNCTION__);
+               showError ('SQL query #1 failed', __FUNCTION__);
                return NULL;
        }
        $vsinfo = array ();
-       while ($row = $result->fetch (PDO::FETCH_ASSOC))
+       $row = $result1->fetch (PDO::FETCH_ASSOC);
+       if (!$row)
+               return NULL;
+       foreach (array ('vip', 'vport', 'proto', 'name', 'vsconfig', 'rsconfig') as $cname)
+               $vsinfo[$cname] = $row[$cname];
+       $vsinfo['rspool'] = array();
+       $result1->closeCursor();
+       $query2 = "select pool.id, name, pool.vsconfig, pool.rsconfig, object_id, " .
+               "lb.vsconfig as lb_vsconfig, lb.rsconfig as lb_rsconfig from " .
+               "IPRSPool as pool left join IPLoadBalancer as lb on pool.id = lb.rspool_id " .
+               "where vs_id = ${vsid} order by pool.name, object_id";
+       $result2 = $dbxlink->query ($query2);
+       if ($result2 == NULL)
        {
-               if (!isset ($vsinfo['vip']))
+               showError ('SQL query #2 failed', __FUNCTION__);
+               return NULL;
+       }
+       while ($row = $result2->fetch (PDO::FETCH_ASSOC))
+       {
+               if (!isset ($vsinfo['rspool'][$row['id']]))
                {
-                       foreach (array ('vip', 'vport', 'proto', 'name', 'vsconfig', 'default_rsconfig') as $cname)
-                               $vsinfo[$cname] = $row[$cname];
-                       $vsinfo['rslist'] = array();
+                       $vsinfo['rspool'][$row['id']]['name'] = $row['name'];
+                       $vsinfo['rspool'][$row['id']]['vsconfig'] = $row['vsconfig'];
+                       $vsinfo['rspool'][$row['id']]['rsconfig'] = $row['rsconfig'];
+                       $vsinfo['rspool'][$row['id']]['lblist'] = array();
                }
-               $vsinfo['rslist'][] = array ('rsid' => $row['rsid'], 'rsip' => $row['rsip'], 'rsport' => $row['rsport']);
+               if ($row['object_id'] == NULL)
+                       continue;
+               $vsinfo['rspool'][$row['id']]['lblist'][$row['object_id']] = array
+               (
+                       'vsconfig' => $row['lb_vsconfig'],
+                       'rsconfig' => $row['lb_rsconfig']
+               );
        }
-       $result->closeCursor();
+       $result2->closeCursor();
        return $vsinfo;
 }
 
index 5d9a486..1bbd045 100644 (file)
@@ -1670,13 +1670,13 @@ function renderAddressspace ()
                        foreach ($lblist as $lb_object_id)
                        {
                                echo '<td>';
-                               if (!count ($vsdata['lblist']))
+                               if (!isset ($vsdata['lblist'][$lb_object_id]))
                                        echo '&nbsp;';
                                else
                                        foreach ($vsdata['lblist'][$lb_object_id] as $pool_id => $pool_info)
                                        {
                                                echo $pool_info['size'] . "@(<a href='${root}?page=rspool&id=${pool_id}'>";
-                                               echo $pool_info['name'] . '</a>)';
+                                               echo $pool_info['name'] . '</a>)';
                                        }
                                echo '</td>';
                        }
@@ -3624,9 +3624,6 @@ function renderVirtualService ($vsid = 0)
                return;
        }
        $vsinfo = getVServiceInfo ($vsid);
-#echo '<pre>';
-#print_r ($vsinfo);
-#echo '</pre>';
        echo '<table border=0 class=objectview cellspacing=0 cellpadding=0>';
        if (!empty ($vsinfo['name']))
                echo "<tr><td colspan=2 align=center><h1>${vsinfo['name']}</h1></td></tr>\n";
@@ -3640,41 +3637,70 @@ function renderVirtualService ($vsid = 0)
        echo "<tr><th width='50%' class=tdright>Protocol:</th><td class=tdleft>${vsinfo['proto']}</td></tr>\n";
        echo "<tr><th width='50%' class=tdright>Virtual IP address:</th><td class=tdleft><a href='${root}?page=ipaddress&tab=default&ip=${vsinfo['vip']}'>${vsinfo['vip']}</a></td></tr>\n";
        echo "<tr><th width='50%' class=tdright>Virtual port:</th><td class=tdleft>${vsinfo['vport']}</td></tr>\n";
+       if (!empty ($vsinfo['vsconfig']))
+       {
+               echo "<tr><th width='50%' class=tdright>VS configuration:</th><td class=tdleft>&nbsp;</td></tr>\n";
+               echo "<tr><td class=tdleft colspan=2><pre>${vsinfo['vsconfig']}</pre></td></tr>\n";
+       }
+       if (!empty ($vsinfo['rsconfig']))
+       {
+               echo "<tr><th width='50%' class=tdright>RS configuration:</th><td class=tdleft>&nbsp;</td></tr>\n";
+               echo "<tr><td class=tdleft colspan=2><pre>${vsinfo['rsconfig']}</pre></td></tr>\n";
+       }
        echo "</table>\n";
        finishPortlet ();
        echo '</td>';
 
-       echo '<td class=pcright rowspan=3>';
+       echo '<td class=pcright>';
        startPortlet ('Backend');
-       echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
-       echo "<tr><th>Real IP address</th><th>Real port</th><th>[LBs]</tr>\n";
-       foreach ($vsinfo['rslist'] as $rsinfo)
-       {
-               echo "<tr><td><a href='${root}?page=ipaddress&tab=default&ip=${rsinfo['rsip']}'>${rsinfo['rsip']}</a></td>";
-               echo "<td>${rsinfo['rsport']}</td>";
-               echo "<td>[LB config]</td></tr>";
+       echo "<table cellspacing=0 cellpadding=5 align=center border=1>\n";
+       echo "<tr><th>real server pool</th><th>load balancers</th></tr>\n";
+       foreach ($vsinfo['rspool'] as $pool_id => $poolInfo)
+       {
+               echo '<tr><td class=tdleft>';
+               // Pool info
+               echo '<table width=100%>';
+               echo "<tr><td colspan=2><a href='${root}?page=rspool&id=${pool_id}'>";
+               if (!empty ($poolInfo['name']))
+                       echo $poolInfo['name'];
+               else
+                       echo 'ANONYMOUS';
+               echo "</a></td></tr>";
+               if (!empty ($poolInfo['vsconfig']))
+                       echo "<tr><th>VS config</th><td><pre>${poolInfo['vsconfig']}</pre></td></tr>";
+               if (!empty ($poolInfo['rsconfig']))
+                       echo "<tr><th>RS config</th><td><pre>${poolInfo['rsconfig']}</pre></td></tr>";
+               echo '</table>';
+               echo '</td><td>';
+               // LB list
+               if (!count ($poolInfo['lblist']))
+                       echo 'none';
+               else
+               {
+                       echo '<table width=100%>';
+                       foreach ($poolInfo['lblist'] as $object_id => $lbInfo)
+                       {
+                               // FIXME: dname should be cached
+                               $oi = getObjectInfo ($object_id);
+                               echo "<tr><td colspan=2><a href='${root}?page=object&object_id=${object_id}'>";
+                               echo $oi['dname'] . '</a></td></tr>';
+                               if (!empty ($lbInfo['vsconfig']))
+                                       echo "<tr><th>VS config</th><td><pre>${lbInfo['vsconfig']}</pre></td></tr>";
+                               if (!empty ($lbInfo['rsconfig']))
+                                       echo "<tr><th>RS config</th><td><pre>${lbInfo['rsconfig']}</pre></td></tr>";
+                       }
+                       echo '</table>';
+               }
+               echo "</td></tr>\n";
        }
        echo "</table>\n";
        finishPortlet ();
        echo '</td>';
 
-       echo "</tr>\n<tr>";
-
-       echo '<td>';
-       startPortlet ('Virtual service configuration');
-       echo "<pre>${vsinfo['vsconfig']}</pre>";
-       finishPortlet ();
-       echo '</td>';
-
-       echo "</tr>\n<tr>";
-
-       echo '<td>';
-       startPortlet ('Default real server configuration');
-       echo "<pre>${vsinfo['default_rsconfig']}</pre>";
-       finishPortlet ();
-       echo '</td>';
-
        echo '</tr><table>';
+#echo '<pre>';
+#print_r ($vsinfo);
+#echo '</pre>';
 }
 
 function renderProgressBar ($percentage = 0)