4 require_once 'plc_login.php';
6 // Get session and API handles
7 require_once 'plc_session.php';
11 require_once 'plc_drupal.php';
12 include 'plc_header.php';
15 require_once 'plc_functions.php';
16 require_once 'plc_peers.php';
17 require_once 'linetabs.php';
18 require_once 'table.php';
19 require_once 'details.php';
20 require_once 'form.php';
21 require_once 'toggle.php';
22 require_once 'plc_objects.php';
24 // --------------------
25 // recognized URL arguments
26 $node_id=intval($_GET['id']);
27 if ( ! $node_id ) { plc_error('Malformed URL - id not set'); return; }
30 // Need to mention columns explicitly as we want hrn which is a tag
31 $columns=array ('hostname','boot_state','run_level','site_id','model','node_type','version',
32 'slice_ids','conf_file_ids','interface_ids','nodegroup_ids','peer_id',
33 'pcu_ids','ports','hrn');
34 $nodes= $api->GetNodes( array($node_id),$columns);
37 drupal_set_message ("Node " . $node_id . " not found");
43 $hostname= $node['hostname'];
45 $boot_state= $node['boot_state'];
46 $run_level = $node['run_level'];
47 $site_id= $node['site_id'];
48 $model= $node['model'];
49 $node_type= $node['node_type'];
50 $version= $node['version'];
52 // arrays of ids of node info
53 $slice_ids= $node['slice_ids'];
54 $conf_file_ids= $node['conf_file_ids'];
55 $interface_ids= $node['interface_ids'];
56 $nodegroup_ids= $node['nodegroup_ids'];
59 $peer_id = $node['peer_id'];
60 $peers=new Peers ($api);
63 $sites= $api->GetSites( array( $site_id ) );
65 $site_name= $site['name'];
66 $site_node_ids= $site['node_ids'];
68 // hash node_id=>hostname for this site's nodes
69 $site_node_hash=array();
70 if( !empty( $site_node_ids ) ) {
71 // get site node info basics
72 $site_nodes= $api->GetNodes( $site_node_ids );
74 foreach( $site_nodes as $site_node ) {
75 $site_node_hash[$site_node['node_id']]= $site_node['hostname'];
79 // gets slice info for each slice
80 if( !empty( $slice_ids ) )
81 $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" , "peer_id" ) );
84 if( !empty( $interface_ids ) )
85 $interfaces= $api->GetInterfaces( $interface_ids );
87 // gets nodegroup info
88 if( !empty( $nodegroup_ids ) )
89 $nodegroups= $api->GetNodeGroups( $nodegroup_ids, array("groupname","tag_type_id","value"));
91 // Thierry : remaining stuff
92 // (*) events: xxx todo xxx for admins xxx
93 // should display the latest events relating to that node.
94 // historically we had to turn this off at some point as GetEvents was getting the session deleted in the DB
95 // (*) conf_files: xxx todo xxx for admins xxx
96 //if( !empty( $conf_file_ids ) )
97 // $conf_files= $api->GetConfFiles( $conf_file_ids );
99 //////////////////// display node info
101 drupal_set_title("Details for node " . $hostname);
102 $local_peer= ! $peer_id;
105 // extra privileges to admins, and (pi||tech) on this site
106 $admin_privileges=(plc_is_admin () && $local_peer);
107 $privileges = $admin_privileges || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech()));
111 $tabs [] = tab_nodes_site($site_id);
112 $tabs [] = tab_site($site_id);
113 //$tabs [] = tab_nodes();
115 if ( $local_peer && $privileges ) {
117 $tabs["Add Interface"]=array('url'=>l_interface_add($node_id),
118 'bubble'=>"Define new network interface on $hostname");
119 $tabs['Delete'] = array ('url'=>l_actions(),
121 'values'=>array('action'=>'delete-node','node_id'=>$node_id),
122 'bubble'=>"Delete node $hostname",
123 'confirm'=>'Are you sure to delete ' . $hostname);
124 $tabs["Events"]=array_merge(tablook_event(),
125 array('url'=>l_event("Node","node",$node_id),
126 'bubble'=>"Events for node $hostname"));
127 $tabs["Comon"]=array_merge(tablook_comon(),
128 array('url'=>l_comon("node_id",$node_id),
129 'bubble'=>"Comon page about node $hostname"));
132 plekit_linetabs($tabs);
134 // show gray background on foreign objects : start a <div> with proper class
135 $peers->block_start ($peer_id);
137 $toggle = new PlekitToggle ('node',"Details",
138 array('bubble'=>'Display and modify details for that node',
139 'visible'=>get_arg('show_details')));
142 $details=new PlekitDetails($privileges);
144 if ( ! $local_peer) {
145 $details->th_td("Peer",$peers->peer_link($peer_id));
149 $details->form_start(l_actions(),array("action"=>"update-node", "node_id"=>$node_id, "hostname"=>$hostname));
150 // xxx can hostname really be changed like this without breaking the rest, bootcd .. ?
151 //$details->th_td("Hostname",$hostname,"hostname");
152 $details->th_td("Hostname",$hostname);
153 if ($hrn) $details->th_td("SFA hrn",$hrn);
154 else $details->tr("SFA hrn not set","center");
155 $details->th_td("Model",$model,"model");
157 if ( $admin_privileges) {
158 $reservation_value = $details->form->select_html("node_type",
159 node_type_selectors ($api, $node_type));
161 $reservation_value = node_type_display ($api,$node_type);
163 $details->th_td("Reservation",$reservation_value);
165 $details->tr_submit("submit","Update Node");
166 $details->form_end();
167 if ($privileges) $details->space();
169 $display_reboot_button = FALSE;
171 // PCU stuff - not too sure why, but GetPCUs is not exposed to the 'user' role
172 $display_pcus = ( $local_peer && (plc_is_admin() || plc_is_pi() || plc_is_tech()));
174 $pcu_ids= $node['pcu_ids'];
175 $ports= $node['ports'];
176 // avoid 2 API calls : get all site PCUs and then search from there
177 function search_pcu ($site_pcus,$pcu_id) {
178 if ($site_pcus) foreach ($site_pcus as $site_pcu) if ($site_pcu['pcu_id']==$pcu_id) return $site_pcu;
181 $site_pcus = $api->GetPCUs(array('site_id'=>$site_id));
182 // not sure what the exact semantics is, but I expect pcu_ids and ports should have same cardinality
183 if (count ($pcu_ids) != count ($ports))
184 $pcu_string = plc_error_html("Unexpected condition: " . count($pcu_ids) . " pcu_ids and " . count($ports) . " ports");
185 else if (count($pcu_ids) == 0)
186 $pcu_string = plc_warning_html("No PCU !");
187 else if (count($pcu_ids) == 1) {
190 $pcu_columns = array('hostname');
191 $pcu=search_pcu($site_pcus,$pcu_id);
193 $pcu_string = plc_error_html("Cannot find PCU " . $pcu_id);
195 // else : regular case - don't set pcu_string
196 // NOTE: temporarily only offer the reboot_button for DC7x00, DRAC, and HPiLO PCU models
197 if ( $pcu['model'] == "IntelAMT" || $pcu['model'] == "DRAC" || $pcu['model'] == "HPiLO" ){
198 $display_reboot_button = TRUE;
202 $pcu_string = plc_warning_html("More than one PCU attached ? ");
204 // in the regular case, pcu_string is not set here
206 $details->form_start(l_actions(),array("action"=>"attach-pcu","node_id"=>$node_id));
209 $pcu_update_area = "This site has no PCU - " . href ( l_pcu_add(), "add one here");
211 $pcu_add_link = href (l_pcu_add(),plc_add_icon() . "Add new");
213 // first option in pcus
215 $none_detach = 'Detach';
218 $pcu_selectors = array(array('display'=>$none_detach,'value'=>-1));
219 // one option per site pcu
220 foreach ($site_pcus as $site_pcu) {
221 $selector=array('display'=>$site_pcu['hostname'],'value'=>$site_pcu['pcu_id']);
222 if ($pcu_id == $site_pcu['pcu_id']) $selector['selected']=true;
223 $pcu_selectors []= $selector;
225 $pcu_chooser = $details->form()->select_html('pcu_id',$pcu_selectors);
227 function port_selector ($i,$port) {
228 $selector = array ('display'=>'port ' . $i, 'value'=>$i);
229 if ($i == $port) $selector['selected'] = true;
232 $port_selectors = array () ;
233 $available_ports =range(1,8);
234 foreach ($available_ports as $available_port)
235 $port_selectors []= port_selector ($available_port,$port);
236 $port_chooser = $details->form()->select_html('port',$port_selectors);
239 $details->form()->submit_html('attach_pcu',"Attach PCU");
241 $pcu_update_area = $pcu_add_link . "<br>Or, select existing " . $pcu_chooser . " " . $port_chooser . " " . $pcu_attach_button;
245 $pcu_value_area=plc_vertical_table(array($pcu_string,$pcu_update_area));
247 $pcu_value_area=$pcu_update_area;
249 $details->th_td("PCU",$pcu_value_area);
250 $details->form_end();
253 //////////////////// Reboot Node
254 if ( $display_reboot_button )
256 if ( ! empty($_SESSION['messages']) ) {
257 $msg = $_SESSION['messages']['status'][0];
263 This message is a template from the 'Report a problem' link on the node details page.
265 I've experienced a problem rebooting $hostname with the pcu_id $pcu_id;
267 http://".PLC_WWW_HOST."/db/sites/pcu.php?id=$pcu_id
268 http://".PLC_WWW_HOST."/db/nodes/node.php?id=$node_id\n\n";
271 $body .= "The last time I tried, it returned:\n $msg\n\n";
273 $body .= "And, this is what I've tried, which leads me to believe that there is a bug on your side:";
275 $url=rawurlencode($body);
276 $email = "<font style='font-size: smaller'>><a href=\"mailto:".PLC_MAIL_SUPPORT_ADDRESS."?Subject=Reporting a problem rebooting $hostname&Body=$url\">Report a problem</a></font>";
278 // NOTE: not sure how to make the buttons display side-by-side...
279 $reboot = $details->form_start_html(l_actions(),array("action"=>"reboot-node-with-pcu",
280 "node_id"=>$node_id, "hostname"=>$hostname, "test"=>FALSE));
281 $reboot .= $email . $details->form->submit_html("submit","Reboot Node");
282 $reboot .= $details->form_end_html();
284 $reboot .= $details->form_start_html(l_actions(),array("action"=>"reboot-node-with-pcu",
285 "node_id"=>$node_id, "hostname"=>$hostname, "test"=>TRUE));
286 $reboot .= $details->form->submit_html("submit","Test PCU");
287 $reboot .= $details->form_end_html();
289 $details->tr($reboot, "right");
294 //////////////////// type & version
295 $details->th_td("CD Version",$version);
296 // let's use plc_objects
297 $Node = new Node($node);
298 $details->th_td("Date created",$Node->dateCreated());
299 $details->th_td("Last update",$Node->lastUpdated());
300 $details->th_td("Last contact",$Node->lastContact());
304 $stale_text = $Node->stale() ? ("... (more than " . Node::stale_text() . " ago)") : "" ;
305 $details->th_td ("Observed Boot state", $run_level . $stale_text);
306 if ( ! ($local_peer && $privileges)) {
308 $boot_value=$boot_state;
311 $boot_form = new PlekitForm (l_actions(), array("node_id"=>$node_id,
312 "action"=>"node-boot-state"));
313 $boot_value .= $boot_form->start_html();
314 $states = array( 'boot'=>'Boot', 'safeboot'=>'SafeBoot',
315 'disabled' => 'Disabled', 'reinstall'=>'Reinstall');
317 foreach ($states as $dbname=>$displayname) {
318 $selector=array("display"=>$displayname, "value"=>$dbname);
319 if ($dbname == $boot_state) $selector['selected']=true;
320 $selectors []= $selector;
322 $boot_value .= $boot_form->select_html("boot_state",$selectors,array('autosubmit'=>true));
323 $boot_value .= $boot_form->end_html();
325 $details->th_td ("Preferred Boot state",$boot_value);
327 // same here for the download area
328 if ( $local_peer && $privileges) {
331 $download_form = new PlekitForm (l_actions_download(),array("node_id"=>$node_id));
332 $download_value .= $download_form->start_html();
334 array("display"=>"-- All in one images --","disabled"=>true),
335 array("value"=>"download-node-iso","display"=>"Download ISO image for $hostname"),
336 array("value"=>"download-node-usb","display"=>"Download USB image for $hostname"),
337 array("value"=>"download-node-usb-partition", "display"=>"Download partitioned, USB image for $hostname"),
338 // array("display"=>"-- Floppy + generic image --","disabled"=>true),
339 // array("value"=>"download-node-floppy","display"=>"Download Floppy file for $hostname"),
340 // array("value"=>"download-generic-iso","display"=>"Download generic ISO image (requires floppy)"),
341 // array("value"=>"download-generic-usb","display"=>"Download generic USB image (requires floppy)"),
343 $download_value .= $download_form->select_html("action",$selectors,
344 array('label'=>"Download mode",'autosubmit'=>true));
345 $download_value .= $download_form->end_html();
346 $details->th_td ("Download",$download_value);
350 // site info and all site nodes
352 $details->th_td("Site",l_site_t($site_id,$site_name));
354 // build list of node links
356 foreach ($site_node_hash as $hash_node_id => $hash_hostname) {
357 $nodes_area []= l_node_t($hash_node_id,$hash_hostname);
359 $details->th_tds ("All site nodes",$nodes_area);
364 $form=new PlekitForm (l_actions(), array('node_id'=>$node_id));
367 //////////////////////////////////////////////////////////// slivers
369 $toggle=new PlekitToggle ('slices',count_english_warning($slices,'sliver'),
370 array('bubble'=>'Review slices running on that node',
371 'visible'=>get_arg('show_slices')));
374 plc_warning ("This node is not associated to any slice");
377 $headers['Peer']="string";
378 $headers['Slice Name']="string";
379 $headers['Sliver']="string";
381 $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page);
382 if (count ($slices) <= $reasonable_page) {
383 $table_options['search_area']=false;
384 $table_options['pagesize_area']=false;
386 $table=new PlekitTable("node_slices",$headers,1,$table_options);
389 foreach ($slices as $slice) {
391 $peers->cell ($table,$slice['peer_id']);
392 $table->cell (l_slice_t ($slice['slice_id'],$slice['name']));
393 $table->cell (l_sliver_t ($node_id,$slice['slice_id'],'sliver tags'));
401 //////////////////////////////////////////////////////////// Tags
405 $tags=$api->GetNodeTags (array('node_id'=>$node_id));
406 function get_tagname ($tag) { return $tag['tagname'];}
407 // xxx looks like tech-only see an error here,
408 // might be that GetNodeTags is not accessible or something
409 $tagnames = array_map ("get_tagname",$tags);
410 $nodegroups_hash=plc_nodegroup_global_hash($api,$tagnames);
412 $toggle = new PlekitToggle ('tags',count_english($tags,'tag'),
413 array('bubble'=>'Inspect and set tags on that node',
414 'visible'=>get_arg('show_tags')));
417 $headers=array("Name"=>"string",
419 "Nodegroup"=>"string",
421 if (plc_is_admin()) $headers[plc_delete_icon()]="none";
423 $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
424 $table=new PlekitTable("node_tags",$headers,0,$table_options);
426 if ($tags) foreach ($tags as $tag) {
427 // does this match a nodegroup ?
428 $nodegroup_name="n/a";
429 $nodegroup_key=$tag['tagname'] . "=" . $tag['value'];
430 $nodegroup=$nodegroups_hash[$nodegroup_key];
431 if ($nodegroup) $nodegroup_name=l_nodegroup_t($nodegroup['nodegroup_id'],$nodegroup['groupname']);
433 $table->cell(l_tag_obj($tag));
434 $table->cell($tag['value']);
435 $table->cell($nodegroup_name);
436 // the remove checkbox
437 if (plc_is_admin()) $table->cell ($form->checkbox_html('node_tag_ids[]',$tag['node_tag_id']));
442 $table->tfoot_start();
446 $table->cell($form->submit_html("delete-node-tags","Remove Tags"),
447 // use the whole columns and right adjust
448 array('hfill'=>true,'align'=>'right'));
453 // get list of tag names in the node/* category
454 $all_tags= $api->GetTagTypes( array ("category"=>"node*","-SORT"=>"tagname"), array("tagname","tag_type_id"));
455 // xxx cannot use onchange=submit() - would need to somehow pass action name
456 function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); }
457 $selector=array_map("tag_selector",$all_tags);
458 $table->cell($form->select_html("tag_type_id",$selector,array('label'=>"Choose")));
459 $table->cell($form->text_html("value","",array('width'=>8)));
460 $table->cell($form->submit_html("set-tag-on-node","Set Tag"),array('columns'=>2,'align'=>'left'));
468 //////////////////////////////////////////////////////////// interfaces
470 $toggle=new PlekitToggle ('interfaces',count_english_warning($interfaces,'interface'),
471 array('bubble'=>'Inspect and tune interfaces on that node',
472 'visible'=>get_arg('show_interfaces')));
474 // display interfaces
475 if( ! $interfaces ) {
477 plc_warning_html("This node has no interface");
478 echo "Please add an interface to make this a usable PLC node.</p>\n";
479 } // else { // show this unconditionnally as otherwise there's no mean to create one..
481 // display a hostname column iff at least one interface has a hostname
482 $need_hostname=false;
483 if ($interfaces) foreach ($interfaces as $interface) if ($interface['hostname']) $need_hostname=true;
488 if (plc_is_admin()) { $headers['I']='int'; $sort_column +=1;}
489 $headers["IP"]="sortIPAddress";
490 if ($need_hostname) $headers['hostname']='string';
491 $headers["Method"]="string";
492 $headers["Type"]="string";
493 $headers["MAC"]="string";
494 $headers["bw limit"]="sortBandwidth";
495 $headers["tags"]=array('type'=>'int',
496 'title'=>"number of tags set on interface");
497 // a single symbol, marking 'p' for primary and a delete button for non-primary
498 if ( $privileges ) $headers[plc_delete_icon()]='string';
500 $table_options=array('search_area'=>false,"pagesize_area"=>false,'notes_area'=>false);
501 $table=new PlekitTable("node_interfaces",$headers,$sort_column,$table_options);
504 if ($interfaces) foreach ( $interfaces as $interface ) {
505 $interface_id= $interface['interface_id'];
506 $interface_ip= $interface['ip'];
509 if (plc_is_admin()) $table->cell(l_interface_t($interface_id,$interface_id));
510 $table->cell(l_interface_t($interface_id,$interface_ip));
511 if ($need_hostname) $table->cell($interface['hostname']);
512 $table->cell($interface['method']);
513 $table->cell($interface['type']);
514 $table->cell($interface['mac']);
515 $table->cell(pretty_bandwidth($interface['bwlimit']));
516 $table->cell(href(l_interface_tags($interface_id),
517 count($interface['interface_tag_ids'])));
519 if ($interface['is_primary']) {
520 $table->cell(plc_bubble("p","Cannot delete a primary interface"));
522 $table->cell ($form->checkbox_html('interface_ids[]',$interface_id));
528 $table->tfoot_start();
530 // we should have 6 cols, use 3 for the left (new) and the rest for the right (remove)
531 //$add_button=new PlekitFormButton (l_interface_add($node_id),"add","Add Interface","GET");
532 //$table->cell($add_button->html(),array('columns'=> 3,'align'=>'left'));
533 $table->cell($form->submit_html("new-interface","Add Interface"),
534 array('columns'=> 3,'align'=>'left'));
535 $table->cell($form->submit_html("delete-interfaces","Remove Interfaces"),
536 array('columns'=>$table->columns()-3,'align'=>'right'));
546 ////////////////////////////////////////////////////////////
547 $peers->block_end($peer_id);
549 //plekit_linetabs ($tabs,"bottom");
552 include 'plc_footer.php';