r1723 + getAutoPorts(): new function to hold AutoPorts kitchen in one place
authorDenis Ovsienko <infrastation@yandex.ru>
Mon, 25 Feb 2008 11:43:18 +0000 (11:43 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Mon, 25 Feb 2008 11:43:18 +0000 (11:43 +0000)
+ initial AutoPorts dynamic tab code

inc/database.php
inc/functions.php
inc/interface.php
inc/navigation.php
inc/triggers.php

index 89cc1500b186f5e0787c5e10b99f338ca037c808..7de7535ba6330a857e7a67f2672eb01637d40681 100644 (file)
@@ -2652,29 +2652,8 @@ function executeAutoPorts ($object_id = 0, $type_id = 0)
                showError ('Invalid arguments', __FUNCTION__);
                die;
        }
-       $typemap = explode (';', str_replace (' ', '', getConfigVar ('AUTOPORTS_CONFIG')));
-       foreach ($typemap as $equation)
-       {
-               $tmp = explode ('=', $equation);
-               if (count ($tmp) != 2)
-                       continue;
-               $objtype_id = $tmp[0];
-               if ($objtype_id != $type_id)
-                       continue;
-               $portlist = $tmp[1];
-               foreach (explode ('+', $portlist) as $product)
-               {
-                       $tmp = explode ('*', $product);
-                       if (count ($tmp) != 3)
-                               continue;
-                       $nports = $tmp[0];
-                       $port_type = $tmp[1];
-                       $format = $tmp[2];
-                       for ($i = 0; $i < $nports; $i++)
-                               // format string might ignore the index
-                               commitAddPort ($object_id, @sprintf ($format, $i), $port_type, '', '');
-               }
-       }
+       foreach (getAutoPorts ($type_id) as $autoport)
+               commitAddPort ($object_id, $autoport['name'], $autoport['type'], '', '');
 }
 
 ?>
index f0212e2acc557279d58b5a39155ab00640ed3c2e..a9ee97868613fec67c7f45859ecc8f6ba1a5989a 100644 (file)
@@ -1204,4 +1204,34 @@ function email_regex_simple ()
        "\@((?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?))"; # @domain
 }
 
+// Parse AUTOPORTS_CONFIG and return a list of generated pairs (port_type, port_name)
+// for the requested object_type_id.
+function getAutoPorts ($type_id)
+{
+       $ret = array();
+       $typemap = explode (';', str_replace (' ', '', getConfigVar ('AUTOPORTS_CONFIG')));
+       foreach ($typemap as $equation)
+       {
+               $tmp = explode ('=', $equation);
+               if (count ($tmp) != 2)
+                       continue;
+               $objtype_id = $tmp[0];
+               if ($objtype_id != $type_id)
+                       continue;
+               $portlist = $tmp[1];
+               foreach (explode ('+', $portlist) as $product)
+               {
+                       $tmp = explode ('*', $product);
+                       if (count ($tmp) != 3)
+                               continue;
+                       $nports = $tmp[0];
+                       $port_type = $tmp[1];
+                       $format = $tmp[2];
+                       for ($i = 0; $i < $nports; $i++)
+                               $ret[] = array ('type' => $port_type, 'name' => @sprintf ($format, $i));
+               }
+       }
+       return $ret;
+}
+
 ?>
index 74447ddcca182e59d17cb4a7192ee97ff261770b..6940d29d5da70fb7809c7ae1ef0451d9fad13d49 100644 (file)
@@ -4473,4 +4473,9 @@ function renderLivePTR ($id = 0)
        echo "</td></tr></table>\n";
 }
 
+function renderAutoPortsForm ()
+{
+       dragon();
+}
+
 ?>
index 00bf17e783de63617136de57baa2721766e3a1de..e586a0da621e9fe391f01c3be140f41e50c2ab90 100644 (file)
@@ -76,6 +76,7 @@ $tab['object']['switchvlans'] = 'Live VLANs';
 $tab['object']['snmpportfinder'] = 'SNMP port finder';
 $tab['object']['slb'] = '[SLB]';
 $tab['object']['lvsconfig'] = 'LVS configuration';
+$tab['object']['autoports'] = 'AutoPorts';
 $tabhandler['object']['default'] = 'renderRackObject';
 $tabhandler['object']['edit'] = 'renderEditObjectForm';
 $tabhandler['object']['rackspace'] = 'renderRackSpaceForObject';
@@ -85,12 +86,14 @@ $tabhandler['object']['portfwrd'] = 'renderIPAddressPortForwarding';
 $tabhandler['object']['switchvlans'] = 'renderVLANMembership';
 $tabhandler['object']['snmpportfinder'] = 'renderSNMPPortFinder';
 $tabhandler['object']['lvsconfig'] = 'renderLVSConfig';
+$tabhandler['object']['autoports'] = 'renderAutoPortsForm';
 $trigger['object']['network'] = 'trigger_ipv4';
 $trigger['object']['portfwrd'] = 'trigger_natv4';
 $trigger['object']['switchvlans'] = 'trigger_switchvlans';
 $trigger['object']['snmpportfinder'] = 'trigger_snmpportfinder';
 $trigger['object']['slb'] = 'trigger_natv4';
 $trigger['object']['lvsconfig'] = 'trigger_lvsconfig';
+$trigger['object']['autoports'] = 'trigger_autoports';
 $ophandler['object']['ports']['addPort'] = 'addPortForObject';
 $ophandler['object']['ports']['delPort'] = 'delPortFromObject';
 $ophandler['object']['ports']['editPort'] = 'editPortForObject';
index a5309f3dcea1e8f099cbac6f779852c09173e9b5..e26e93a0e5ca96d0aa067a0604984cf64f989c0f 100644 (file)
@@ -87,4 +87,13 @@ function trigger_poolrscount ()
        return count ($poolInfo['rslist']) > 0;
 }
 
+function trigger_autoports ()
+{
+       assertUIntArg ('object_id');
+       if (count (getObjectPortsAndLinks ($_REQUEST['object_id'])) != 0)
+               return FALSE;
+       $info = getObjectInfo ($_REQUEST['object_id']);
+       return count (getAutoPorts ($info['objtype_id'])) != 0;
+}
+
 ?>