6 require_once 'plc_login.php';
8 // Get session and API handles
9 require_once 'plc_session.php';
10 global $plc, $api, $adm;
13 require_once 'plc_drupal.php';
14 drupal_set_title('Nodes');
15 include 'plc_header.php';
18 require_once 'plc_functions.php';
19 require_once 'plc_sorts.php';
22 $_person= $plc->person;
23 $_roles= $_person['role_ids'];
26 // The set of columns to fetch
27 // and the filter applied for fetching sites
28 $columns = array( "node_id", "hostname", "boot_state", "peer_id" ) ;
29 $filter = array("node_type"=>"regular");
30 if ( in_array( '10', $_roles ) || in_array('20', $_roles) || in_array('40',$_roles)) {
31 // admins, PIs and techs can see interface details
32 $columns [] = "interface_ids";
36 // perform post-processing on objects as returned by GetNodes
37 // performs sanity check and summarize the result in a single column
38 // performs in-place replacement, so passes a reference
39 function layout_node ($node) {
41 // we need the 'interface_ids' field to do this
42 // so regular users wont run this
43 if ( ! array_key_exists ('interface_ids', $node))
48 // do all this stuff on local nodes only
49 if ( ! $node['peer_id'] ) {
50 // check that the node has keys
51 if (count($node['interface_ids']) == 0)
52 $messages [] = "No interface";
55 // but always cleanup $node columns
56 unset ($node['interface_ids']);
57 $node['status'] = plc_make_table('plc-warning',$messages);
58 $node['comon'] = plc_comon_button("node_id",$node['node_id']);
62 // if nodepattern is set then set id to that node's id.
63 // we use GET rather than POST so paginate can display the right contents on subsequent pages
64 // can be useful for writing bookmarkable URL's as well
65 if( $_GET['nodepattern'] || $_GET['peerscope']) {
68 $nodepattern= $_GET['nodepattern'];
69 // need to use a hash filter for patterns to be properly handled
70 if (empty($nodepattern)) {
73 $filter = array_merge (array( "hostname"=>$nodepattern ), $filter);
76 list ( $peer_filter, $peer_label) = plc_peer_info($api,$_GET['peerscope']);
77 $filter=array_merge($filter,$peer_filter);
79 $nodes= $api->GetNodes($filter, $columns);
80 $nodes_count = count ($nodes);
81 if ( $nodes_count == 1) {
82 header( "location: index.php?id=". $nodes[0]['node_id'] );
84 } else if ( $nodes_count == 0) {
85 echo "<span class='plc-warning'> No node matching $nodepattern </span>";
87 drupal_set_title ("Nodes matching $nodepattern on". $peer_label);
88 $nodes = array_map(layout_node,$nodes);
90 echo paginate( $nodes, "node_id", "Nodes", 25, "hostname");
93 // if a site_id is given, display the site nodes only
94 else if( $_GET['site_id'] ) {
96 $site_id= $_GET['site_id'];
99 $site_info= $api->GetSites( array( intval( $site_id ) ), array( "name", "node_ids" ) );
100 drupal_set_title("Nodes on site " . $site_info[0]['name']);
103 $nodes= $api->GetNodes( array_merge(array('node_id'=>$site_info[0]['node_ids']),$filter), $columns);
105 if ( empty ($nodes) ) {
106 echo "No node to display";
109 $nodes = array_map(layout_node,$nodes);
110 sort_nodes( $nodes );
112 echo paginate( $nodes, "node_id", "Nodes", 25, "hostname");
116 // if a slice_id is given, display only the nodes related to this slice
117 else if( $_GET['slice_id'] ) {
119 $slice_id= $_GET['slice_id'];
122 $slice_info= $api->GetSlices( array( intval( $slice_id ) ), array( "name", "node_ids" ) );
123 drupal_set_title("nodes where " . $slice_info[0]['name'] . " is running");
126 $nodes= $api->GetNodes( array_merge(array('node_id'=>$slice_info[0]['node_ids']),$filter), $columns);
128 if ( empty ($nodes) ) {
129 echo "No node to display";
132 $nodes = array_map(layout_node,$nodes);
133 sort_nodes( $nodes );
135 echo paginate( $nodes, "node_id", "Nodes", 25, "hostname");
136 echo "<br /><p><a href='/db/slices/index.php?id=" . $slice_id . "'>Go to slice page</a></p>";
140 // if no node id, display list of nodes to choose
141 elseif( !$_GET['id'] ) {
144 $nodes= $api->GetNodes( empty($filter) ? NULL : $filter, $columns );
146 if ( empty ($nodes) ) {
147 echo "No node to display";
150 $nodes = array_map(layout_node,$nodes);
151 sort_nodes( $nodes );
153 drupal_set_html_head('<script type="text/javascript" src="/planetlab/bsn/bsn.Ajax.js"></script>
154 <script type="text/javascript" src="/planetlab/bsn/bsn.DOM.js"></script>
155 <script type="text/javascript" src="/planetlab/bsn/bsn.AutoSuggest.js"></script>');
158 <form method=get action='index.php'>\n";
160 <th><label for='testinput'>Enter hostname or pattern: : </label></th>\n
161 <td><input type='text' id='testinput' name='nodepattern' size=40 value='' /></td>\n
162 <td rowspan=2><input type=submit value='Select Node' /></td>\n
164 <th><label for='peerscope'>Federation scope: </label></th>\n
165 <td><select id='peerscope' name='peerscope' onChange='submit()'>\n
167 echo plc_peers_option_list($api);
168 echo "</select></td>\n
169 </tr></table></form></div>\n
172 echo paginate( $nodes, "node_id", "Nodes", 25, "hostname" );
174 echo "<script type=\"text/javascript\">\n
176 script:\"/planetlab/nodes/test.php?\",\n
180 var as = new AutoSuggest('testinput', options);\n
186 // get the node id from the URL
187 $node_id= intval( $_GET['id'] );
189 // make the api call to pull that nodes DATA
190 $node_info= $api->GetNodes( array( $node_id ) );
192 if (empty ($node_info)) {
193 echo "No such node.";
197 $hostname= $node_info[0]['hostname'];
198 $boot_state= $node_info[0]['boot_state'];
199 $site_id= $node_info[0]['site_id'];
200 $model= $node_info[0]['model'];
201 $version= $node_info[0]['version'];
203 // arrays of ids of node info
204 $slice_ids= $node_info[0]['slice_ids'];
205 $conf_file_ids= $node_info[0]['conf_file_ids'];
206 $interface_ids= $node_info[0]['interface_ids'];
207 $nodegroup_ids= $node_info[0]['nodegroup_ids'];
208 $pcu_ids= $node_info[0]['pcu_ids'];
209 $ports= $node_info[0]['ports'];
212 $peer_id= $node_info[0]['peer_id'];
215 $site_info= $api->GetSites( array( $site_id ) );
216 $site_name= $site_info[0]['name'];
217 $site_nodes= $site_info[0]['node_ids'];
219 if( !empty( $site_nodes ) ) {
220 // get site node info basics
221 $site_node_list= $api->GetNodes( $site_nodes );
223 foreach( $site_node_list as $s_node ) {
224 $site_node[$s_node['node_id']]= $s_node['hostname'];
228 // gets slice info for each slice
229 if( !empty( $slice_ids ) )
230 $slice_info= $api->GetSlices( $slice_ids, array( "slice_id", "name" , "peer_id" ) );
232 // gets conf file info
233 if( !empty( $conf_file_ids ) )
234 $conf_files= $api->GetConfFiles( $conf_file_ids );
236 // get interface info
237 if( !empty( $interface_ids ) )
238 $interfaces= $api->GetInterfaces( $interface_ids );
240 // gets nodegroup info
241 if( !empty( $nodegroup_ids ) )
242 $node_groups= $api->GetNodeGroups( $nodegroup_ids );
244 // xxx Thierry : disabling call to GetEvents, that gets the session deleted in the DB
246 // $filter= array( "object_type"=>"Node", "object_id"=>$node_id );
247 // $fields= array( "event_id", "person_id", "fault_code", "call_name", "call", "message", "time" );
249 // $event_info= $api->GetEvents( $filter, $fields );
251 // gets pcu and port info key to both is $pcu_id
252 if( !empty( $pcu_ids ) )
253 $PCUs= $api->GetPCUs( $pcu_ids );
258 echo "<div class=plc-foreign>";
261 drupal_set_title("Node " . $hostname . " details");
263 $is_admin = in_array( 10, $_roles );
264 $is_pi = in_array( 20, $_roles );
265 $is_tech = in_array( 40, $_roles );
266 $in_site = in_array( $site_id, $_person['site_ids'] );
269 if ( ! $peer_id && ( $is_admin || ( ($is_pi||$is_tech) && $in_site ) ) ) {
271 // the javascript callback we set on the form; this
272 // (*) checks whether we clicked on 'delete'
273 // (*) in this case performs a javascript 'confirm'
274 // (*) then, notice that if we select delete, then cancel, we can select back 'Choose action'
275 // so submit only when value is not empty
276 $change='if (document.basic.action.value=="delete") if (! confirm("Are you sure you want to delete ' . $hostname . ' ? ") ) return false; if (document.basic.action.value!="") submit();';
278 echo "<table><tr><td>";
280 echo plc_event_button("Node","node",$node_id);
283 echo plc_comon_button("node_id",$node_id);
285 echo "<form name='basic' action='/db/nodes/node_actions.php' method='post'>\n";
286 echo "<input type=hidden name='node_id' value='$node_id'></input>\n";
287 echo "<select name='action' onChange='$change'>\n";
288 echo "<option value='' selected='selected'> Choose Action </option>\n";
289 echo "<option value='prompt-update'> Update $hostname </option>\n";
290 echo "<option value='delete'> Delete $hostname </option>\n";
291 echo "</select></form>\n";
293 echo "</td></tr></table>";
297 echo "<table><tbody>\n";
299 echo "<tr><th>Hostname: </th><td> $hostname </td></tr>\n";
300 echo "<tr><th>Model: </th><td> $model</td></tr>\n";
301 echo "<tr><th>Version: </th><td> $version</td></tr>\n";
303 echo "<tr><th>Boot State: </th><td>";
307 echo "<form name='bootstate' action='/db/nodes/node_actions.php' method=post>\n";
308 echo "<input type=hidden name='node_id' value='$node_id'>\n";
309 echo "<input type=hidden name='action' value='boot-state'>\n";
310 echo "<select name='boot_state' onChange=\"submit();\">\n";
312 $states= array( 'boot'=>'Boot', 'dbg'=>'Debug', 'inst'=>'Install', 'rins'=>'Reinstall', 'rcnf'=>'Reconfigure', 'new'=>'New' );
314 foreach( $states as $key => $val ) {
315 echo "<option value='$key'";
317 if( $key == $boot_state )
320 echo ">$val</option>\n";
324 echo "</select></input></form>";
328 if ( ! $peer_id && ( $is_admin || ( ($is_pi||$is_tech) && $in_site ) ) ) {
330 if ( ! method_exists ($api,"GetBootMedium")) {
331 $new_api_only=" disabled='disabled' ";
334 echo "<tr><th>Download </th><td>";
335 echo "<form name='download' action='/db/nodes/node_actions.php' method='post'>\n";
336 echo "<input type=hidden name='node_id' value='$node_id'></input>\n";
337 echo "<select name='action' onChange='submit();'>\n";
338 echo "<option value='' selected='selected'> Download Mode </option>\n";
339 echo "<option value='' disabled='disabled'> -- All in one images -- </option>";
340 echo "<option value='download-node-iso' $new_api_only> Download ISO image for $hostname</option>\n";
341 echo "<option value='download-node-usb' $new_api_only> Download USB image for $hostname</option>\n";
342 echo "<option value='' disabled='disabled'> -- Floppy + generic image -- </option>";
343 echo "<option value='download-node-floppy'> Download Floppy file for $hostname</option>\n";
344 echo "<option value='download-generic-iso' $new_api_only> Download generic ISO image (requires floppy) </option>\n";
345 echo "<option value='download-generic-usb' $new_api_only> Download generic USB image (requires floppy) </option>\n";
346 echo "</select></form>";
351 // site info and all site nodes
352 echo "<tr><td colspan=2> </td></tr>\n";
353 echo "<tr><th>Site: </th><td> <a href='/db/sites/index.php?id=$site_id'>$site_name</a></td></tr>\n";
354 echo "<tr><th>All site nodes: </th><td>";
355 if (empty($site_node)) {
356 echo "<span class='plc-warning'>Site has no node</span>";
358 foreach( $site_node as $key => $val ) {
359 echo "<a href=index.php?id=$key>$val</a><br />";
364 echo "</tbody></table><br />\n";
370 // display interfaces
372 echo "<p><table class='list_set' border=0 cellpadding=2>\n";
373 echo "<caption class='list_set'>Interfaces</caption>\n";
374 echo "<thead><tr class='list_set'>";
375 // placeholder for the delete buttons
376 if ( $is_admin || ($is_pi && $in_site)) {
377 echo "<th class='list_set'></th>";
379 echo "<th class='list_set'>IP Address</th><th class='list_set'>Method</th><th class='list_set'>Type</th><th class='list_set'>MAC</th><th class='list_set'>Bandwidth Limit</th></tr></thead><tbody>\n";
381 foreach( $interfaces as $interface ) {
382 $nn_id= $interface['interface_id'];
383 $nn_ip= $interface['ip'];
384 $nn_broad= $interface['broadcast'];
385 $nn_primary= $interface['is_primary'];
386 $nn_network= $interface['network'];
387 $nn_dns1= $interface['dns1'];
388 $nn_dns2= $interface['dns2'];
389 $nn_hostname= $interface['hostname'];
390 $nn_netmaks= $interface['netmask'];
391 $nn_gatewary= $interface['gateway'];
392 $nn_mac= $interface['mac'];
393 $nn_bwlimit= $interface['bwlimit'];
394 $nn_type= $interface['type'];
395 $nn_method= $interface['method'];
397 echo "<tr class='list_set'>";
398 if ( $is_admin || ($is_pi && $in_site)) {
399 echo "<td class='list_set'>";
401 echo plc_delete_link_button('interfaces.php?id=' . $nn_id . '&delete=1&submitted=1', '\\nInterface ' . $nn_ip);
403 echo '<span title="This interface is primary"> P </span>';
407 echo "<td class='list_set'>";
408 if( $is_admin || $is_pi || $is_tech ) {
409 echo "<a href='interfaces.php?id=$nn_id'>$nn_ip</a>";
411 echo "</td><td class='list_set'>$nn_ip</td>";
413 echo "<td class='list_set'>$nn_method</td><td class='list_set'>$nn_type</td><td class='list_set'>$nn_mac</td><td class='list_set'>$nn_bwlimit</td></tr>\n";
416 echo "</tbody></table>\n";
419 echo "<p><span class='plc-warning'>No interface</span>. Please add an interface to make this a usable PLC node</p>.\n";
422 echo "<br /><a href='interfaces.php?node_id=$node_id'>Add an interface</a>.\n";
423 echo "<br /><hr />\n";
426 // display node group info
427 if( !empty( $node_groups ) ) {
429 echo "<p><table border=0 cellpadding=3>\n<caption>Node Groups</caption>\n<thead><tr><th>Name</th><th>Description</th>";
430 if( in_array( 10, $_roles ) ) echo "<th></th><th></th>";
431 echo "</tr></thead><tbody>\n";
433 foreach( $node_groups as $node_group ) {
434 echo "<tr><td><a href='/db/nodes/node_groups.php?id=". $node_group['nodegroup_id'] ."'>". $node_group['name'] ."</a></td><td>". $node_group['description'] ."</td>";
436 if( in_array( '10', $_roles ) || ( in_array( 20, $_roles ) && in_array( $site_id, $_person['site_ids'] ) ) || ( in_array( 40, $_roles ) && in_array( $site_id, $_person['site_ids'] ) ) )
437 echo "<td><a href='node_groups.php?nodegroup_id=". $node_group['nodegroup_id'] ."'>Update</a></td><td><a href='node_groups.php?remove=$node_id&nodegrop_id=". $node_group['nodegroup_id'] ."' onclick=\"javascript:return confirm('Are you sure you want to remove ". $hostname ." from ". $node_group['name'] ."?')\">remove</a></td>";
442 echo "</tbody></table><br />\n";
445 echo "<p><span class='plc-warning'>This node is not in any nodegroup.</span></p>\n";
448 // select list for adding to node group
449 // get nodegroup info
450 $full_ng_info= $api->GetNodeGroups( NULL );
451 if( empty( $node_groups ) ) {
452 $person_ng= $full_ng_info;
454 $person_ng= arr_diff( $full_ng_info, $node_groups );
457 sort_nodegroups( $person_ng );
459 if( !empty( $person_ng ) ) {
460 echo "<p>Select nodegroup to add this node to.<br />\n";
461 echo "<select name='ng_add' onChange='submit()'>\n<option value=''>Choose node group...</option>\n";
463 foreach( $person_ng as $ngs ) {
464 echo "<option value=". $ngs['nodegroup_id'] .">". $ngs['name'] ."</option>\n";
471 echo "<br /><hr />\n";
472 if( !empty( $slice_info ) ) {
473 sort_slices( $slice_info );
474 echo paginate( $slice_info, "slice_id", "Slices", 15, "name", "slivers", $node_id );
476 echo "<p><span class='plc-warning'>This node is not associated to any slice.</span></p>\n";
480 // display events - disabled, see GetEvents above
481 if( !empty( $event_info ) ) {
482 echo "<br /><hr />\n";
483 echo "<p><table class='list_set' border=0 cellpadding=2>\n<caption class='list_set'>Node Events</caption>\n<thead><tr class='list_set'><th class='list_set'></th><th class='list_set'>Call Name</th><th class='list_set'>Call</th><th class='list_set'>Message</th><th class='list_set'>Time</th></tr></thead><tbody>\n";
485 // display event on rows of table
486 foreach( $event_info as $event ) {
487 echo "<tr><td>". $event['call'] ."</td><td>". $event['message'] ."</td><td>". $event['time'] ."</td></tr>\n";
489 echo "</tbody></table>\n";
499 echo "<br /><hr /><p><a href='/db/nodes/index.php'>Back to nodes list</a></div>";
504 include 'plc_footer.php';