add a non-primary interface : user to select for virtual or physical interface (set...
[plewww.git] / planetlab / common / actions.php
index 66d6c0a..c93a326 100644 (file)
@@ -397,32 +397,46 @@ switch ($action) {
      drupal_set_error ("Could not delete all selected interfaces, only $counter were removed");
    plc_redirect(l_node($_POST['node_id']));
  }
+
  case 'new-interface': {
    plc_redirect(l_interface_add($_POST['node_id']));
  }
+
  case 'add-interface': {
-   $node_id=$_POST['node_id'];
+   $node_id=intval($_POST['node_id']);
    foreach ($interface_details as $field) {
      $interface[$field]= $_POST[$field];
+     // these must be integers
      if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
-       $interface[$field]= intval( $interface[$field] );
+       if ( empty ($interface[$field]) ) 
+        unset ($interface[$field]);
+       else 
+        $interface[$field]= intval( $interface[$field] );
      }
    }
-   $interface_id =$api->AddInterface( intval( $node_id ), $interface );
-   if ($interface_id >0 ) {
-     $api->begin();
-        $api->AddInterfaceTag($interface_id,"alias",strval($interface_id));
-        $api->AddInterfaceTag($interface_id,"ifname","eth0");
-     list($id1, $id2) = $api->commit();
-     if ( $id1 > 0 && $id2 > 0 ) {
-         drupal_set_message ("Interface $interface_id added into node $node_id");
-     } else {
-         drupal_set_error ("Could not add interface tags to interface $interface_id");
-     }
-   } else {
+   $interface_id =$api->AddInterface( $node_id , $interface );
+   if ($interface_id <= 0 ) {
      drupal_set_error ("Could not create interface");
+     drupal_set_error ($api->error());
+   } else {
+     $ip=$interface['ip'];
+     drupal_set_message ("Interface $ip added into node $node_id");
+     if ($_POST['is-virtual']) {
+       $ifname=$_POST['ifname'];
+       if ($api->AddInterfaceTag($interface_id,"ifname",$ifname) <= 0) 
+        drupal_set_error ("Could not set tag 'ifname'=$ifname");
+       else 
+        drupal_set_message ("Set tag 'ifname'=$ifname");
+       $alias=$_POST['alias'];
+       // deafult to interface_id
+       if ( ! $alias ) $alias=strval($interface_id);
+       if ($api->AddInterfaceTag($interface_id,"alias",$alias) <= 0) 
+        drupal_set_error ("Could not set tag 'alias'=$alias");
+       else 
+        drupal_set_message ("Set tag 'alias'=$alias");
+     }
    }
-   plc_redirect (l_node($node_id));
+   plc_redirect (l_node_interfaces($node_id));
  }
    
  case 'update-interface': {
@@ -825,9 +839,9 @@ Our support team will be glad to answer any question that you might have.
    }
    
    if ($node_mode)
-     plc_redirect (l_node($node_id));
+     plc_redirect (l_node_tags($node_id));
    else
-     plc_redirect (l_interface($interface_id));
+     plc_redirect (l_interface_tags($interface_id));
  }
 
  case 'delete-node-tags' : 
@@ -862,9 +876,9 @@ Our support team will be glad to answer any question that you might have.
    else
      drupal_set_error ("Could not delete all selected tags, only $counter were removed");
    if ($node_mode)
-     plc_redirect(l_node($_POST['node_id']));
+     plc_redirect(l_node_tags($_POST['node_id']));
    else
-     plc_redirect(l_interface($_POST['interface_id']));
+     plc_redirect(l_interface_tags($_POST['interface_id']));
  }
 
 //////////////////////////////////////// nodegroups