+//////////////////////////////////////// nodegroups
+ case 'update-nodegroup': {
+ $nodegroup_id = $_POST['nodegroup_id'];
+ $groupname = $_POST['groupname'];
+ $value = $_POST['value'];
+
+ $fields=array();
+ $fields['groupname']=$groupname;
+ $fields['value']=$value;
+ if ( $api->UpdateNodeGroup($nodegroup_id,$fields) == 1)
+ drupal_set_message ('Nodegroup updated');
+ else
+ drupal_set_error ("Could not update nodegroup $groupname");
+
+ plc_redirect(l_nodegroup($nodegroup_id));
+
+ }
+
+ case 'add-nodegroup': {
+ $groupname=$_POST['groupname'];
+ if ( ! $groupname ) {
+ drupal_set_error ('Empty groupname');
+ plc_redirect (l_nodegroups());
+ }
+ $tag_type_id=intval($_POST['tag_type_id']);
+ if ( ! $tag_type_id ) {
+ drupal_set_error ('You must select a tag in the dropdown list');
+ plc_redirect (l_nodegroups());
+ }
+ $value=$_POST['value'];
+ if ( ! $value ) {
+ drupal_set_message ("Empty value.. let's see ..");
+ }
+ if ( $api->AddNodeGroup ($groupname,$tag_type_id,$value) > 0)
+ drupal_set_message ("Nodegroup $groupname created");
+ else
+ drupal_set_error ("Could not create nodegroup $groupname");
+
+ plc_redirect (l_nodegroups());
+ break;
+ }
+
+ case 'delete-nodegroups': {
+ $nodegroup_ids=$_POST['nodegroup_ids'];
+ if ( ! $nodegroup_ids ) {
+ drupal_set_message("action=delete-nodegroups - No group selected");
+ plc_redirect(l_nodegroups());
+ }
+ $success=true;
+ $counter=0;
+ foreach ($nodegroup_ids as $nodegroup_id)
+ if ($api->DeleteNodeGroup(intval($nodegroup_id)) != 1)
+ $success=false;
+ else
+ $counter++;
+ if ($success)
+ drupal_set_message ("Deleted $counter group(s)");
+ else
+ drupal_set_error ("Could not delete all selected groups, only $counter were removed");
+ plc_redirect (l_nodegroups());
+ break;
+ }
+
+//////////////////////////////////////// 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) {
+ 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];
+ }
+ }
+
+ 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;
+ }