cleanup unused PLC_API_VERSION
[nodeconfig.git] / PlanetLabConf / bwlimit.php
index 3e3cbc9..a35bdeb 100755 (executable)
@@ -13,10 +13,21 @@ require_once 'plc_api.php';
 global $adm;
 
 // Look up the node
-$nodenetworks = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR']));
-if (!empty($nodenetworks)) {
-  if ($nodenetworks[0]['bwlimit'] !== NULL) {
-    $rate = $nodenetworks[0]['bwlimit'];
+// backwards compatibility with the old 4.2 API
+global $__PLC_API_VERSION;
+if ( ! method_exists ($adm,"GetInterfaces"))
+  $__PLC_API_VERSION = 4.2;
+else
+  $__PLC_API_VERSION = 4.3;
+
+if ($__PLC_API_VERSION==4.2)
+  $interfaces = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR']));
+else
+  $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR']));
+
+if (!empty($interfaces)) {
+  if ($interfaces[0]['bwlimit'] !== NULL) {
+    $rate = $interfaces[0]['bwlimit'];
     if ($rate >= 1000000000 && ($rate % 1000000000) == 0) {
       printf("%.0fgbit", ($rate / 1000000000.));
     } elseif ($rate >= 1000000 && ($rate % 1000000) == 0) {
@@ -31,4 +42,4 @@ if (!empty($nodenetworks)) {
   }
 }
 
-?>
\ No newline at end of file
+?>