View Issue Details

IDProjectCategoryView StatusLast Update
321RackTablesdefaultpublic2012-01-29 07:06
Reporteruser126Assigned Touser145 
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Version0.17.9 
Fixed in Version0.17.11 
Summary321: Adding multiple interfaces via web
Descriptionas I wrote to racktables-users, this is a small patch to have an easy way to add multiple interfaces (of the same type) to an object.

This patch is a quick'n'dirty one.
Needs to be improved in error handling and return codes.
I tried to stay as close to your coding as possible.

I would prefer to insert all ports within one database transaction and rollback if the creation of one port fails.
But this would require mysql innodb tables, which racktables doesn't at the moment. and also a major rewrite of database.php, since write locking a table commits a started transaction.

Please have a look.
TagsNo tags attached.

Activities

2010-03-18 22:44

 

racktables-addmanyports.diff (5,761 bytes)   
diff -Nurd RackTables-0.17.9.orig//inc/database.php RackTables-0.17.9-multi//inc/database.php
--- RackTables-0.17.9.orig//inc/database.php	2010-02-11 18:54:06.000000000 +0100
+++ RackTables-0.17.9-multi//inc/database.php	2010-03-18 21:29:56.000000000 +0100
@@ -2962,6 +2962,24 @@
 	return $ret;
 }
 
+function commitAddManyPorts ($object_id = 0, $port_name = '', $port_type_id = 0 , $port_label = '', $port_numbering_start = 0, $port_numbering_count = 0)
+{
+
+	if ($object_id == 0 or $port_type_id == 0 or $port_name == '' or $port_numbering_count == 0)
+	{
+		showError ('Invalid arguments', __FUNCTION__);
+		//echo "o_id: $object_id; type: $port_type_id; port_name: $port_name; count: $port_numbering_count";
+		die;
+	}
+	$ret = TRUE;
+	for ($i=0,$c=$port_numbering_start; $i<=$port_numbering_count; $i++,$c++)
+		$ret = $ret and '' == commitAddPort ($object_id, @sprintf($port_name,$c), $port_type_id, @sprintf($port_label,$c), '');
+                //echo "commitAddPort ($object_id, @sprintf($port_name,$i), $port_type_id,'', '');";
+	return ($ret?'':"Failed");
+
+
+}
+
 // Return only implicitly listed tags, the rest of the chain will be
 // generated/deducted later at higher levels.
 // Result is a chain: randomly indexed taginfo list.
diff -Nurd RackTables-0.17.9.orig//inc/interface.php RackTables-0.17.9-multi//inc/interface.php
--- RackTables-0.17.9.orig//inc/interface.php	2010-02-11 18:54:06.000000000 +0100
+++ RackTables-0.17.9-multi//inc/interface.php	2010-03-18 21:12:33.000000000 +0100
@@ -1100,11 +1100,9 @@
 		echo "<td colspan=3>&nbsp;</td><td>";
 		printImageHREF ('add', 'add a port', TRUE, 104);
 		echo "</td></tr></form>";
+
 	}
-	if (getConfigVar('ENABLE_MULTIPORT_FORM') == 'yes')
-		startPortlet ('Ports and interfaces');
-	else
-		echo '<br>';
+	startPortlet ('Ports and interfaces');
 	$object = spotEntity ('object', $object_id);
 	amplifyCell ($object);
 	echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
@@ -1199,8 +1197,26 @@
 	if (getConfigVar ('ADDNEW_AT_TOP') != 'yes')
 		printNewItemTR ($prefs);
 	echo "</table><br>\n";
-	if (getConfigVar('ENABLE_MULTIPORT_FORM') == 'yes')
-		finishPortlet();
+	finishPortlet();
+
+	startPortlet ('Add many Ports');
+
+	echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
+	echo "<tr><th>&nbsp;</th><th class=tdleft>Local name</th><th class=tdleft>Visible label</th><th class=tdleft>Interface</th><th class=tdleft>Start Number</th>";
+	echo "<th class=tdleft>Count</th><th>&nbsp;</th></tr>\n";
+	printOpFormIntro ('addManyPorts');
+	echo "<tr><td>";
+	printImageHREF ('add', 'add ports', TRUE);
+	echo "</td><td><input type=text size=8 name=port_name tabindex=105></td>\n";
+	echo "<td><input type=text name=port_label tabindex=106></td><td>";
+	printNiftySelect (getNewPortTypeOptions(), array ('name' => 'port_type_id', 'tabindex' => 107), $prefs['selected']);
+	echo "<td><input type=text name=port_numbering_start tabindex=108 size=3 maxlength=3></td>\n";
+	echo "<td><input type=text name=port_numbering_count tabindex=109 size=3 maxlength=3></td>\n";
+	echo "<td>&nbsp;</td><td>";
+	printImageHREF ('add', 'add ports', TRUE, 110);
+	echo "</td></tr></form>";
+	echo "</table><br>\n";
+
 	if (getConfigVar('ENABLE_MULTIPORT_FORM') != 'yes')
 		return;
 
