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 // Get all columns as we focus on only one entry
31 $nodes= $api->GetNodes( array($node_id));
34 drupal_set_message ("Node " . $node_id . " not found");
40 $hostname= $node['hostname'];
41 $boot_state= $node['boot_state'];
42 $run_level = $node['run_level'];
43 $site_id= $node['site_id'];
44 $model= $node['model'];
45 $version= $node['version'];
46 $node_type = $node['node_type'];
48 // arrays of ids of node info
49 $slice_ids= $node['slice_ids'];
50 $conf_file_ids= $node['conf_file_ids'];
51 $interface_ids= $node['interface_ids'];
52 $nodegroup_ids= $node['nodegroup_ids'];
55 $peer_id = $node['peer_id'];
56 $peers=new Peers ($api);
59 $sites= $api->GetSites( array( $site_id ) );
61 $site_name= $site['name'];
62 $site_node_ids= $site['node_ids'];
64 // hash node_id=>hostname for this site's nodes
65 $site_node_hash=array();
66 if( !empty( $site_node_ids ) ) {
67 // get site node info basics
68 $site_nodes= $api->GetNodes( $site_node_ids );
70 foreach( $site_nodes as $site_node ) {
71 $site_node_hash[$site_node['node_id']]= $site_node['hostname'];
75 // gets slice info for each slice
76 if( !empty( $slice_ids ) )
77 $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" , "peer_id" ) );
80 if( !empty( $interface_ids ) )
81 $interfaces= $api->GetInterfaces( $interface_ids );
83 // gets nodegroup info
84 if( !empty( $nodegroup_ids ) )
85 $nodegroups= $api->GetNodeGroups( $nodegroup_ids, array("groupname","tag_type_id","value"));
87 // Thierry : remaining stuff
88 // (*) events: xxx todo xxx for admins xxx
89 // should display the latest events relating to that node.
90 // historically we had to turn this off at some point as GetEvents was getting the session deleted in the DB
91 // (*) conf_files: xxx todo xxx for admins xxx
92 //if( !empty( $conf_file_ids ) )
93 // $conf_files= $api->GetConfFiles( $conf_file_ids );
95 //////////////////// display node info
97 drupal_set_title("Details for node " . $hostname);
98 $local_peer= ! $peer_id;
101 // extra privileges to admins, and (pi||tech) on this site
102 $privileges = (plc_is_admin () && $local_peer) || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech()));
106 $tabs [] = tab_nodes_site($site_id);
107 $tabs [] = tab_site($site_id);
108 //$tabs [] = tab_nodes();
110 if ( $local_peer && $privileges ) {
112 $tabs["Add Interface"]=array('url'=>l_interface_add($node_id),
113 'bubble'=>"Define new network interface on $hostname");
114 $tabs['Delete'] = array ('url'=>l_actions(),
116 'values'=>array('action'=>'delete-node','node_id'=>$node_id),
117 'bubble'=>"Delete node $hostname",
118 'confirm'=>'Are you sure to delete ' . $hostname);
119 $tabs["Events"]=array_merge(tablook_event(),
120 array('url'=>l_event("Node","node",$node_id),
121 'bubble'=>"Events for node $hostname"));
122 $tabs["Comon"]=array_merge(tablook_comon(),
123 array('url'=>l_comon("node_id",$node_id),
124 'bubble'=>"Comon page about node $hostname"));
127 plekit_linetabs($tabs);
129 // show gray background on foreign objects : start a <div> with proper class
130 $peers->block_start ($peer_id);
132 $toggle = new PlekitToggle ('node',"Details",
133 array('bubble'=>'Display and modify details for that node',
134 'visible'=>get_arg('show_details',true)));
137 $details=new PlekitDetails($privileges);
139 if ( ! $local_peer) {
140 $details->th_td("Peer",$peers->peer_link($peer_id));
144 $details->form_start(l_actions(),array("action"=>"update-node", "node_id"=>$node_id, "hostname"=>$hostname));
145 // xxx can hostname really be changed like this without breaking the rest, bootcd .. ?
146 //$details->th_td("Hostname",$hostname,"hostname");
147 $details->th_td("Hostname",$hostname);
148 $details->th_td("Model",$model,"model");
149 $details->tr_submit("submit","Update Node");
150 $details->form_end();
151 if ($privileges) $details->space();
153 $display_reboot_button = FALSE;
155 // PCU stuff - not too sure why, but GetPCUs is not exposed to the 'user' role
156 $display_pcus = ( $local_peer && (plc_is_admin() || plc_is_pi() || plc_is_tech()));
158 $pcu_ids= $node['pcu_ids'];
159 $ports= $node['ports'];
160 // avoid 2 API calls : get all site PCUs and then search from there
161 function search_pcu ($site_pcus,$pcu_id) {
162 if ($site_pcus) foreach ($site_pcus as $site_pcu) if ($site_pcu['pcu_id']==$pcu_id) return $site_pcu;
165 $site_pcus = $api->GetPCUs(array('site_id'=>$site_id));
166 // not sure what the exact semantics is, but I expect pcu_ids and ports should have same cardinality
167 if (count ($pcu_ids) != count ($ports))
168 $pcu_string = plc_error_html("Unexpected condition: " . count($pcu_ids) . " pcu_ids and " . count($ports) . " ports");
169 else if (count($pcu_ids) == 0)
170 $pcu_string = plc_warning_html("No PCU !");
171 else if (count($pcu_ids) == 1) {
174 $pcu_columns = array('hostname');
175 $pcu=search_pcu($site_pcus,$pcu_id);
177 $pcu_string = plc_error_html("Cannot find PCU " . $pcu_id);
179 // else : regular case - don't set pcu_string
180 // NOTE: temporarily only offer the reboot_button for DC7x00, DRAC, and HPiLO PCU models
181 if ( $pcu['model'] == "IntelAMT" || $pcu['model'] == "DRAC" || $pcu['model'] == "HPiLO" ){
182 $display_reboot_button = TRUE;
186 $pcu_string = plc_warning_html("More than one PCU attached ? ");
188 // in the regular case, pcu_string is not set here
190 $details->form_start(l_actions(),array("action"=>"attach-pcu","node_id"=>$node_id));
193 $pcu_update_area = "This site has no PCU - " . href ( l_pcu_add(), "add one here");
195 $pcu_add_link = href (l_pcu_add(),plc_add_icon() . "Add new");
197 // first option in pcus
199 $none_detach = 'Detach';
202 $pcu_selectors = array(array('display'=>$none_detach,'value'=>-1));
203 // one option per site pcu
204 foreach ($site_pcus as $site_pcu) {
205 $selector=array('display'=>$site_pcu['hostname'],'value'=>$site_pcu['pcu_id']);
206 if ($pcu_id == $site_pcu['pcu_id']) $selector['selected']=true;
207 $pcu_selectors []= $selector;
209 $pcu_chooser = $details->form()->select_html('pcu_id',$pcu_selectors);
211 function port_selector ($i,$port) {
212 $selector = array ('display'=>'port ' . $i, 'value'=>$i);
213 if ($i == $port) $selector['selected'] = true;
216 $port_selectors = array () ;
217 $available_ports =range(1,8);
218 foreach ($available_ports as $available_port)
219 $port_selectors []= port_selector ($available_port,$port);
220 $port_chooser = $details->form()->select_html('port',$port_selectors);
223 $details->form()->submit_html('attach_pcu',"Attach PCU");
225 $pcu_update_area = $pcu_add_link . "<br>Or, select existing " . $pcu_chooser . " " . $port_chooser . " " . $pcu_attach_button;
229 $pcu_value_area=plc_vertical_table(array($pcu_string,$pcu_update_area));
231 $pcu_value_area=$pcu_update_area;
233 $details->th_td("PCU",$pcu_value_area);
234 $details->form_end();
237 //////////////////// Reboot Node
238 if ( $display_reboot_button )
240 if ( ! empty($_SESSION['messages']) ) {
241 $msg = $_SESSION['messages']['status'][0];
247 This message is a template from the 'Report a problem' link on the node details page.
249 I've experienced a problem rebooting $hostname with the pcu_id $pcu_id;
251 http://".PLC_WWW_HOST."/db/sites/pcu.php?id=$pcu_id
252 http://".PLC_WWW_HOST."/db/nodes/node.php?id=$node_id\n\n";
255 $body .= "The last time I tried, it returned:\n $msg\n\n";
257 $body .= "And, this is what I've tried, which leads me to believe that there is a bug on your side:";
259 $url=rawurlencode($body);
260 $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>";
262 // NOTE: not sure how to make the buttons display side-by-side...
263 $reboot = $details->form_start_html(l_actions(),array("action"=>"reboot-node-with-pcu",
264 "node_id"=>$node_id, "hostname"=>$hostname, "test"=>FALSE));
265 $reboot .= $email . $details->form->submit_html("submit","Reboot Node");
266 $reboot .= $details->form_end_html();
268 $reboot .= $details->form_start_html(l_actions(),array("action"=>"reboot-node-with-pcu",
269 "node_id"=>$node_id, "hostname"=>$hostname, "test"=>TRUE));
270 $reboot .= $details->form->submit_html("submit","Test PCU");
271 $reboot .= $details->form_end_html();
273 $details->tr($reboot, "right");
278 //////////////////// type & version
279 $details->th_td("Type",$node_type);
280 $details->th_td("Version",$version);
281 // let's use plc_objects
282 $Node = new Node($node);
283 $details->th_td("Date created",$Node->dateCreated());
284 $details->th_td("Last update",$Node->lastUpdated());
285 $details->th_td("Last contact",$Node->lastContact());
289 $stale_text = $Node->stale() ? ("... (more than " . Node::stale_text() . " ago)") : "" ;
290 $details->th_td ("Observed Boot state", $run_level . $stale_text);
291 if ( ! ($local_peer && $privileges)) {
293 $boot_value=$boot_state;
296 $boot_form = new PlekitForm (l_actions(), array("node_id"=>$node_id,
297 "action"=>"node-boot-state"));
298 $boot_value .= $boot_form->start_html();
299 $states = array( 'boot'=>'Boot', 'safeboot'=>'SafeBoot',
300 'disabled' => 'Disabled', 'reinstall'=>'Reinstall');
302 foreach ($states as $dbname=>$displayname) {
303 $selector=array("display"=>$displayname, "value"=>$dbname);
304 if ($dbname == $boot_state) $selector['selected']=true;
305 $selectors []= $selector;
307 $boot_value .= $boot_form->select_html("boot_state",$selectors,array('autosubmit'=>true));
308 $boot_value .= $boot_form->end_html();
310 $details->th_td ("Preferred Boot state",$boot_value);
312 // same here for the download area
313 if ( $local_peer && $privileges) {
316 $download_form = new PlekitForm (l_actions_download(),array("node_id"=>$node_id));
317 $download_value .= $download_form->start_html();
319 array("display"=>"-- All in one images --","disabled"=>true),
320 array("value"=>"download-node-iso","display"=>"Download ISO image for $hostname"),
321 array("value"=>"download-node-usb","display"=>"Download USB image for $hostname"),
322 array("value"=>"download-node-usb-partition", "display"=>"Download partitioned, USB image for $hostname"),
323 // array("display"=>"-- Floppy + generic image --","disabled"=>true),
324 // array("value"=>"download-node-floppy","display"=>"Download Floppy file for $hostname"),
325 // array("value"=>"download-generic-iso","display"=>"Download generic ISO image (requires floppy)"),
326 // array("value"=>"download-generic-usb","display"=>"Download generic USB image (requires floppy)"),
328 $download_value .= $download_form->select_html("action",$selectors,
329 array('label'=>"Download mode",'autosubmit'=>true));
330 $download_value .= $download_form->end_html();
331 $details->th_td ("Download",$download_value);
335 // site info and all site nodes
337 $details->th_td("Site",l_site_t($site_id,$site_name));
339 // build list of node links
341 foreach ($site_node_hash as $hash_node_id => $hash_hostname) {
342 $nodes_area []= l_node_t($hash_node_id,$hash_hostname);
344 $details->th_tds ("All site nodes",$nodes_area);
349 $form=new PlekitForm (l_actions(), array('node_id'=>$node_id));
352 //////////////////////////////////////////////////////////// slivers
354 $toggle=new PlekitToggle ('slices',count_english_warning($slices,'sliver'),
355 array('bubble'=>'Review slices running on that node',
356 'visible'=>get_arg('show_slices',false)));
359 plc_warning ("This node is not associated to any slice");
362 $headers['Peer']="string";
363 $headers['Slice Name']="string";
364 $headers['Sliver']="string";
366 $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page);
367 if (count ($slices) <= $reasonable_page) {
368 $table_options['search_area']=false;
369 $table_options['pagesize_area']=false;
371 $table=new PlekitTable("node_slices",$headers,1,$table_options);
374 foreach ($slices as $slice) {
376 $peers->cell ($table,$slice['peer_id']);
377 $table->cell (l_slice_t ($slice['slice_id'],$slice['name']));
378 $table->cell (l_sliver_t ($node_id,$slice['slice_id'],'sliver tags'));
386 //////////////////////////////////////////////////////////// Tags
390 $tags=$api->GetNodeTags (array('node_id'=>$node_id));
391 function get_tagname ($tag) { return $tag['tagname'];}
392 // xxx looks like tech-only see an error here,
393 // might be that GetNodeTags is not accessible or something
394 $tagnames = array_map ("get_tagname",$tags);
395 $nodegroups_hash=plc_nodegroup_global_hash($api,$tagnames);
397 $toggle = new PlekitToggle ('tags',count_english($tags,'tag'),
398 array('bubble'=>'Inspect and set tags on that node',
399 'visible'=>get_arg('show_tags',false)));
402 $headers=array("Name"=>"string",
404 "Nodegroup"=>"string",
406 if (plc_is_admin()) $headers[plc_delete_icon()]="none";
408 $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
409 $table=new PlekitTable("node_tags",$headers,0,$table_options);
411 if ($tags) foreach ($tags as $tag) {
412 // does this match a nodegroup ?
413 $nodegroup_name="n/a";
414 $nodegroup_key=$tag['tagname'] . "=" . $tag['value'];
415 $nodegroup=$nodegroups_hash[$nodegroup_key];
416 if ($nodegroup) $nodegroup_name=l_nodegroup_t($nodegroup['nodegroup_id'],$nodegroup['groupname']);
418 $table->cell(l_tag_obj($tag));
419 $table->cell($tag['value']);
420 $table->cell($nodegroup_name);
421 // the remove checkbox
422 if (plc_is_admin()) $table->cell ($form->checkbox_html('node_tag_ids[]',$tag['node_tag_id']));
427 $table->tfoot_start();
431 $table->cell($form->submit_html("delete-node-tags","Remove Tags"),
432 // use the whole columns and right adjust
433 array('hfill'=>true,'align'=>'right'));
438 // get list of tag names in the node/* category
439 $all_tags= $api->GetTagTypes( array ("category"=>"node*","-SORT"=>"tagname"), array("tagname","tag_type_id"));
440 // xxx cannot use onchange=submit() - would need to somehow pass action name
441 function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); }
442 $selector=array_map("tag_selector",$all_tags);
443 $table->cell($form->select_html("tag_type_id",$selector,array('label'=>"Choose")));
444 $table->cell($form->text_html("value","",array('width'=>8)));
445 $table->cell($form->submit_html("set-tag-on-node","Set Tag"),array('columns'=>2,'align'=>'left'));
453 //////////////////////////////////////////////////////////// interfaces
455 $toggle=new PlekitToggle ('interfaces',count_english_warning($interfaces,'interface'),
456 array('bubble'=>'Inspect and tune interfaces on that node',
457 'visible'=>get_arg('show_interfaces',false)));
459 // display interfaces
460 if( ! $interfaces ) {
462 plc_warning_html("This node has no interface");
463 echo "Please add an interface to make this a usable PLC node.</p>\n";
464 } // else { // show this unconditionnally as otherwise there's no mean to create one..
466 // display a hostname column iff at least one interface has a hostname
467 $need_hostname=false;
468 if ($interfaces) foreach ($interfaces as $interface) if ($interface['hostname']) $need_hostname=true;
473 if (plc_is_admin()) { $headers['I']='int'; $sort_column +=1;}
474 $headers["IP"]="sortIPAddress";
475 if ($need_hostname) $headers['hostname']='string';
476 $headers["Method"]="string";
477 $headers["Type"]="string";
478 $headers["MAC"]="string";
479 $headers["bw limit"]="sortBandwidth";
480 $headers["tags"]=array('type'=>'int',
481 'title'=>"number of tags set on interface");
482 // a single symbol, marking 'p' for primary and a delete button for non-primary
483 if ( $privileges ) $headers[plc_delete_icon()]='string';
485 $table_options=array('search_area'=>false,"pagesize_area"=>false,'notes_area'=>false);
486 $table=new PlekitTable("node_interfaces",$headers,$sort_column,$table_options);
489 if ($interfaces) foreach ( $interfaces as $interface ) {
490 $interface_id= $interface['interface_id'];
491 $interface_ip= $interface['ip'];
494 if (plc_is_admin()) $table->cell(l_interface_t($interface_id,$interface_id));
495 $table->cell(l_interface_t($interface_id,$interface_ip));
496 if ($need_hostname) $table->cell($interface['hostname']);
497 $table->cell($interface['method']);
498 $table->cell($interface['type']);
499 $table->cell($interface['mac']);
500 $table->cell(pretty_bandwidth($interface['bwlimit']));
501 $table->cell(href(l_interface_tags($interface_id),
502 count($interface['interface_tag_ids'])));
504 if ($interface['is_primary']) {
505 $table->cell(plc_bubble("p","Cannot delete a primary interface"));
507 $table->cell ($form->checkbox_html('interface_ids[]',$interface_id));
513 $table->tfoot_start();
515 // we should have 6 cols, use 3 for the left (new) and the rest for the right (remove)
516 //$add_button=new PlekitFormButton (l_interface_add($node_id),"add","Add Interface","GET");
517 //$table->cell($add_button->html(),array('columns'=> 3,'align'=>'left'));
518 $table->cell($form->submit_html("new-interface","Add Interface"),
519 array('columns'=> 3,'align'=>'left'));
520 $table->cell($form->submit_html("delete-interfaces","Remove Interfaces"),
521 array('columns'=>$table->columns()-3,'align'=>'right'));
531 ////////////////////////////////////////////////////////////
532 $peers->block_end($peer_id);
534 //plekit_linetabs ($tabs,"bottom");
537 include 'plc_footer.php';