X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetlab%2Fcommon%2Factions.php;h=b0466bdda7f830e7346b2aa78d7f36cd0f8139a3;hb=943aa87a34c6728e5c41db662dd70c08e9bdb7e4;hp=5f3994db2095fbc61591777c2bfac1bbae4593a5;hpb=638c7772a6ec67f3dea26d9bd2cd4fa2c3e479c6;p=plewww.git diff --git a/planetlab/common/actions.php b/planetlab/common/actions.php index 5f3994d..b0466bd 100644 --- a/planetlab/common/actions.php +++ b/planetlab/common/actions.php @@ -51,6 +51,8 @@ $known_actions []= "update-node"; // expects: node_id, hostname, model $known_actions []= "attach-pcu"; // expects: node_id, pcu_id, port (pcu_id <0 means detach) +$known_actions []= "reboot-node-with-pcu"; +// expects: node_id //////////////////////////////////////// interfaces $known_actions []= "delete-interfaces"; @@ -85,6 +87,9 @@ $known_actions []= 'remove-nodes-from-slice'; // expects: slice_id & node_ids $known_actions []= 'add-nodes-in-slice'; // expects: slice_id & node_ids +$known_actions []= 'update-initscripts'; +// expects: slice_id & name & previous-initscript & previous-initscript-body +// & initscript & initscript-body $known_actions []= 'delete-slice-tags'; // expects: slice_tag_id $known_actions []= 'add-slice-tag'; @@ -97,6 +102,10 @@ $known_actions []= "add-tag-type"; // expects: tag_type_id & tagname & description & category & min_role_id $known_actions []= "delete-tag-types"; // expects: tag_type_ids +$known_actions []= "remove-roles-from-tag-type"; +// expects: tag_type_id & role_ids +$known_actions []= "add-role-to-tag-type"; +// expects: tag_type_id_id & id //////////////////////////////////////// tags $known_actions []= "set-tag-on-node"; @@ -380,6 +389,22 @@ switch ($action) { plc_redirect(l_node($node_id)); break; } + + case 'reboot-node-with-pcu': { + $node_id=intval($_POST['node_id']); + $hostname= $_POST['hostname']; + + $ret = $api->RebootNodeWithPCU( $node_id ); + $error= $api->error(); + + if( empty( $error ) ) { + drupal_set_message("Reboot node $hostname: $ret"); + plc_redirect(l_node($node_id)); + } else { + drupal_set_error($error); + } + break; + } //////////////////////////////////////////////////////////// interfaces @@ -683,6 +708,49 @@ Our support team will be glad to answer any question that you might have. break; } + case 'update-initscripts': { +// expects: slice_id & name & previous-initscript & previous-initscript-body +// & initscript & initscript-body + $slice_id = intval ($_POST['slice_id']); + $previous_initscript=$_POST['previous-initscript']; + $initscript=$_POST['initscript']; + $previous_initscript_body=$_POST['previous-initscript-body']; + $initscript_body=$_POST['initscript-body']; + + $changes=FALSE; + if (strcmp($initscript,$previous_initscript) != 0) { + $newvalue=$api->SetSliceInitscript($slice_id,$initscript); + $status = (strcmp($newvalue,$initscript)==0) ? "OK" : "failed"; + if (! $initscript) drupal_set_message("Removed shared initscript '" . $previous_initscript . "' " . $status); + else drupal_set_message("Replaced shared initscript with '" . $initscript . "' " . $status); + $changes=TRUE; + } + + // somehow some \r chars make it here; just ignore them + $previous_initscript_body=str_replace("\r","",$previous_initscript_body); + // plc_debug_txt('previous initscript_body after cr',$previous_initscript_body); + + $initscript_body=str_replace("\r","",$initscript_body); + // make sure the script ends with a single \n + $initscript_body=trim($initscript_body); + if (!empty($initscript_body) && $initscript_body[strlen($initscript_body)-1] != "\n") + $initscript_body.="\n"; + // plc_debug_txt('initscript_body after cr & nl/eof',$initscript_body); + + if (strcmp($initscript_body,$previous_initscript_body) != 0) { + $newvalue=$api->SetSliceInitscriptBody($slice_id,$initscript_body); + // plc_debug_txt('newvalue',$newvalue); + $status=(strcmp($newvalue,$initscript_body)==0) ? "OK" : "failed"; + if (! $initscript_body) drupal_set_message("Removed initscript body " . $status); + else drupal_set_message("Installed new initscript body " . $status); + $changes=TRUE; + } + if (!$changes) drupal_set_message("No changes required in initscript"); + plc_redirect(l_slice($slice_id) . "&show_details=0&show_initscripts=1" ); + break; + } + + case 'delete-slice-tags': { $slice_id = intval($_POST['slice_id']); $slice_tag_ids = array_map("intval", $_POST['slice_tag_ids']); @@ -697,7 +765,7 @@ Our support team will be glad to answer any question that you might have. } if ($success) drupal_set_message ("Deleted $count slice tag(s)"); - plc_redirect(l_slice($slice_id) . "&show_tags=true" ); + plc_redirect(l_slice($slice_id) . "&show_tags=1" ); break; } @@ -797,6 +865,30 @@ Our support team will be glad to answer any question that you might have. break; } + case 'remove-roles-from-tag-type' : { + $tag_type_id=$_POST['tag_type_id']; + $role_ids=$_POST['role_ids']; + if ( ! $role_ids) { + drupal_set_error("You have not selected role(s) to remove"); + } else { + foreach( $role_ids as $role_id) + if ( $api->DeleteRoleFromTagType( intval( $role_id ), intval( $tag_type_id ) ) != 1 ) + drupal_set_error ("Could not remove role $role_id from tag type $tag_type_id"); + } + plc_redirect (l_tag_roles($tag_type_id)); + } + + case 'add-role-to-tag-type' : { + $tag_type_id=$_POST['tag_type_id']; + $role_id=$_POST['role_id']; + if ( ! $role_id) { + drupal_set_error ("You have not selected a role to add"); + } else if ($api->AddRoleToTagType( intval( $role_id ), intval( $tag_type_id ) ) != 1) { + drupal_set_error("Could not add role $role_id to tag $tag_type_id"); + } + plc_redirect (l_tag_roles($tag_type_id)); + } + //////////////////////////////////////// tags case 'set-tag-on-node': case 'set-tag-on-interface': { @@ -953,34 +1045,45 @@ Our support team will be glad to answer any question that you might have. //////////////////////////////////////// leases case 'manage-leases': { $actions=json_decode($_POST['actions']); + $add_requested=0; + $add_done=0; + $del_requested=0; + $del_done=0; + $errors=array(); foreach ($actions as $action) { - $todo=$action[0]; - switch ($todo) { - case 'add-leases': { - plc_debug('(add) action',$action); - break; - } - case 'delete-leases': { - plc_debug('(delete) action',$action); - break; - } - default: { - plc_debug('wrong entry',$action); - } + if ($action[0] == 'add-leases') { + $nodenames=$action[1]; + $add_requested += count($nodenames); + $slicename=$action[2]; + $t_from=intval($action[3]); + $t_until=intval($action[4]); + $hash = $api->AddLeases($nodenames,$slicename,$t_from,$t_until); + // update number of added leases + $ids=$hash['new_ids']; + $add_done += count($ids); + // update global errors array + foreach ($api_errors=$hash['errors'] as $error) $errors[]=$error; + } else if ($action[0]=='delete-leases') { + $lease_id=intval($action[1]); + $del_requested += 1; + if ($api->DeleteLeases(array($lease_id)) == 1) { + $del_done += 1; + } else { + $errors []= "Could not delete lease " . $lease_id; + } + } else { + $errors []= "in actions.php, manage-leases, wrong action ". $action[0]; } } - /* - plc_debug('POST',$_POST); - $slicename=$_POST['slicename']; - $nodenames=$_POST['nodenames']; - $t_from=intval($_POST['t_from']); - $t_until=intval($_POST['t_until']); - foreach ($nodenames as $nodename) plc_debug('nodename',$nodename); - $json=json_decode($_POST['nodenames_json']); - plc_debug('json_decode',$json); - $api->AddLeases(); - */ + if (count($errors)==0) { + echo("All leases updated (" . $add_done . " added and " . $del_done . " deleted)"); + } else { + foreach ($errors as $error) echo($error. "\n"); + echo("Leases updated only partially (" . + $add_done . "/" . $add_requested . " added and " . + $del_done . "/" . $del_requested . " deleted)"); + } break; }