@@ -1427,6 +1443,7 @@
 				79 => array ('code' => 'success', 'format' => 'Rack "%s" was deleted successfully'),
 				80 => array ('code' => 'success', 'format' => "Added new object '%s'"),
 				81 => array ('code' => 'success', 'format' => "SNMP: completed '%s' work"),
+				82 => array ('code' => 'success', 'format' => "Ports have been created successfully"),
 
 // records 100~199 with fatal error messages
 				100 => array ('code' => 'error', 'format' => '%s'),
diff -Nurd RackTables-0.17.9.orig//inc/navigation.php RackTables-0.17.9-multi//inc/navigation.php
--- RackTables-0.17.9.orig//inc/navigation.php	2010-02-11 18:54:06.000000000 +0100
+++ RackTables-0.17.9-multi//inc/navigation.php	2010-03-18 20:46:45.000000000 +0100
@@ -114,6 +114,7 @@
 $trigger['object']['tags'] = 'trigger_tags';
 $ophandler['object']['rackspace']['updateObjectAllocation'] = 'updateObjectAllocation';
 $ophandler['object']['ports']['addPort'] = 'addPortForObject';
+$ophandler['object']['ports']['addManyPorts'] = 'addManyPortsForObject';
 $ophandler['object']['ports']['delPort'] = 'delPortFromObject';
 $ophandler['object']['ports']['editPort'] = 'editPortForObject';
 $ophandler['object']['ports']['linkPort'] = 'linkPortForObject';
diff -Nurd RackTables-0.17.9.orig//inc/ophandlers.php RackTables-0.17.9-multi//inc/ophandlers.php
--- RackTables-0.17.9.orig//inc/ophandlers.php	2010-02-11 18:54:06.000000000 +0100
+++ RackTables-0.17.9-multi//inc/ophandlers.php	2010-03-18 21:16:26.000000000 +0100
@@ -2039,5 +2039,24 @@
 	return buildRedirectURL (__FUNCTION__, 'ERR');
 
 }
+$msgcode['addManyPortsForObject']['OK'] = 82;
+$msgcode['addManyPortsForObject']['ERR1'] = 101;
+$msgcode['addManyPortsForObject']['ERR2'] = 100;
+function addManyPortsForObject ()
+{
+	assertUIntArg ('object_id', __FUNCTION__);
+	assertStringArg ('port_name', __FUNCTION__, TRUE);
+	assertStringArg ('port_label', __FUNCTION__, TRUE);
+	assertUIntArg('port_numbering_start', __FUNCTION__);
+	assertUIntArg('port_numbering_count', __FUNCTION__);
+	if (!strlen ($_REQUEST['port_name']))
+		return buildRedirectURL (__FUNCTION__, 'ERR1');
+	$error = commitAddManyPorts ($_REQUEST['object_id'], $_REQUEST['port_name'], $_REQUEST['port_type_id'], $_REQUEST['port_label'], $_REQUEST['port_numbering_start'], $_REQUEST['port_numbering_count']);
+	if ($error != '')
+		return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error));
+	else
+		return buildRedirectURL (__FUNCTION__, 'OK' );
+}
+
 
 ?>
racktables-addmanyports.diff (5,761 bytes)   
infrastation

infrastation

2010-03-23 15:09

administrator   ~0000035

Let me have some time to review this. I will update later.

user144

2010-04-29 19:02

  ~0000054

This is huge. With the lack of support for the 6509 and 4500 Cisco chassis, it takes forever to add ports to these objects.

user145

2010-05-13 19:05

  ~0000076

I have grabbed this and reviewed the code. I see this as a boon for things not included with the snmp discovery. I should have it in the trunk today.

user145

2010-05-14 01:29

  ~0000078

merged with the trunk for 0.18 and there are no dependencies on 0.18 so it is merged with 0.17.11
adoom42

adoom42

2012-01-29 07:06

administrator   ~0000553

Reminder sent to: user126

RackTables uses InnoDB for all tables now. Please consider adding support for transactions and rollback as you previously mentioned.

Issue History

Date Modified Username Field Change
2010-03-18 22:44 user126 New Issue
2010-03-18 22:44 user126 File Added: racktables-addmanyports.diff
2010-03-23 15:08 infrastation Status new => assigned
2010-03-23 15:08 infrastation Assigned To => infrastation
2010-03-23 15:09 infrastation Note Added: 0000035
2010-03-23 16:34 infrastation Assigned To infrastation =>
2010-03-23 16:34 infrastation Status assigned => acknowledged
2010-04-29 19:02 user144 Note Added: 0000054
2010-05-12 14:31 user145 Status acknowledged => assigned
2010-05-12 14:31 user145 Assigned To => user145
2010-05-13 19:05 user145 Note Added: 0000076
2010-05-14 01:29 user145 Note Added: 0000078
2010-05-14 01:29 user145 Status assigned => resolved
2010-05-14 01:29 user145 Fixed in Version => 0.17.11
2010-05-14 01:29 user145 Resolution open => fixed
2010-07-07 13:15 infrastation Category Interface => Database - core
2010-11-29 13:21 infrastation Status resolved => closed
2012-01-29 07:06 adoom42 Note Added: 0000553