6 require_once 'plc_login.php';
8 // Get session and API handles
9 require_once 'plc_session.php';
13 require_once 'plc_drupal.php';
14 include 'plc_header.php';
17 require_once 'plc_functions.php';
18 require_once 'plc_peers.php';
19 require_once 'linetabs.php';
20 require_once 'table.php';
21 require_once 'details.php';
22 require_once 'toggle.php';
23 require_once 'form.php';
25 // keep css separate for now
26 drupal_set_html_head('
27 <link href="/planetlab/css/my_slice.css" rel="stylesheet" type="text/css" />
30 // -------------------- admins potentially need to get full list of users
31 ini_set('memory_limit','48M');
33 // --------------------
34 // recognized URL arguments
35 $slice_id=intval($_GET['id']);
36 if ( ! $slice_id ) { plc_error('Malformed URL - id not set'); return; }
39 // Get all columns as we focus on only one entry
40 $slices= $api->GetSlices( array($slice_id));
43 drupal_set_message ("Slice " . $slice_id . " not found");
49 // pull all node info to vars
50 $name= $slice['name'];
51 $expires = date( "d/m/Y", $slice['expires'] );
52 $site_id= $slice['site_id'];
54 //$node_ids=$slice['node_ids'];
55 $person_ids=$slice['person_ids'];
56 //$slice_tag_ids= $slice['slice_tag_ids'];
59 $peer_id= $slice['peer_id'];
60 $peers=new Peers ($api);
61 $local_peer = ! $peer_id;
64 $sites= $api->GetSites( array( $site_id ) );
66 $site_name= $site['name'];
67 $max_slices = $site['max_slices'];
69 //$pis=$api->GetPersons(...)
71 // get all persons info
72 if (!empty($person_ids))
73 $persons=$api->GetPersons($person_ids,array('email','enabled'));
76 //////////////////////////////////////// building blocks for the renew area
78 global $DAY; $DAY = 24*60*60;
79 global $WEEK; $WEEK = 7 * $DAY;
80 global $MAX_WEEKS; $MAX_WEEKS= 8; // weeks from today
81 global $GRACE_DAYS; $GRACE_DAYS=10; // days for renewal promoted on top
82 global $NOW; $NOW=mktime();
85 // make the renew area on top and open if the expiration time is less than 10 days from now
86 function renew_needed ($slice) {
87 global $DAY, $NOW, $GRACE_DAYS;
88 $current_exp=$slice['expires'];
90 $time_left = $current_exp - $NOW;
91 $visible = $time_left/$DAY <= $GRACE_DAYS;
95 function renew_area ($slice,$site,$visible) {
96 global $DAY, $WEEK, $MAX_WEEKS, $GRACE_DAYS, $NOW;
98 $current_exp=$slice['expires'];
99 $max_exp= $NOW + ($MAX_WEEKS * $WEEK); // seconds since epoch
101 // xxx some extra code needed to enable this area only if the slice description is OK:
102 // description and url must be non void
104 new PlekitToggle('renew',"Renew this slice",
106 "Enter this zone if you wish to renew your slice",
107 'visible'=>$visible));
110 // xxx message could take roles into account
111 if ($site['max_slices']<=0) {
113 <p class='my-slice-renewal'>Slice creation and renewal have been temporarily disabled for your
114 <site. This may have occurred because your site's nodes have been down
115 or unreachable for several weeks, and multiple attempts to contact
116 your site's PI(s) and Technical Contact(s) have all failed. If so,
117 contact your site's PI(s) and Technical Contact(s) and ask them to
118 bring up your site's nodes. Please visit your <a
119 href='/db/sites/index.php?id=$site_id'>site details</a> page to find
120 out more about your site's nodes, and how to contact your site's PI(s)
121 and Technical Contact(s).</p>
126 // xxx this is a rough cut and paste from the former UI
127 // showing a datepicker view could be considered as well with some extra work
128 // calculate possible extension lengths
129 $selectors = array();
130 foreach ( array ( 1 => "One more week",
131 2 => "Two more weeks",
132 3 => "Three more weeks",
133 4 => "One more month" ) as $weeks => $text ) {
134 $candidate_exp = $current_exp + $weeks*$WEEK;
135 if ( $candidate_exp < $max_exp) {
136 $selectors []= array('display'=>"$text (" . gmstrftime("%A %b-%d-%y %T %Z", $candidate_exp) . ")",
137 'value'=>$candidate_exp);
138 $max_renewal_weeks=$weeks;
139 $max_renewal_date= gmstrftime("%A %b-%d-%y %T %Z", $candidate_exp);
143 if ( empty( $selectors ) ) {
145 <div class='plc-warning renewal'>
146 Slice cannot be renewed any further into the future, try again closer to expiration date.
151 <div class='my-slice-renewal'>
152 <p>You must provide a short description as well as a link to a project website before renewing it.
153 Do <span class='bold'>not</span> provide bogus information; if a complaint is lodged against your slice
154 and PlanetLab Operations is unable to determine what the normal behavior of your slice is,
155 your slice may be deleted to resolve the complaint.</p>
156 <p><span class='bold'>NOTE:</span>
157 Slices cannot be renewed beyond another $max_renewal_weeks week(s) ($max_renewal_date).
162 $form = new PlekitForm (l_actions(),
163 array('action'=>'renew-slice',
164 'slice_id'=>$slice['slice_id']));
166 print $form->label_html('expires','Duration');
167 print $form->select_html('expires',$selectors,array('label'=>'Pick one'));
168 print $form->submit_html('renew-button','Renew');
178 $am_in_slice = in_array(plc_my_person_id(),$person_ids);
181 drupal_set_title("My slice " . $name);
183 drupal_set_title("Slice " . $name);
186 $privileges = ( $local_peer && (plc_is_admin() || $am_in_slice));
189 $tabs [] = tab_nodes_slice($slice_id);
190 $tabs [] = tab_site($site_id);
192 // are these the right privileges for deletion ?
194 $tabs ['Delete']= array('url'=>l_actions(),
196 'values'=>array('action'=>'delete-slice','slice_id'=>$slice_id),
197 'bubble'=>"Delete slice $name",
198 'confirm'=>'Are you sure to delete $name');
200 $tabs["Events"]=array_merge(tablook_event(),
201 array('url'=>l_event("Slice","slice",$slice_id),
202 'bubble'=>"Events for slice $name"));
203 $tabs["Comon"]=array_merge(tablook_comon(),
204 array('url'=>l_comon("slice_id",$slice_id),
205 'bubble'=>"Comon page about slice $name"));
208 plekit_linetabs($tabs);
210 ////////////////////////////////////////
211 $peers->block_start($peer_id);
213 //////////////////////////////////////// renewal area
214 // (1) close to expiration : show on top and open
217 $renew_visible = renew_needed ($slice);
218 if ($renew_visible) renew_area ($slice,$site,true);
222 //////////////////// details
223 // default for opening the details section or not ?
225 $default_show_details = true;
227 $default_show_details = ! $renew_visible;
231 new PlekitToggle ('my-slice-details',"Details",
233 'Display and modify details for that slice',
234 'visible'=>get_arg('show_details',$default_show_details)));
237 $details=new PlekitDetails($privileges);
238 $details->form_start(l_actions(),array('action'=>'update-slice',
239 'slice_id'=>$slice_id,
244 $details->th_td("Peer",$peers->peer_link($peer_id));
249 $details->th_td('Name',$slice['name']);
250 $details->th_td('Description',$slice['description'],'description',
251 array('input_type'=>'textarea',
252 'width'=>50,'height'=>5));
253 $details->th_td('URL',$slice['url'],'url',array('width'=>50));
254 $details->tr_submit("submit","Update Slice");
255 $details->th_td('Expires',$expires);
256 $details->th_td('Instantiation',$slice['instantiation']);
257 $details->th_td('Site',l_site_obj($site));
258 // xxx show the PIs here
259 //$details->th_td('PIs',...);
262 $details->form_end();
265 //////////////////// persons
266 $persons=$api->GetPersons(array('person_id'=>$slice['person_ids']));
267 // just propose to add everyone else,
268 // as regular persons can see only a fraction of the db anyway
270 $potential_persons=$api->GetPersons();
273 $api->GetPersons(array('~person_id'=>$slice['person_ids'],'peer_id'=>NULL),
274 array('email','person_id','first_name','last_name','roles'));
275 $count=count($persons);
278 new PlekitToggle ('my-slice-persons',"$count Users",
280 'Manage accounts attached to this slice',
281 'visible'=>get_arg('show_persons',false)));
284 ////////// people currently in
286 // hide if both current+add are included
287 // so user can chose which section is of interest
289 $toggle_persons = new PlekitToggle ('my-slice-persons-current',
290 "$count people currently in $name",
291 array('visible'=>get_arg('show_persons_current',!$privileges)));
292 $toggle_persons->start();
295 $headers['email']='string';
296 $headers['first']='string';
297 $headers['last']='string';
298 $headers['R']='string';
299 if ($privileges) $headers[plc_delete_icon()]="none";
300 $table=new PlekitTable('persons',$headers,'0',
301 array('notes_area'=>false));
302 $form=new PlekitForm(l_actions(),array('slice_id'=>$slice['slice_id']));
305 if ($persons) foreach ($persons as $person) {
307 $table->cell(l_person_obj($person));
308 $table->cell($person['first_name']);
309 $table->cell($person['last_name']);
310 $table->cell(plc_vertical_table ($person['roles']));
311 if ($privileges) $table->cell ($form->checkbox_html('person_ids[]',$person['person_id']));
318 $table->tfoot_start();
321 $table->cell($form->submit_html ("remove-persons-from-slice","Remove selected"),
322 array('hfill'=>true,'align'=>'right'));
326 $toggle_persons->end();
328 ////////// people to add
330 $count=count($potential_persons);
331 $toggle_persons = new PlekitToggle ('my-slice-persons-add',
332 "$count people may be added to $name",
333 array('visible'=>get_arg('show_persons_add',false)));
334 $toggle_persons->start();
335 if ( ! $potential_persons ) {
337 echo "<p class='not-relevant'>No person to add</p>";
340 $headers['email']='string';
341 $headers['first']='string';
342 $headers['last']='string';
343 $headers['R']='string';
344 $headers['+']="none";
345 $options = array('notes_area'=>false,
348 // show search for admins only as other people won't get that many names to add
349 if ( ! plc_is_admin() ) $options['search_area']=false;
351 $table=new PlekitTable('add_persons',$headers,'0',$options);
352 $form=new PlekitForm(l_actions(),array('slice_id'=>$slice['slice_id']));
355 if ($potential_persons) foreach ($potential_persons as $person) {
357 $table->cell(l_person_obj($person));
358 $table->cell($person['first_name']);
359 $table->cell($person['last_name']);
360 $table->cell(plc_vertical_table ($person['roles']));
361 $table->cell ($form->checkbox_html('person_ids[]',$person['person_id']));
365 $table->tfoot_start();
367 $table->cell($form->submit_html ("add-persons-in-slice","Add selected"),
368 array('hfill'=>true,'align'=>'right'));
373 $toggle_persons->end();
377 //////////////////// nodes
378 // minimal list as a start
379 $node_columns = array('hostname','node_id','arch');
380 $nodes=$api->GetNodes(array('node_id'=>$slice['node_ids']),$node_columns);
382 $potential_nodes=$api->GetNodes();
384 $potential_nodes=$api->GetNodes(array('~node_id'=>$slice['node_ids']),$node_columns);
385 $count=count($nodes);
387 $toggle=new PlekitToggle ('my-slice-nodes',"$count Nodes",
389 'Manage nodes attached to this slice',
390 'visible'=>get_arg('show_nodes',false)));
393 ////////// nodes currently in
394 $count=count($nodes);
395 $toggle_nodes=new PlekitToggle('my-slice-nodes-current',
396 "$count nodes currently in $name",
397 array('visible'=>get_arg('show_nodes_current',!$privileges)));
398 $toggle_nodes->start();
401 $headers['peer']='string';
402 $headers['hostname']='string';
403 $headers['arch']='string';
404 if ($privileges) $headers[plc_delete_icon()]="none";
406 $table_options = array('notes_area'=>false,
409 $table=new PlekitTable('nodes',$headers,'0',$table_options);
411 $form=new PlekitForm(l_actions(),array('slice_id'=>$slice['slice_id']));
414 if ($nodes) foreach ($nodes as $node) {
416 $peers->cell($table,$node['peer_id']);
417 $table->cell(l_node_obj($node));
418 $table->cell($node['arch']);
419 if ($privileges) $table->cell ($form->checkbox_html('node_ids[]',$node['node_id']));
426 $table->tfoot_start();
429 $table->cell($form->submit_html ("remove-nodes-from-slice","Remove selected"),
430 array('hfill'=>true,'align'=>'right'));
434 $toggle_nodes->end();
436 ////////// nodes to add
438 $count=count($potential_nodes);
439 $toggle_nodes=new PlekitToggle('my-slice-nodes-add',
440 "$count more nodes available",
441 array('visible'=>get_arg('show_persons_add',false)));
442 $toggle_nodes->start();
444 if ( ! $potential_nodes ) {
446 echo "<p class='not-relevant'>No node to add</p>";
449 $headers['peer']='string';
450 $headers['hostname']='string';
451 $headers['arch']='string';
452 $headers['+']="none";
454 $table=new PlekitTable('add_nodes',$headers,'1', $table_options);
455 $form=new PlekitForm(l_actions(),
456 array('slice_id'=>$slice['slice_id']));
459 if ($potential_nodes) foreach ($potential_nodes as $node) {
461 $peers->cell($table,$node['peer_id']);
462 $table->cell(l_node_obj($node));
463 $table->cell($node['arch']);
464 $table->cell ($form->checkbox_html('node_ids[]',$node['node_id']));
468 $table->tfoot_start();
470 $table->cell($form->submit_html ("add-nodes-in-slice","Add selected"),
471 array('hfill'=>true,'align'=>'right'));
476 $toggle_nodes->end();
480 //////////////////////////////////////////////////////////// Tags
482 $tags=$api->GetSliceTags (array('slice_id'=>$slice_id));
483 function get_tagname ($tag) { return $tag['tagname'];}
484 $tagnames = array_map ("get_tagname",$tags);
486 $toggle = new PlekitToggle ('slice-tags',count_english_warning($tags,'tag'),
487 array('bubble'=>'Inspect and set tags on tat slice',
488 'visible'=>get_arg('show_tags',false)));
495 "NodeGroup"=>"string");
496 if ($privileges) $headers[plc_delete_icon()]="none";
498 $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
499 $table=new PlekitTable("slice_tags",$headers,'0',$table_options);
500 $form=new PlekitForm(l_actions(),
501 array('slice_id'=>$slice['slice_id']));
505 foreach ($tags as $tag) {
507 if ($tag['node_id']) {
508 $nodes = $api->GetNodes(array('node_id'=>$tag['node_id']));
511 $node_name = $node['hostname'];
514 $nodegroup_name="n/a";
515 if ($tag['nodegroup_id']) {
516 $nodegroup=$api->GetNodeGroups(array('nodegroup_id'=>$tag['nodegroup_id']));
518 $nodegroup = $nodegroup[0];
519 $nodegroup_name = $nodegroup['groupname'];
523 $table->cell(l_tag_obj($tag));
524 $table->cell($tag['value']);
525 $table->cell($node_name);
526 $table->cell($nodegroup_name);
527 if ($privileges) $table->cell ($form->checkbox_html('slice_tag_ids[]',$tag['slice_tag_id']));
532 $table->tfoot_start();
534 $table->cell($form->submit_html ("delete-slice-tags","Remove selected"),
535 array('hfill'=>true,'align'=>'right'));
539 function tag_selector ($tag) {
540 return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']);
542 $all_tags= $api->GetTagTypes( array ("category"=>"slice*"), array("tagname","tag_type_id"));
543 $selector_tag=array_map("tag_selector",$all_tags);
545 function node_selector($node) {
546 return array("display"=>$node["hostname"],"value"=>$node['node_id']);
548 $all_nodes = $api->GetNodes( array ("node_id" => $slice['node_ids']), array("hostname","node_id"));
549 $selector_node=array_map("node_selector",$all_nodes);
551 function nodegroup_selector($ng) {
552 return array("display"=>$ng["groupname"],"value"=>$ng['nodegroup_id']);
554 $all_nodegroups = $api->GetNodeGroups( array("groupname"=>"*"), array("groupname","nodegroup_id"));
555 $selector_nodegroup=array_map("nodegroup_selector",$all_nodegroups);
557 $table->cell($form->select_html("tag_type_id",$selector_tag,array('label'=>"Choose Tag")));
558 $table->cell($form->text_html("value","",array('width'=>8)));
559 $table->cell($form->select_html("node_id",$selector_node,array('label'=>"All Nodes")));
560 $table->cell($form->select_html("nodegroup_id",$selector_nodegroup,array('label'=>"No Nodegroup")));
561 $table->cell($form->submit_html("add-slice-tag","Set Tag"),array('columns'=>2,'align'=>'left'));
571 //////////////////////// renew slice
573 if ( ! $renew_visible) renew_area ($slice,$site,false);
576 $peers->block_end($peer_id);
579 include 'plc_footer.php';