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 $node_type= $node['node_type'];
46 $version= $node['version'];
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 $admin_privileges=(plc_is_admin () && $local_peer);
103 $privileges = $admin_privileges || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech()));
107 $tabs [] = tab_nodes_site($site_id);
108 $tabs [] = tab_site($site_id);
109 //$tabs [] = tab_nodes();
111 if ( $local_peer && $privileges ) {
113 $tabs["Add Interface"]=array('url'=>l_interface_add($node_id),
114 'bubble'=>"Define new network interface on $hostname");
115 $tabs['Delete'] = array ('url'=>l_actions(),
117 'values'=>array('action'=>'delete-node','node_id'=>$node_id),
118 'bubble'=>"Delete node $hostname",
119 'confirm'=>'Are you sure to delete ' . $hostname);
120 $tabs["Events"]=array_merge(tablook_event(),
121 array('url'=>l_event("Node","node",$node_id),
122 'bubble'=>"Events for node $hostname"));
123 $tabs["Comon"]=array_merge(tablook_comon(),
124 array('url'=>l_comon("node_id",$node_id),
125 'bubble'=>"Comon page about node $hostname"));
128 plekit_linetabs($tabs);
130 // show gray background on foreign objects : start a <div> with proper class
131 $peers->block_start ($peer_id);
133 $toggle = new PlekitToggle ('node',"Details",
134 array('bubble'=>'Display and modify details for that node',
135 'visible'=>get_arg('show_details')));
138 $details=new PlekitDetails($privileges);
140 if ( ! $local_peer) {
141 $details->th_td("Peer",$peers->peer_link($peer_id));
145 $details->form_start(l_actions(),array("action"=>"update-node", "node_id"=>$node_id, "hostname"=>$hostname));
146 // xxx can hostname really be changed like this without breaking the rest, bootcd .. ?
147 //$details->th_td("Hostname",$hostname,"hostname");
148 $details->th_td("Hostname",$hostname);
149 $details->th_td("Model",$model,"model");
151 if ( $admin_privileges) {
152 $reservation_value = $details->form->select_html("node_type",
153 node_type_selectors ($api, $node_type));
155 $reservation_value = node_type_display ($api,$node_type);
157 $details->th_td("Reservation",$reservation_value);
159 $details->tr_submit("submit","Update Node");
160 $details->form_end();
161 if ($privileges) $details->space();
163 $display_reboot_button = FALSE;
165 // PCU stuff - not too sure why, but GetPCUs is not exposed to the 'user' role
166 $display_pcus = ( $local_peer && (plc_is_admin() || plc_is_pi() || plc_is_tech()));
168 $pcu_ids= $node['pcu_ids'];
169 $ports= $node['ports'];
170 // avoid 2 API calls : get all site PCUs and then search from there
171 function search_pcu ($site_pcus,$pcu_id) {
172 if ($site_pcus) foreach ($site_pcus as $site_pcu) if ($site_pcu['pcu_id']==$pcu_id) return $site_pcu;
175 $site_pcus = $api->GetPCUs(array('site_id'=>$site_id));
176 // not sure what the exact semantics is, but I expect pcu_ids and ports should have same cardinality
177 if (count ($pcu_ids) != count ($ports))
178 $pcu_string = plc_error_html("Unexpected condition: " . count($pcu_ids) . " pcu_ids and " . count($ports) . " ports");
179 else if (count($pcu_ids) == 0)
180 $pcu_string = plc_warning_html("No PCU !");
181 else if (count($pcu_ids) == 1) {
184 $pcu_columns = array('hostname');
185 $pcu=search_pcu($site_pcus,$pcu_id);
187 $pcu_string = plc_error_html("Cannot find PCU " . $pcu_id);
189 // else : regular case - don't set pcu_string
190 // NOTE: temporarily only offer the reboot_button for DC7x00, DRAC, and HPiLO PCU models
191 if ( $pcu['model'] == "IntelAMT" || $pcu['model'] == "DRAC" || $pcu['model'] == "HPiLO" ){
192 $display_reboot_button = TRUE;
196 $pcu_string = plc_warning_html("More than one PCU attached ? ");
198 // in the regular case, pcu_string is not set here
200 $details->form_start(l_actions(),array("action"=>"attach-pcu","node_id"=>$node_id));
203 $pcu_update_area = "This site has no PCU - " . href ( l_pcu_add(), "add one here");
205 $pcu_add_link = href (l_pcu_add(),plc_add_icon() . "Add new");
207 // first option in pcus
209 $none_detach = 'Detach';
212 $pcu_selectors = array(array('display'=>$none_detach,'value'=>-1));
213 // one option per site pcu
214 foreach ($site_pcus as $site_pcu) {
215 $selector=array('display'=>$site_pcu['hostname'],'value'=>$site_pcu['pcu_id']);
216 if ($pcu_id == $site_pcu['pcu_id']) $selector['selected']=true;
217 $pcu_selectors []= $selector;
219 $pcu_chooser = $details->form()->select_html('pcu_id',$pcu_selectors);
221 function port_selector ($i,$port) {
222 $selector = array ('display'=>'port ' . $i, 'value'=>$i);
223 if ($i == $port) $selector['selected'] = true;
226 $port_selectors = array () ;
227 $available_ports =range(1,8);
228 foreach ($available_ports as $available_port)
229 $port_selectors []= port_selector ($available_port,$port);
230 $port_chooser = $details->form()->select_html('port',$port_selectors);
233 $details->form()->submit_html('attach_pcu',"Attach PCU");
235 $pcu_update_area = $pcu_add_link . "<br>Or, select existing " . $pcu_chooser . " " . $port_chooser . " " . $pcu_attach_button;
239 $pcu_value_area=plc_vertical_table(array($pcu_string,$pcu_update_area));
241 $pcu_value_area=$pcu_update_area;
243 $details->th_td("PCU",$pcu_value_area);
244 $details->form_end();
247 //////////////////// Reboot Node
248 if ( $display_reboot_button )
250 if ( ! empty($_SESSION['messages']) ) {
251 $msg = $_SESSION['messages']['status'][0];
257 This message is a template from the 'Report a problem' link on the node details page.
259 I've experienced a problem rebooting $hostname with the pcu_id $pcu_id;
261 http://".PLC_WWW_HOST."/db/sites/pcu.php?id=$pcu_id
262 http://".PLC_WWW_HOST."/db/nodes/node.php?id=$node_id\n\n";
265 $body .= "The last time I tried, it returned:\n $msg\n\n";
267 $body .= "And, this is what I've tried, which leads me to believe that there is a bug on your side:";
269 $url=rawurlencode($body);
270 $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>";
272 // NOTE: not sure how to make the buttons display side-by-side...
273 $reboot = $details->form_start_html(l_actions(),array("action"=>"reboot-node-with-pcu",
274 "node_id"=>$node_id, "hostname"=>$hostname, "test"=>FALSE));
275 $reboot .= $email . $details->form->submit_html("submit","Reboot Node");
276 $reboot .= $details->form_end_html();
278 $reboot .= $details->form_start_html(l_actions(),array("action"=>"reboot-node-with-pcu",
279 "node_id"=>$node_id, "hostname"=>$hostname, "test"=>TRUE));
280 $reboot .= $details->form->submit_html("submit","Test PCU");
281 $reboot .= $details->form_end_html();
283 $details->tr($reboot, "right");
288 //////////////////// type & version
289 $details->th_td("Version",$version);
290 // let's use plc_objects
291 $Node = new Node($node);
292 $details->th_td("Date created",$Node->dateCreated());
293 $details->th_td("Last update",$Node->lastUpdated());
294 $details->th_td("Last contact",$Node->lastContact());
298 $stale_text = $Node->stale() ? ("... (more than " . Node::stale_text() . " ago)") : "" ;
299 $details->th_td ("Observed Boot state", $run_level . $stale_text);
300 if ( ! ($local_peer && $privileges)) {
302 $boot_value=$boot_state;
305 $boot_form = new PlekitForm (l_actions(), array("node_id"=>$node_id,
306 "action"=>"node-boot-state"));
307 $boot_value .= $boot_form->start_html();
308 $states = array( 'boot'=>'Boot', 'safeboot'=>'SafeBoot',
309 'disabled' => 'Disabled', 'reinstall'=>'Reinstall');
311 foreach ($states as $dbname=>$displayname) {
312 $selector=array("display"=>$displayname, "value"=>$dbname);
313 if ($dbname == $boot_state) $selector['selected']=true;
314 $selectors []= $selector;
316 $boot_value .= $boot_form->select_html("boot_state",$selectors,array('autosubmit'=>true));
317 $boot_value .= $boot_form->end_html();
319 $details->th_td ("Preferred Boot state",$boot_value);
321 // same here for the download area
322 if ( $local_peer && $privileges) {
325 $download_form = new PlekitForm (l_actions_download(),array("node_id"=>$node_id));
326 $download_value .= $download_form->start_html();
328 array("display"=>"-- All in one images --","disabled"=>true),
329 array("value"=>"download-node-iso","display"=>"Download ISO image for $hostname"),
330 array("value"=>"download-node-usb","display"=>"Download USB image for $hostname"),
331 array("value"=>"download-node-usb-partition", "display"=>"Download partitioned, USB image for $hostname"),
332 // array("display"=>"-- Floppy + generic image --","disabled"=>true),
333 // array("value"=>"download-node-floppy","display"=>"Download Floppy file for $hostname"),
334 // array("value"=>"download-generic-iso","display"=>"Download generic ISO image (requires floppy)"),
335 // array("value"=>"download-generic-usb","display"=>"Download generic USB image (requires floppy)"),
337 $download_value .= $download_form->select_html("action",$selectors,
338 array('label'=>"Download mode",'autosubmit'=>true));
339 $download_value .= $download_form->end_html();
340 $details->th_td ("Download",$download_value);
344 // site info and all site nodes
346 $details->th_td("Site",l_site_t($site_id,$site_name));
348 // build list of node links
350 foreach ($site_node_hash as $hash_node_id => $hash_hostname) {
351 $nodes_area []= l_node_t($hash_node_id,$hash_hostname);
353 $details->th_tds ("All site nodes",$nodes_area);
358 $form=new PlekitForm (l_actions(), array('node_id'=>$node_id));
361 //////////////////////////////////////////////////////////// slivers
363 $toggle=new PlekitToggle ('slices',count_english_warning($slices,'sliver'),
364 array('bubble'=>'Review slices running on that node',
365 'visible'=>get_arg('show_slices')));
368 plc_warning ("This node is not associated to any slice");
371 $headers['Peer']="string";
372 $headers['Slice Name']="string";
373 $headers['Sliver']="string";
375 $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page);
376 if (count ($slices) <= $reasonable_page) {
377 $table_options['search_area']=false;
378 $table_options['pagesize_area']=false;
380 $table=new PlekitTable("node_slices",$headers,1,$table_options);
383 foreach ($slices as $slice) {
385 $peers->cell ($table,$slice['peer_id']);
386 $table->cell (l_slice_t ($slice['slice_id'],$slice['name']));
387 $table->cell (l_sliver_t ($node_id,$slice['slice_id'],'sliver tags'));
395 //////////////////////////////////////////////////////////// Tags
399 $tags=$api->GetNodeTags (array('node_id'=>$node_id));
400 function get_tagname ($tag) { return $tag['tagname'];}
401 // xxx looks like tech-only see an error here,
402 // might be that GetNodeTags is not accessible or something
403 $tagnames = array_map ("get_tagname",$tags);
404 $nodegroups_hash=plc_nodegroup_global_hash($api,$tagnames);
406 $toggle = new PlekitToggle ('tags',count_english($tags,'tag'),
407 array('bubble'=>'Inspect and set tags on that node',
408 'visible'=>get_arg('show_tags')));
411 $headers=array("Name"=>"string",
413 "Nodegroup"=>"string",
415 if (plc_is_admin()) $headers[plc_delete_icon()]="none";
417 $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
418 $table=new PlekitTable("node_tags",$headers,0,$table_options);
420 if ($tags) foreach ($tags as $tag) {
421 // does this match a nodegroup ?
422 $nodegroup_name="n/a";
423 $nodegroup_key=$tag['tagname'] . "=" . $tag['value'];
424 $nodegroup=$nodegroups_hash[$nodegroup_key];
425 if ($nodegroup) $nodegroup_name=l_nodegroup_t($nodegroup['nodegroup_id'],$nodegroup['groupname']);
427 $table->cell(l_tag_obj($tag));
428 $table->cell($tag['value']);
429 $table->cell($nodegroup_name);
430 // the remove checkbox
431 if (plc_is_admin()) $table->cell ($form->checkbox_html('node_tag_ids[]',$tag['node_tag_id']));
436 $table->tfoot_start();
440 $table->cell($form->submit_html("delete-node-tags","Remove Tags"),
441 // use the whole columns and right adjust
442 array('hfill'=>true,'align'=>'right'));
447 // get list of tag names in the node/* category
448 $all_tags= $api->GetTagTypes( array ("category"=>"node*","-SORT"=>"tagname"), array("tagname","tag_type_id"));
449 // xxx cannot use onchange=submit() - would need to somehow pass action name
450 function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); }
451 $selector=array_map("tag_selector",$all_tags);
452 $table->cell($form->select_html("tag_type_id",$selector,array('label'=>"Choose")));
453 $table->cell($form->text_html("value","",array('width'=>8)));
454 $table->cell($form->submit_html("set-tag-on-node","Set Tag"),array('columns'=>2,'align'=>'left'));
462 //////////////////////////////////////////////////////////// interfaces
464 $toggle=new PlekitToggle ('interfaces',count_english_warning($interfaces,'interface'),
465 array('bubble'=>'Inspect and tune interfaces on that node',
466 'visible'=>get_arg('show_interfaces')));
468 // display interfaces
469 if( ! $interfaces ) {
471 plc_warning_html("This node has no interface");
472 echo "Please add an interface to make this a usable PLC node.</p>\n";
473 } // else { // show this unconditionnally as otherwise there's no mean to create one..
475 // display a hostname column iff at least one interface has a hostname
476 $need_hostname=false;
477 if ($interfaces) foreach ($interfaces as $interface) if ($interface['hostname']) $need_hostname=true;
482 if (plc_is_admin()) { $headers['I']='int'; $sort_column +=1;}
483 $headers["IP"]="sortIPAddress";
484 if ($need_hostname) $headers['hostname']='string';
485 $headers["Method"]="string";
486 $headers["Type"]="string";
487 $headers["MAC"]="string";
488 $headers["bw limit"]="sortBandwidth";
489 $headers["tags"]=array('type'=>'int',
490 'title'=>"number of tags set on interface");
491 // a single symbol, marking 'p' for primary and a delete button for non-primary
492 if ( $privileges ) $headers[plc_delete_icon()]='string';
494 $table_options=array('search_area'=>false,"pagesize_area"=>false,'notes_area'=>false);
495 $table=new PlekitTable("node_interfaces",$headers,$sort_column,$table_options);
498 if ($interfaces) foreach ( $interfaces as $interface ) {
499 $interface_id= $interface['interface_id'];
500 $interface_ip= $interface['ip'];
503 if (plc_is_admin()) $table->cell(l_interface_t($interface_id,$interface_id));
504 $table->cell(l_interface_t($interface_id,$interface_ip));
505 if ($need_hostname) $table->cell($interface['hostname']);
506 $table->cell($interface['method']);
507 $table->cell($interface['type']);
508 $table->cell($interface['mac']);
509 $table->cell(pretty_bandwidth($interface['bwlimit']));
510 $table->cell(href(l_interface_tags($interface_id),
511 count($interface['interface_tag_ids'])));
513 if ($interface['is_primary']) {
514 $table->cell(plc_bubble("p","Cannot delete a primary interface"));
516 $table->cell ($form->checkbox_html('interface_ids[]',$interface_id));
522 $table->tfoot_start();
524 // we should have 6 cols, use 3 for the left (new) and the rest for the right (remove)
525 //$add_button=new PlekitFormButton (l_interface_add($node_id),"add","Add Interface","GET");
526 //$table->cell($add_button->html(),array('columns'=> 3,'align'=>'left'));
527 $table->cell($form->submit_html("new-interface","Add Interface"),
528 array('columns'=> 3,'align'=>'left'));
529 $table->cell($form->submit_html("delete-interfaces","Remove Interfaces"),
530 array('columns'=>$table->columns()-3,'align'=>'right'));
540 ////////////////////////////////////////////////////////////
541 $peers->block_end($peer_id);
543 //plekit_linetabs ($tabs,"bottom");
546 include 'plc_footer.php';