corrected behavior of Add Interface button. PlekitForm strips url of arguments,
[plewww.git] / planetlab / common / actions.php
index dabfc81..f7d77df 100644 (file)
@@ -49,12 +49,16 @@ $known_actions []= "delete-node";
 //     expects:        node_id
 $known_actions []= "update-node";      
 //     expects:        node_id, hostname, model
+$known_actions []= "attach-pcu";
+//     expects:        node_id, pcu_id, port (pcu_id <0 means detach)
 
 //////////////////////////////////////// interfaces
 $known_actions []= "delete-interfaces";        
 //     expects:        interface_ids
 $known_actions []="add-interface";
 //     expects:        node_id & interface details
+$known_actions []="new-interface";
+//     expects:        node_id 
 $known_actions []="update-interface";
 //     expects:        interface_id & interface details
 
@@ -314,11 +318,12 @@ switch ($action) {
  }
 
  case 'update-node': {
+   $node_id=intval($_POST['node_id']);
    $hostname= $_POST['hostname'];
    $model= $_POST['model'];
 
    $fields= array( "hostname"=>$hostname, "model"=>$model );
-   $api->UpdateNode( intval( $node_id ), $fields );
+   $api->UpdateNode( $node_id, $fields );
    $error= $api->error();
 
    if( empty( $error ) ) {
@@ -330,6 +335,35 @@ switch ($action) {
    break;
  }
 
+ // this code will ensure that at most one PCU gets attached to the node
+ case 'attach-pcu': {
+   $node_id=intval($_POST['node_id']);
+   $pcu_id=intval($_POST['pcu_id']);
+   $port=intval($_POST['port']);
+   // always start with deleting former PCUs
+   $nodes = $api->GetNodes(array($node_id),array('pcu_ids'));
+   $former_pcu_ids = $nodes[0]['pcu_ids'];
+   if ($former_pcu_ids) foreach ($former_pcu_ids as $former_pcu_id) {
+       if ($api->DeleteNodeFromPCU($node_id,$former_pcu_id) == 1) 
+        drupal_set_message ('Detached node ' . $node_id . ' from PCU ' . $pcu_id);
+       else 
+        drupal_set_error ('Could not detach node ' . $node_id . ' from PCU ' . $pcu_id);
+     }
+   // re-attach only if provided pcu_id >=0
+   if ($pcu_id >= 0) {
+     if ($api->AddNodeToPCU($node_id,$pcu_id,$port) == 1)
+       drupal_set_message ('Attached node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
+     else
+       drupal_set_error ('Failed to attach node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
+   } else {
+     drupal_set_message ('Detached node from all PCUs');
+   }
+   
+   plc_redirect(l_node($node_id));
+   break;
+ }
+   
+
 //////////////////////////////////////////////////////////// interfaces
  case 'delete-interfaces' : {
    $interface_ids=$_POST['interface_ids'];
@@ -351,7 +385,9 @@ 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'];
    foreach ($interface_details as $field) {
@@ -434,6 +470,9 @@ switch ($action) {
      $fields['login_base'] = $_POST['login_base'];
    if ($_POST['max_slices']) 
      $fields['max_slices'] = intval($_POST['max_slices']);
+   if (isset($_POST['enabled'])) {
+     $fields['enabled'] = (bool)$_POST['enabled'];
+   }
    
    $retcod=$api->UpdateSite( intval( $site_id ), $fields );
    if ($retcod == 1)