4 // pattern-matching selection not implemented
5 // due to GetSlices bug, see test.php for details
6 // in addition that would not make much sense
9 require_once 'plc_login.php';
11 // Get session and API handles
12 require_once 'plc_session.php';
16 require_once 'plc_drupal.php';
18 drupal_set_title('Slices');
19 include 'plc_header.php';
22 require_once 'plc_functions.php';
23 require_once 'plc_sorts.php';
26 $_person= $plc->person;
27 $_roles= $_person['role_ids'];
29 //print_r( $_person );
32 // if node_host is set then set id to that node's id.
33 if( $_POST['slicename'] ) {
34 $slicename= $_POST['slicename'];
36 $slices= $api->GetSlices( array( $slicename ), array( "slice_id" ) );
38 $slice_id=$slice['slice_id'];
40 plc_redirect(l_slice($slice_id));
45 // if no slice id, display list of slices
47 // diplay site select list for admins
48 if( in_array( 10, $_roles ) ) {
49 // auto complete box for finding a slice
51 drupal_set_html_head('<script type="text/javascript" src="/planetlab/bsn/bsn.Ajax.js"></script>
52 <script type="text/javascript" src="/planetlab/bsn/bsn.DOM.js"></script>
53 <script type="text/javascript" src="/planetlab/bsn/bsn.AutoSuggest.js"></script>');
56 <form method=post action='index.php'>\n";
57 if( $slicename ) echo "<font color=red>'$slicename' is not a valid slice name.</font>\n";
58 echo "<p><label for='testinput'>Enter Slice Name: </label>\n
59 <input type='text' id='testinput' name='slicename' size=40 value='' />\n
60 <input type=submit value='Select Slice' />\n
65 $site_info= $api->GetSites( NULL, array( "site_id", "name", "peer_id" ) );
66 sort_sites( $site_info );
68 // Thierry -- try to select only one entry
69 // xxx still not right if _person in several sites, but that is good enough
70 //if( $site['site_id'] == $_POST['site_id'] || in_array( $site['site_id'], $_person['site_ids'] ) )
71 if ($_POST['site_id'])
72 $selected_site_id = $_POST['site_id'];
73 else if ($_GET['site_id'])
74 $selected_site_id = $_GET['site_id'];
76 $selected_site_id = $_person['site_ids'][0];
78 echo "Select a site to view slices from: ";
79 echo "<select name='site_id' onChange='submit()'>\n";
81 foreach( $site_info as $site ) {
82 echo "<option value=". $site['site_id'];
83 if ( $site['site_id'] == $selected_site_id)
85 if ( $site['peer_id'] )
86 echo " class='plc-foreign'";
87 echo ">". $site['name'] ."</option>\n";
95 if( $_POST['site_id'] ) {
97 $site= array( intval( $_POST['site_id'] ) );
98 } elseif( $_GET['site_id'] ) {
100 $site= array( intval( $_GET['site_id'] ) );
103 $site= $_person['site_ids'];
107 $site_info= $api->GetSites( $site, array( "slice_ids","name" ) );
109 if ( $selection == "Site" )
110 drupal_set_title ("Slices for site " . $site_info[0]['name']);
112 drupal_set_title ("Slices for " . $_person['email'] . "'s sites");
114 // make an array of all slices
115 foreach( $site_info as $site ) {
116 foreach( $site['slice_ids'] as $slice_id ) {
117 $slice_ids[]= $slice_id;
122 if (empty ($slice_ids)) {
123 echo "<p><strong>No slice found, or all are expired.</strong>";
126 $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name", "site_id", "person_ids", "expires", "peer_id" ) );
128 //print '<pre>'; print_r( $api->trace() ) ; print '</pre>';
131 echo "<p><strong>No Slices on site, or all are expired.</strong>\n";
133 echo "<table class='list_set' border=0 cellpadding=2>\n";
134 echo "<caption class='list_set'>Slice list</caption>\n";
135 echo "<thead><tr class='list_set'><th class='list_set'>Slice Name</th>";
136 echo "<th class='list_set'>Users</th>";
137 echo "<th class='list_set'>Expiration</th></tr>";
138 echo "</thead><tbody>\n";
140 // create a list of person_ids
141 $person_ids = array();
142 foreach( $slices as $slice ) {
143 if ( !empty($slice['person_ids']) )
144 $person_ids = array_merge($person_ids, $slice['person_ids']);
147 // create an associative array of persons with person_id as the key
148 $person_list = $api->GetPersons( $person_ids, array("person_id", "email") );
150 foreach( $person_list as $person)
152 $persons[$person['person_id']] = $person;
155 foreach( $slices as $slice ) {
156 $slice_id= $slice['slice_id'];
157 $slice_name= $slice['name'];
158 $slice_expires= date( "M j, Y", $slice['expires'] );
159 $peer_id = $slice['peer_id'];
163 $extraclass="plc-foreign";
165 echo "<tr class='list_set $extraclass'><td><a href='/db/slices/index.php?id=$slice_id'>$slice_name</a></td><td class='list_set'>";
167 if( !empty( $slice['person_ids'] ) ) {
168 foreach( $slice['person_ids'] as $person_id ) {
169 $person = $persons[$person_id];
170 $id= $person['person_id'];
171 $email= $person['email'];
172 echo "<a href='../persons/index.php?id=$id'>$email</a><br />\n";
178 echo "</td><td class='list_set'>$slice_expires</td></tr>\n";
182 echo "</tbody></table>\n";
190 echo "<script type=\"text/javascript\">
192 script:\"/planetlab/slices/test.php?\",
196 var as = new AutoSuggest('testinput', options);
200 // if nothing else then show slice info
202 $slice_id= intval( $_GET['id'] );
204 // GetSlices API call
205 $slices= $api->GetSlices( array( $slice_id ) );
207 if( empty( $slices ) )
208 plc_redirect(l_slices());
210 // pull all slice info to vars
211 $instantiation= $slice['instantiation'];
212 $name= $slice['name'];
214 $expires= date( "M j, Y", $slice['expires'] );
215 $site_id= $slice['site_id'];
216 $description= $slice['description'];
217 $max_nodes= $slice['max_nodes'];
218 $node_ids=$slice['node_ids'];
219 $person_ids=$slice['node_ids'];
222 $peer_id= $slice['peer_id'];
224 $person_ids= $slice['person_ids'];
225 $node_ids= $slice['node_ids'];
226 $slice_tag_ids= $slice['slice_tag_ids'];
231 // if( !empty( $node_ids ) )
232 // $nodes= $api->GetNodes( $node_ids, array( "node_id", "hostname" ) );
235 $site_info= $api->GetSites( array( $site_id ), array( "site_id", "name", "person_ids" ) );
237 // gets all persons from site_id
239 if( !empty( $person_ids ) )
240 $persons= $api->GetPersons( $site_info[0]['person_ids'] , array( "person_id", "role_ids", "first_name", "last_name", "email" ) );
243 // gets site contacts pis stores in dict
244 foreach( $persons as $person )
245 if( in_array( "20", $person['role_ids'] ) ) {
246 $pis[]= array( "email" => $person['email'], "first_name" => $person['first_name'], "last_name" => $person['last_name'], "person_id" => $person['person_id'] );
250 sort_persons( $pis );
255 if( !empty( $slice_tag_ids ) )
256 $slice_attibs= $api->GetSliceTags( $slice_tag_ids,
257 array( "slice_tag_id", "tag_type_id", "value", "description", "min_role_id", "node_id" ) );
259 // gets tag type info and combines it to form all tag info array
260 if( $slice_attibs ) {
261 foreach( $slice_attibs as $slice_attib ) {
262 $tag_type= $api->GetTagTypes( array( $slice_attib['tag_type_id'] ),
263 array( "tag_type_id", "tagname", "description" ) );
265 $tags[]= array( "slice_tag_id" => $slice_attib['slice_tag_id'],
266 "tag_type_id" => $slice_attib['tag_type_id'],
267 "tagname" => $tag_type[0]['tagname'],
268 "value" => $slice_attib['value'],
269 "description" => $slice_attib['description'],
270 "min_role_id" => $slice_attib['min_role_id'],
271 "node_id" => $slice_attib['node_id'] );
276 drupal_set_title("Slice details for " . $name);
280 echo "<div class='plc-foreign'>\n";
286 $actions= array( ''=>'Choose Action' );
288 if( in_array( 10, $_roles )
289 || ( in_array( 20, $_roles ) && in_array( $site_id, $_person['site_ids'] ) )
290 || in_array( $slice_id, $_person['slice_ids'] ) ) {
291 $actions['renew']= "Renew $name";
292 $actions['nodes']= "Manage Nodes";
294 if ( in_array( 10, $_roles )
295 || ( in_array( 20, $_roles ) && in_array( $site_id, $_person['site_ids'] ) ) ) {
296 $actions['users']= "Manage Users";
297 $actions['delete']= "Delete $name";
300 echo "<table><tr><td>\n";
301 if (in_array( 10, $_roles )) {
302 echo plc_event_button("slices","slice",$slice_id);
305 echo plc_comon_button("slice_id",$slice_id);
308 echo "<form action='/db/slices/slice_action.php' method='post'>\n";
309 echo "<input type=hidden name=slice_id value=$slice_id>\n";
311 echo "<select name='actions' onChange=\"submit();\">\n";
312 foreach( $actions as $key => $val ) {
313 echo "<option value='$key'";
315 if( $key == $_POST['actions'] )
321 echo "</select><br />\n";
324 echo "</td></tr></table>\n";
327 echo "<table cellpadding=3><tbody>\n
328 <tr><th>Slice Name: </th><td> $name </td></tr>\n
329 <tr><th>Description: </th><td> $description </td></tr>\n
330 <tr><th>URL: </th><td> <a href='$url'>$url</a> </td></tr>\n";
332 if( gmmktime() > $slice['expires'] ) {
333 $class1= ' style="color:red;"';
334 $msg1= '(slice is expired)';
336 echo "<tr><th$class1>Expiration: </th><td$class1> $expires $msg1</td></tr>\n";
337 echo "<tr><th>Instantiation: </th><td><select name='instantiation' onChange=\"submit();\"\n";
338 echo "<option value='delegated'";
339 if( $instantiation == 'delegated' ) echo " selected";
340 echo ">delegated</option>";
341 echo "<option value='plc-instantiated'";
342 if( $instantiation == 'plc-instantiated' ) echo " selected";
343 echo ">plc-instantiated</option>";
344 echo "<option value='not-instantiated'";
345 if( $instantiation == 'not-instantiated' ) echo " selected";
346 echo ">not-instantiated</option>";
350 echo "<tr><th>Site: </th><td> <a href='/db/sites/index.php?id=$site_id'>". $site_info[0]['name'] ."</a></td></tr>\n";
351 $href="'/db/nodes/index.php?slice_id=" . $slice_id . "'";
352 printf ("<tr><th> <a href=%s># Nodes</a></th><td><a href=%s>Total %d nodes</a></td>\n",$href,$href,count($node_ids));
353 $href="'/db/persons/index.php?slice_id=" . $slice_id . "'";
354 printf ("<tr><th> <a href=%s># Users</a></th><td><a href=%s>Total %d users</a></td>\n",$href,$href,count($person_ids));
355 echo "</tbody></table>\n";
357 if ( (!$class1) && in_array( $slice_id, $_person['slice_ids'] ) && (! $peer_id) )
358 echo "<p><a href='update_slice.php?id=$slice_id'>Update Information</a>\n";
360 echo "<br /><hr />\n";
366 // builds 2 arrays, one for tags, one for slivers
367 foreach( $tags as $tag ) {
368 if( empty( $tag['node_id'] ) ) {
373 $sliver_nodes[]= $tag['node_id'];
378 // Get node info for those slivers
379 $sliver_node_info= $api->GetNodes( $sliver_nodes, array( "node_id", "hostname" ) );
381 if( $sliver_node_info ) {
382 foreach( $sliver_node_info as $sliv_node ) {
383 $new_sliver_node_info[$sliv_node['node_id']]= $sliv_node;
388 echo "<br /></div>\n";
392 $is_admin=in_array( 10, $_roles );
393 $is_in_slice=in_array( $slice_id, $_person['slice_ids'] );
394 $is_pi=in_array( 20, $_roles );
396 echo "<table cellpadding=3><caption class='list_set'>Slice Tags</caption>";
400 echo "<th>Tag</th><th>Value</th><th>Description</th>";
401 echo "</tr></thead><tbody>\n";
403 foreach( $tags as $tag ) {
404 // ignore sliver tags at this stage
405 if( empty( $tag['node_id'] ) ) {
409 sprintf($label,"\\n [ %s = %s] \\n from %s",$tag['tagname'],$tag['value'],$name);
410 // xxx this is deprecated
411 echo plc_delete_link_button ('tag_action.php?rem_id=' . $tag['slice_tag_id'],
415 if( $is_admin || ($is_pi && $is_in_slice) ) {
416 printf ("<td><a href='tags.php?type=slice?id=%s'>%s</a></td>",
417 $tag['slice_tag_id'],$tag['tagname']);
419 printf("<td>%s</td>",$tag['tagname']);
421 printf("<td align=center>%s</td><td>%s</td>",
422 $tag['value'],$tag['description']);
428 echo "</tbody></table>\n";
431 if( $is_admin || ($is_pi && $is_in_slice) )
432 echo "<a href='tags.php?type=slice&add=$slice_id'>Add a Slice Tag</a>\n";
438 echo "<table cellpadding=3><caption class='list_set'>Sliver Tags</caption>";
442 echo "<th>Tag</th><th>Value</th><th>Description</th><th>Node</th>";
443 echo "</tr></thead><tbody>\n";
445 foreach( $tags as $tag ) {
446 $nodename=$new_sliver_node_info[$tag['node_id']]['hostname'];
447 // consider only sliver tags at this stage
448 if( !empty( $tag['node_id'] ) ) {
452 $label=sprintf("\\n [ %s = %s ] \\n from %s \\n on node %s",
453 $tag['tagname'],$tag['value'],$name,$nodename);
454 echo plc_delete_link_label('/db/nodes/sliver_action.php?rem_id=' . $tag['slice_tag_id'],
459 printf("<td><a href='tags.php?type=slice&id=%s'>%s</a></td>",$tag['slice_tag_id'],$tag['tagname']);
461 printf("<td>%s</td>",$tag['tagname']);
463 printf("<td align=center>%s</td><td>%s</td><td><a href='/db/nodes/index.php?id=%s'>%s</a></td>",
464 $tag['value'],$tag['description'],$tag['node_id'],$nodename);
470 echo "</tbody></table>\n";
474 echo "<br /><hr />\n";
476 if( $pis && !$peer_id ) {
478 echo "<h5>Contacts</h5>\n";
480 $pi_rows= count( $pis );
481 $tech_rows= count( $techs );
484 echo "<table cellpadding=2><tbody>";
486 echo "<tr><td rowspan=$pi_rows><strong>PI's:</strong> </td>\n";
488 foreach( $pis as $pi ) {
489 if( $table_row != 0 )
491 printf("<td><a href='/db/persons/index.php?id=%s'>%s %s</td><td><a href='mailto:%s'>%s</a></td></tr>\n",
492 $pi['person_id'],$pi['first_name'],$pi['last_name'],$pi['email'],$pi['email']);
498 echo "</table>\n<br /><hr />\n";
503 echo "<p><a href='index.php'>Back to slice list</a></div>\n";
507 include 'plc_footer.php';