get rid of all trace or error_reporting even under commented form
[plewww.git] / planetlab / nodes / nodes.php
1 <?php
2
3 // Require login
4 require_once 'plc_login.php';
5
6 // Get session and API handles
7 require_once 'plc_session.php';
8 global $plc, $api;
9
10 // Print header
11 require_once 'plc_drupal.php';
12 include 'plc_header.php';
13
14 // Common functions
15 require_once 'plc_functions.php';
16 require_once 'plc_objects.php';
17 require_once 'plc_peers.php';
18 require_once 'plc_visibletags2.php';
19 require_once 'linetabs.php';
20 require_once 'table2.php';
21 require_once 'nifty.php';
22 require_once 'toggle.php';
23 require_once 'columns.php';
24
25 // keep css separate for now
26 drupal_set_html_head('
27 <link href="/planetlab/css/my_slice.css" rel="stylesheet" type="text/css" />
28 ');
29
30
31 // -------------------- 
32 // recognized URL arguments
33 $peerscope = get_array($_GET, 'peerscope');
34 $pattern = get_array($_GET, 'pattern');
35 $site_id = intval(get_array($_GET, 'site_id'));
36 $slice_id = intval(get_array($_GET, 'slice_id'));
37 $person_id = intval(get_array($_GET, 'person_id'));
38
39 // --- decoration
40 $title="Nodes";
41 $tabs=array();
42 $tabs []= tab_nodes();
43 if (count (plc_my_site_ids()) == 1) {
44     $tabs []= tab_nodes_mysite();
45 } else {
46     $tabs []= tab_nodes_all_mysite();
47 }
48 $tabs []= tab_nodes_local();
49
50 // -------------------- 
51 $node_filter=array();
52
53 //////////////////
54 // performs sanity check and summarize the result in a single column
55 function node_status ($node) {
56
57   $messages=array();
58   if ($node['node_type'] != 'regular' && $node['node_type'] != 'reservable' ) 
59     $messages []= $node['node_type'];
60
61   // checks on local nodes only
62   if ( ( ! $node['peer_id']) ) {
63     // has it got interfaces 
64     if (count($node['interface_ids']) == 0) 
65       $messages []= "No interface";
66   }
67   return plc_vertical_table($messages,'plc-warning');
68 }
69
70
71 if (plc_is_admin()) 
72         $default_configuration = "ID:f|hostname:f|ST:f|AU:f|RES:f";
73 else
74         $default_configuration = "hostname:f|ST:f|AU:f|RES:f";
75
76 //$extra_default = "LCN|DN|R|L|OS|MS|SN";
77 $column_configuration = "";
78 $slice_column_configuration = "";
79 $show_configuration = "";
80
81
82 $PersonTags=$api->GetPersonTags (array('person_id'=>$plc->person['person_id']));
83 //print_r($PersonTags);
84 foreach ($PersonTags as $ptag) {
85         if ($ptag['tagname'] == 'columnconf')
86         {
87                 $column_configuration = $ptag['value'];
88                 $conf_tag_id = $ptag['person_tag_id'];
89         }
90         if ($ptag['tagname'] == 'showconf')
91         {
92                 $show_configuration = $ptag['value'];
93                 $show_tag_id = $ptag['person_tag_id'];
94         }
95 }
96
97 //print("column configuration = ".$column_configuration);
98
99 $nodesconf_exists = false;
100 if ($column_configuration == "")
101 {
102         $column_configuration = "nodes;default";
103         $nodesconf_exists = true;
104 }
105 else {
106         $slice_conf = explode(";",$column_configuration);
107         for ($i=0; $i<count($slice_conf); $i++ ) {
108                 if ($slice_conf[$i] == "nodes")
109                 {
110                         $i++;
111                         $slice_column_configuration = $slice_conf[$i];
112                         $nodesconf_exists = true;
113                         break;
114                 }
115                 else
116                 {
117                         $i++;
118                         $slice_column_configuration = $slice_conf[$i];
119                 }
120         }
121 }
122
123 if ($nodesconf_exists == false)
124         $column_configuration = $column_configuration.";nodes;default";
125 //panos: need to define an "empty" configuration here (for the moment A column
126 //will be added by default the first time
127
128
129 if ($slice_column_configuration == "" || $slice_column_configuration == "default")
130         $full_configuration = $default_configuration;
131         
132 else
133         $full_configuration = $default_configuration."|".$slice_column_configuration;
134
135 //print("full configuration = ".$full_configuration);
136
137 // fetch nodes 
138 $node_fixed_columns=array('node_type','site_id','boot_state','last_contact','interface_ids','peer_id', 'slice_ids');
139
140 $fix_columns = array();
141 if (plc_is_admin()) 
142 $fix_columns[]=array('tagname'=>'node_id', 'header'=>'ID', 'type'=>'string', 'title'=>'The ID the node');
143 $fix_columns[]=array('tagname'=>'hostname', 'header'=>'hostname', 'type'=>'string', 'title'=>'The name of the node');
144 $fix_columns[]=array('tagname'=>'peer_id', 'header'=>'AU', 'type'=>'string', 'title'=>'Authority');
145 $fix_columns[]=array('tagname'=>'run_level', 'header'=>'ST', 'type'=>'string', 'title'=>'Status');
146 $fix_columns[]=array('tagname'=>'node_type', 'header'=>'RES', 'type'=>'string', 'title'=>'Reservable');
147
148
149 $visibletags = new VisibleTags ($api, 'node');
150 $visibletags->columns();
151 $tag_columns = $visibletags->headers();
152
153 //columns that are not defined as extra myslice tags
154 $extra_columns = array();
155 //MyPLC columns
156 $extra_columns[]=array('tagname'=>'sitename', 'header'=>'SN', 'type'=>'string', 'title'=>'Site name', 'fetched'=>true, 'source'=>'myplc');
157 $extra_columns[]=array('tagname'=>'domain', 'header'=>'DN', 'type'=>'string', 'title'=>'Toplevel domain name', 'fetched'=>true, 'source'=>'myplc');
158 $extra_columns[]=array('tagname'=>'ipaddress', 'header'=>'IP', 'type'=>'string', 'title'=>'IP Address', 'fetched'=>true, 'source'=>'myplc');
159 $extra_columns[]=array('tagname'=>'fcdistro', 'header'=>'OS', 'type'=>'string', 'title'=>'Operating system', 'fetched'=>false, 'source'=>'myplc');
160 $extra_columns[]=array('tagname'=>'date_created', 'header'=>'DA', 'source'=>'myplc', 'type'=>'date', 'title'=>'Date added', 'fetched'=>false);
161 $extra_columns[]=array('tagname'=>'arch', 'header'=>'A', 'source'=>'myplc', 'type'=>'string', 'title'=>'Architecture', 'fetched'=>false);
162 if (plc_is_admin()) { 
163 $extra_columns[]=array('tagname'=>'deployment', 'header'=>'DL', 'source'=>'myplc', 'type'=>'string', 'title'=>'Deployment', 'fetched'=>false);
164 }
165
166 //CoMon Live data
167 //NOTE: Uncomment these lines if CoMon provides information for your nodes
168
169 if (MYSLICE_COMON_AVAILABLE)
170 {
171 $extra_columns[]=array('tagname'=>'bwlimit', 'header'=>'BW', 'source'=>'comon', 'type'=>'sortAlphaNumericTop', 'title'=>'Bandwidth limit', 'fetched'=>false);
172 $extra_columns[]=array('tagname'=>'numcores', 'header'=>'CC', 'source'=>'comon', 'type'=>'sortAlphaNumericTop', 'title'=>'Number of CPU Cores', 'fetched'=>false);
173 $extra_columns[]=array('tagname'=>'cpuspeed', 'header'=>'CR', 'source'=>'comon', 'type'=>'sortAlphaNumericTop', 'title'=>'CPU clock rate', 'fetched'=>false);
174 $extra_columns[]=array('tagname'=>'disksize', 'header'=>'DS', 'source'=>'comon', 'type'=>'sortAlphaNumericTop', 'title'=>'Disk size', 'fetched'=>false);
175 $extra_columns[]=array('tagname'=>'gbfree', 'header'=>'DF', 'source'=>'comon', 'type'=>'sortAlphaNumericTop', 'title'=>'Currently available disk space', 'fetched'=>false);
176 $extra_columns[]=array('tagname'=>'memsize', 'header'=>'MS', 'source'=>'comon', 'type'=>'sortAlphaNumericTop', 'title'=>'Memory size', 'fetched'=>false);
177 $extra_columns[]=array('tagname'=>'numslices', 'header'=>'SM', 'source'=>'comon', 'type'=>'sortAlphaNumericTop', 'title'=>'Number of slices in memory', 'fetched'=>false);
178 $extra_columns[]=array('tagname'=>'uptime', 'header'=>'UT', 'source'=>'comon', 'type'=>'sortAlphaNumericTop', 'title'=>'Continuous uptime until now', 'fetched'=>false);
179 }
180
181 //TopHat Live data
182
183 if (MYSLICE_TOPHAT_AVAILABLE)
184 {
185 $extra_columns[]=array('tagname'=>'asn', 'header'=>'AS', 'source'=>'tophat', 'type'=>'string', 'title'=>'AS Number', 'fetched'=>false);
186 $extra_columns[]=array('tagname'=>'city', 'header'=>'LCY', 'source'=>'tophat', 'type'=>'string', 'title'=>'City', 'fetched'=>false);
187 $extra_columns[]=array('tagname'=>'region', 'header'=>'LRN', 'source'=>'tophat', 'type'=>'string', 'title'=>'Region', 'fetched'=>false);
188 $extra_columns[]=array('tagname'=>'country', 'header'=>'LCN', 'source'=>'tophat', 'type'=>'string', 'title'=>'Country', 'fetched'=>false);
189 $extra_columns[]=array('tagname'=>'continent', 'header'=>'LCT', 'source'=>'tophat', 'type'=>'string', 'title'=>'Continent', 'fetched'=>false);
190 //$extra_columns[]=array('tagname'=>'hopcount', 'header'=>'HC', 'source'=>'tophat', 'type'=>'sortAlphaNumericTop', 'title'=>'Hop count from reference node', 'fetched'=>false);
191 ////$extra_columns[]=array('tagname'=>'rtt', 'header'=>'RTT', 'source'=>'tophat', 'type'=>'sortAlphaNumericTop', 'title'=>'Round trip time from reference node', 'fetched'=>false);
192 ////$extra_columns[]=array('tagname'=>'agents', 'header'=>'MA', 'source'=>'tophat', 'type'=>'sortAlphaNumericTop', 'title'=>'Co-located measurement agents', 'fetched'=>true);
193 ////$extra_columns[]=array('tagname'=>'agents_sonoma', 'header'=>'MAS', 'source'=>'tophat', 'type'=>'sortAlphaNumericTop', 'title'=>'Co-located SONoMA agents', 'fetched'=>true);
194 ////$extra_columns[]=array('tagname'=>'agents_etomic', 'header'=>'MAE', 'source'=>'tophat', 'type'=>'sortAlphaNumericTop', 'title'=>'Co-located ETOMIC agents', 'fetched'=>true);
195 ////$extra_columns[]=array('tagname'=>'agents_tdmi', 'header'=>'MAT', 'source'=>'tophat', 'type'=>'sortAlphaNumericTop', 'title'=>'Co-located TDMI agents', 'fetched'=>true);
196 ////$extra_columns[]=array('tagname'=>'agents_dimes', 'header'=>'MAD', 'source'=>'tophat', 'type'=>'sortAlphaNumericTop', 'title'=>'Co-located DIMES agents', 'fetched'=>true);
197 }
198
199
200 $ConfigureColumns =new PlekitColumns($full_configuration, $fix_columns, $tag_columns, $extra_columns);
201
202 $visiblecolumns = $ConfigureColumns->node_tags();
203
204 $node_columns=array_merge($node_fixed_columns,$visiblecolumns);
205
206 //$visibletags = new VisibleTags ($api, 'node');
207 //$visiblecolumns = $visibletags->column_names();
208 //print("<p>OLD");
209 //print_r($visiblecolumns);
210 //$node_columns=array_merge($node_fixed_columns,$visiblecolumns);
211
212
213 // server-side filtering - set pattern in $_GET for filtering on hostname
214 if ($pattern) {
215   $node_filter['hostname']=$pattern;
216   $title .= " matching " . $pattern;
217  } else {
218   $node_filter['hostname']="*";
219  }
220
221 // server-side selection on peerscope
222 $peerscope=new PeerScope($api,$_GET['peerscope']);
223 $node_filter=array_merge($node_filter,$peerscope->filter());
224 $title .= ' - ' . $peerscope->label();
225
226 if ($site_id) {
227   $sites=$api->GetSites(array($site_id));
228   $site=$sites[0];
229   $name=$site['name'];
230   $login_base=$site['login_base'];
231   $title .= t_site($site);
232   $tabs []= tab_site($site);
233   $node_filter['site_id']=array($site_id);
234 }
235
236 if ($slice_id) {
237   $slices=$api->GetSlices(array($slice_id),array('node_ids','name'));
238   $slice=$slices[0];
239   $title .= t_slice($slice);
240   $tabs []= tab_slice($slice);
241   $node_filter['node_id'] = $slice['node_ids'];
242  }
243
244 // person_id is set : this is mostly oriented towards people managing several sites
245 if ($person_id) {
246   // avoid doing a useless call to GetPersons if the person_id is already known though $plc,
247   // as this is mostly done for the 'all my sites nodes' link
248   if ($person_id == plc_my_person_id()) { 
249     $person=plc_my_person();
250     $site_ids = plc_my_site_ids();
251   } else {
252     // fetch the person's site_ids
253     $persons = $api->GetPersons(array('person_id'=>$person_id),array('person_id','email','site_ids'));
254     $person=$persons[0];
255     $site_ids=$person['site_ids'];
256   }
257   $title .= t_person($person);
258   $node_filter['site_id']=$site_ids;
259  }
260
261 // go
262 //print("getting nodes ".$node_columns);
263 //print_r($node_columns);
264 $nodes=$api->GetNodes($node_filter,$node_columns);
265
266 //print("<p> GOT NODES </p>");
267 //print_r($nodes);
268
269 $ConfigureColumns->fetch_live_data($nodes);
270
271 $show_columns_message = TRUE;
272 $show_conf = explode(";",$show_configuration);
273 foreach ($show_conf as $ss) {
274   if ($ss =="columns")
275     $show_columns_message = FALSE;
276 }
277
278
279
280 // build site_ids - interface_ids
281 $site_ids=array();
282 $interface_ids=array();
283 if ($nodes) foreach ($nodes as $node) {
284   $site_ids []= $node['site_id'];
285   $interface_ids = array_merge ($interface_ids,$node['interface_ids']);
286 }
287
288 // fetch related interfaces
289 $interface_columns=array('ip','node_id','interface_id');
290 $interface_filter=array('is_primary'=>TRUE,'interface_id'=>$interface_ids);
291 $interfaces=$api->GetInterfaces($interface_filter,$interface_columns);
292
293 $interface_hash=array();
294 foreach ($interfaces as $interface) $interface_hash[$interface['node_id']]=$interface;
295
296 // fetch related sites
297 $site_columns=array('site_id','login_base');
298 $site_filter=array('site_id'=>$site_ids);
299 $sites=$api->GetSites($site_filter,$site_columns);
300
301 $site_hash=array();
302 foreach ($sites as $site) $site_hash[$site['site_id']]=$site;
303
304 // --------------------
305 drupal_set_title($title);
306
307 plekit_linetabs($tabs);
308
309 if ( ! $nodes ) {
310   drupal_set_message ('No node found');
311   return;
312  }
313   
314 $nifty=new PlekitNifty ('','objects-list','big');
315 $nifty->start();
316 $headers = array (); 
317 $notes=array();
318 $notes [] = "For information about the different columns please see the <b>node table layout</b> tab above or <b>mouse over</b> the column headers";
319
320 $info_header = array();
321 $short="?"; $long="extra status info"; $type='string'; 
322 $info_header[$short]=array('type'=>$type,'title'=>$long, 'label'=>'?', 'header'=>'?', 'visible'=>true); 
323 //$notes []= "$short = $long";
324 //$info_header["?"] = "none";
325 $headers = array_merge($ConfigureColumns->get_headers(),$info_header);
326
327 $layout_help='
328 This tab allows you to customize the columns in the node tables,
329 below. Information on the nodes comes from a variety of monitoring
330 sources. If you, as either a user or a provider of monitoring data,
331 would like to see additional columns made available, please send us
332 your request in mail to <a
333 href="mailto:support@myslice.info">support@myslice.info</a>.  You can
334 find more information about the MySlice project at <a
335 href="http://trac.myslice.info">http://trac.myslice.info</a>.
336 ';
337 $toggle_nodes=new PlekitToggle('nodes-layout',
338                                "Node table layout",
339                                array('visible'=>NULL, 
340                                      'info-text'=>$layout_help,
341                                      'info-visible'=>$show_columns_message));
342 $toggle_nodes->start();
343 print("<div id='debug'></div>");
344 print("<input type='hidden' id='slice_id' value='nodes' />");
345 print("<input type='hidden' id='person_id' value='".$plc->person['person_id']."' />");
346 print("<input type='hidden' id='conf_tag_id' value='".$conf_tag_id."' />");
347 print("<input type='hidden' id='show_tag_id' value='".$show_tag_id."' />");
348 print("<input type='hidden' id='show_configuration' value='".$show_configuration."' />");
349 print("<input type='hidden' id='column_configuration' value='".$slice_column_configuration."' />");
350 print("<br><input type='hidden' size=80 id='full_column_configuration' value='".$column_configuration."' />");
351 print("<input type='hidden' id='defaultConf' value='".$default_configuration."'></input>");
352
353 ////////// end
354
355 $ConfigureColumns->configuration_panel_html(true);
356 $ConfigureColumns->javascript_init();
357 $toggle_nodes->end();
358
359 $table_options = array('notes'=>$notes,
360                        'search_width'=>15,
361                        'pagesize'=>20,
362                         'configurable'=>true);
363
364 # initial sort on hostnames
365 $table=new PlekitTable ("nodes",$headers,2, $table_options);
366 $table->start();
367
368 $peers = new Peers ($api);
369 // write rows
370 foreach ($nodes as $node) {
371   //$node_obj = new Node ($node);
372
373   $hostname=$node['hostname'];
374   $node_id=$node['node_id'];
375   $site_id=$node['site_id'];
376   $site=$site_hash[$site_id];
377   $login_base = $site['login_base'];
378   $ip=$interface_hash[$node['node_id']]['ip'];
379   $interface_id=$interface_hash[$node['node_id']]['interface_id'];
380   $peer_id=$node['peer_id'];
381   
382   $table->row_start();
383   $table->cell($node['node_id'], array('display'=>'none'));
384   if (plc_is_admin()) $table->cell(l_node_t($node_id,$node_id));
385   $table->cell (l_node_t($node_id,$hostname));
386   $peers->cell ($table,$peer_id);
387
388   //prefetch some columns
389   $node['domain'] = topdomain($hostname);
390   $node['sitename'] = l_site_t($site_id,$login_base);
391   if ($interface_id)
392         $node['ipaddress'] = l_interface_t($interface_id,$ip);
393   else
394         $node['ipaddress'] = "n/a";
395
396   list($label,$class) = Node::status_label_class_($node);
397   $table->cell ($label,array('class'=>$class));
398   $table->cell( ($node['node_type']=='reservable')?reservable_mark():"" );
399   //$table->cell (count($node['slice_ids']));
400   //foreach ($visiblecolumns as $tagname) $table->cell($node[$tagname]);
401   $ConfigureColumns->cells($table, $node);
402   $table->cell (node_status($node));
403   $table->row_end();
404   
405 }
406
407 $table->end();
408 $nifty->end();
409
410
411 //plekit_linetabs ($tabs,"bottom");
412
413 // Print footer
414 include 'plc_footer.php';
415
416 ?>
417