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