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