6 require_once 'plc_login.php';
8 // Get session and API handles
9 require_once 'plc_session.php';
13 require_once 'plc_drupal.php';
14 include 'plc_header.php';
17 require_once 'plc_functions.php';
18 require_once 'plc_objects.php';
19 require_once 'plc_peers.php';
20 require_once 'plc_visibletags2.php';
21 require_once 'linetabs.php';
22 require_once 'table2.php';
23 require_once 'nifty.php';
24 require_once 'toggle.php';
25 require_once 'columns.php';
27 // keep css separate for now
28 drupal_set_html_head('
29 <link href="/planetlab/css/my_slice.css" rel="stylesheet" type="text/css" />
33 ini_set("memory_limit","64M");
35 // --------------------
36 // recognized URL arguments
37 $peerscope=$_GET['peerscope'];
38 $pattern=$_GET['pattern'];
39 $site_id=intval($_GET['site_id']);
40 $slice_id=intval($_GET['slice_id']);
41 $person_id=intval($_GET['person_id']);
46 $tabs []= tab_nodes();
47 if (count (plc_my_site_ids()) == 1) {
48 $tabs []= tab_nodes_mysite();
50 $tabs []= tab_nodes_all_mysite();
52 $tabs []= tab_nodes_local();
54 // --------------------
58 // performs sanity check and summarize the result in a single column
59 function node_status ($node) {
62 if ($node['node_type'] != 'regular' && $node['node_type'] != 'reservable' )
63 $messages []= $node['node_type'];
65 // checks on local nodes only
66 if ( ( ! $node['peer_id']) ) {
67 // has it got interfaces
68 if (count($node['interface_ids']) == 0)
69 $messages []= "No interface";
71 return plc_vertical_table($messages,'plc-warning');
75 $first_time_configuration = false;
78 $default_configuration = "ID:f|hostname:f|ST:f|AU:f|RES:f";
80 $default_configuration = "hostname:f|ST:f|AU:f|RES:f";
82 //$extra_default = "LCN|DN|R|L|OS|MS|SN";
83 $column_configuration = "";
84 $slice_column_configuration = "";
85 $show_configuration = "";
86 $show_columns_message = '1';
89 $PersonTags=$api->GetPersonTags (array('person_id'=>$plc->person['person_id']));
90 //print_r($PersonTags);
91 foreach ($PersonTags as $ptag) {
92 if ($ptag['tagname'] == 'columnconf')
94 $column_configuration = $ptag['value'];
95 $conf_tag_id = $ptag['person_tag_id'];
97 if ($ptag['tagname'] == 'showconf')
99 $show_configuration = $ptag['value'];
100 $show_tag_id = $ptag['person_tag_id'];
104 //print("column configuration = ".$column_configuration);
106 $nodesconf_exists = false;
107 if ($column_configuration == "")
109 $first_time_configuration = true;
110 $column_configuration = "nodes;default";
111 $nodesconf_exists = true;
114 $slice_conf = explode(";",$column_configuration);
115 for ($i=0; $i<count($slice_conf); $i++ ) {
116 if ($slice_conf[$i] == "nodes")
119 $slice_column_configuration = $slice_conf[$i];
120 $nodesconf_exists = true;
126 $slice_column_configuration = $slice_conf[$i];
131 if ($nodesconf_exists == false)
132 $column_configuration = $column_configuration.";nodes;default";
133 //panos: need to define an "empty" configuration here (for the moment A column
134 //will be added by default the first time
137 if ($slice_column_configuration == "" || $slice_column_configuration == "default")
138 $full_configuration = $default_configuration;
141 $full_configuration = $default_configuration."|".$slice_column_configuration;
143 //print("full configuration = ".$full_configuration);
146 $node_fixed_columns=array('node_type','site_id','boot_state','last_contact','interface_ids','peer_id', 'slice_ids');
148 $fix_columns = array();
150 $fix_columns[]=array('tagname'=>'node_id', 'header'=>'ID', 'type'=>'string', 'title'=>'The ID the node');
151 $fix_columns[]=array('tagname'=>'hostname', 'header'=>'hostname', 'type'=>'string', 'title'=>'The name of the node');
152 $fix_columns[]=array('tagname'=>'peer_id', 'header'=>'AU', 'type'=>'string', 'title'=>'Authority');
153 $fix_columns[]=array('tagname'=>'run_level', 'header'=>'ST', 'type'=>'string', 'title'=>'Status');
154 $fix_columns[]=array('tagname'=>'node_type', 'header'=>'RES', 'type'=>'string', 'title'=>'Reservable');
157 $visibletags = new VisibleTags ($api, 'node');
158 $visibletags->columns();
159 $tag_columns = $visibletags->headers();
161 //columns that are not defined as extra myslice tags
162 $extra_columns = array();
164 $extra_columns[]=array('tagname'=>'sitename', 'header'=>'SN', 'type'=>'string', 'title'=>'Site name', 'fetched'=>true, 'source'=>'myplc');
165 $extra_columns[]=array('tagname'=>'domain', 'header'=>'DN', 'type'=>'string', 'title'=>'Toplevel domain name', 'fetched'=>true, 'source'=>'myplc');
166 $extra_columns[]=array('tagname'=>'ipaddress', 'header'=>'IP', 'type'=>'string', 'title'=>'IP Address', 'fetched'=>true, 'source'=>'myplc');
167 $extra_columns[]=array('tagname'=>'fcdistro', 'header'=>'OS', 'type'=>'string', 'title'=>'Operating system', 'fetched'=>false, 'source'=>'myplc');
168 $extra_columns[]=array('tagname'=>'date_created', 'header'=>'DA', 'source'=>'myplc', 'type'=>'date', 'title'=>'Date added', 'fetched'=>false);
169 $extra_columns[]=array('tagname'=>'arch', 'header'=>'A', 'source'=>'myplc', 'type'=>'string', 'title'=>'Architecture', 'fetched'=>false);
170 if (plc_is_admin()) {
171 $extra_columns[]=array('tagname'=>'deployment', 'header'=>'DL', 'source'=>'myplc', 'type'=>'string', 'title'=>'Deployment', 'fetched'=>false);
175 $extra_columns[]=array('tagname'=>'bwlimit', 'header'=>'BW', 'source'=>'comon', 'type'=>'sortAlphaNumericTop', 'title'=>'Bandwidth limit', 'fetched'=>false);
176 $extra_columns[]=array('tagname'=>'numcores', 'header'=>'CC', 'source'=>'comon', 'type'=>'sortAlphaNumericTop', 'title'=>'Number of CPU Cores', 'fetched'=>false);
177 $extra_columns[]=array('tagname'=>'cpuspeed', 'header'=>'CR', 'source'=>'comon', 'type'=>'sortAlphaNumericTop', 'title'=>'CPU clock rate', 'fetched'=>false);
178 $extra_columns[]=array('tagname'=>'disksize', 'header'=>'DS', 'source'=>'comon', 'type'=>'sortAlphaNumericTop', 'title'=>'Disk size', 'fetched'=>false);
179 $extra_columns[]=array('tagname'=>'gbfree', 'header'=>'DF', 'source'=>'comon', 'type'=>'sortAlphaNumericTop', 'title'=>'Currently available disk space', 'fetched'=>false);
180 $extra_columns[]=array('tagname'=>'memsize', 'header'=>'MS', 'source'=>'comon', 'type'=>'sortAlphaNumericTop', 'title'=>'Memory size', 'fetched'=>false);
181 $extra_columns[]=array('tagname'=>'numslices', 'header'=>'SM', 'source'=>'comon', 'type'=>'sortAlphaNumericTop', 'title'=>'Number of slices in memory', 'fetched'=>false);
182 $extra_columns[]=array('tagname'=>'uptime', 'header'=>'UT', 'source'=>'comon', 'type'=>'sortAlphaNumericTop', 'title'=>'Continuous uptime until now', 'fetched'=>false);
185 //$extra_columns[]=array('tagname'=>'hopcount', 'header'=>'HC', 'source'=>'tophat', 'type'=>'sortAlphaNumericTop', 'title'=>'Hop count from reference node', 'fetched'=>false);
188 $ConfigureColumns =new PlekitColumns($full_configuration, $fix_columns, $tag_columns, $extra_columns);
190 $visiblecolumns = $ConfigureColumns->node_tags();
192 $node_columns=array_merge($node_fixed_columns,$visiblecolumns);
194 //$visibletags = new VisibleTags ($api, 'node');
195 //$visiblecolumns = $visibletags->column_names();
197 //print_r($visiblecolumns);
198 //$node_columns=array_merge($node_fixed_columns,$visiblecolumns);
201 // server-side filtering - set pattern in $_GET for filtering on hostname
203 $node_filter['hostname']=$pattern;
204 $title .= " matching " . $pattern;
206 $node_filter['hostname']="*";
209 // server-side selection on peerscope
210 $peerscope=new PeerScope($api,$_GET['peerscope']);
211 $node_filter=array_merge($node_filter,$peerscope->filter());
212 $title .= ' - ' . $peerscope->label();
215 $sites=$api->GetSites(array($site_id));
218 $login_base=$site['login_base'];
219 $title .= t_site($site);
220 $tabs []= tab_site($site);
221 $node_filter['site_id']=array($site_id);
225 $slices=$api->GetSlices(array($slice_id),array('node_ids','name'));
227 $title .= t_slice($slice);
228 $tabs []= tab_slice($slice);
229 $node_filter['node_id'] = $slice['node_ids'];
232 // person_id is set : this is mostly oriented towards people managing several sites
234 // avoid doing a useless call to GetPersons if the person_id is already known though $plc,
235 // as this is mostly done for the 'all my sites nodes' link
236 if ($person_id == plc_my_person_id()) {
237 $person=plc_my_person();
238 $site_ids = plc_my_site_ids();
240 // fetch the person's site_ids
241 $persons = $api->GetPersons(array('person_id'=>$person_id),array('person_id','email','site_ids'));
243 $site_ids=$person['site_ids'];
245 $title .= t_person($person);
246 $node_filter['site_id']=$site_ids;
250 //print("getting nodes ".$node_columns);
251 //print_r($node_columns);
252 $nodes=$api->GetNodes($node_filter,$node_columns);
254 //print("<p> GOT NODES </p>");
257 $ConfigureColumns->fetch_live_data($nodes);
259 $show_conf = explode(";",$show_configuration);
260 foreach ($show_conf as $ss) {
262 $show_columns_message = '0';
267 // build site_ids - interface_ids
269 $interface_ids=array();
270 if ($nodes) foreach ($nodes as $node) {
271 $site_ids []= $node['site_id'];
272 $interface_ids = array_merge ($interface_ids,$node['interface_ids']);
275 // fetch related interfaces
276 $interface_columns=array('ip','node_id','interface_id');
277 $interface_filter=array('is_primary'=>TRUE,'interface_id'=>$interface_ids);
278 $interfaces=$api->GetInterfaces($interface_filter,$interface_columns);
280 $interface_hash=array();
281 foreach ($interfaces as $interface) $interface_hash[$interface['node_id']]=$interface;
283 // fetch related sites
284 $site_columns=array('site_id','login_base');
285 $site_filter=array('site_id'=>$site_ids);
286 $sites=$api->GetSites($site_filter,$site_columns);
289 foreach ($sites as $site) $site_hash[$site['site_id']]=$site;
291 // --------------------
292 drupal_set_title($title);
294 plekit_linetabs($tabs);
297 drupal_set_message ('No node found');
301 $nifty=new PlekitNifty ('','objects-list','big');
303 $headers = array (); $offset=0;
305 $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";
310 if (plc_is_admin()) {
311 $short="I"; $long="node_id"; $type='int';
312 $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
315 $short="P"; $long="Peer"; $type='string';
316 $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
317 $short="D"; $long="toplevel domain name"; $type='string';
318 $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
319 $headers["Site"]="string";
320 $headers["Hostname"]="string";
321 $short="IP"; $long="IP Address"; $type='sortIPAddress';
322 $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
323 $short="ST"; $long=Node::status_footnote(); $type='string';
324 $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
325 $short="SL"; $long="Number of slivers"; $type='int';
326 $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
328 $headers=array_merge($headers,$visibletags->headers());
329 $notes=array_merge($notes,$visibletags->notes());
330 $short="?"; $long="extra status info"; $type='string';
331 $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
334 $info_header = array();
335 $short="?"; $long="extra status info"; $type='string';
336 $info_header[$short]=array('type'=>$type,'title'=>$long, 'label'=>'?', 'header'=>'?', 'visible'=>true);
337 //$notes []= "$short = $long";
338 //$info_header["?"] = "none";
339 $headers = array_merge($ConfigureColumns->get_headers(),$info_header);
341 if ($first_time_configuration)
342 $column_conf_visible = '1';
344 $column_conf_visible = '0';
346 $toggle_nodes=new PlekitToggle('nodes-column-configuration',
348 array('visible'=>$column_conf_visible, 'info_div'=>'note_columns_div'));
349 $toggle_nodes->start();
350 print("<div id='debug'></div>");
351 print("<input type='hidden' id='slice_id' value='nodes' />");
352 print("<input type='hidden' id='person_id' value='".$plc->person['person_id']."' />");
353 print("<input type='hidden' id='conf_tag_id' value='".$conf_tag_id."' />");
354 print("<input type='hidden' id='show_tag_id' value='".$show_tag_id."' />");
355 print("<input type='hidden' id='show_configuration' value='".$show_configuration."' />");
356 print("<input type='hidden' id='column_configuration' value='".$slice_column_configuration."' />");
357 print("<br><input type='hidden' size=80 id='full_column_configuration' value='".$column_configuration."' />");
358 print("<input type='hidden' id='defaultConf' value='".$default_configuration."'></input>");
360 if ($show_columns_message == '0')
361 $note_display = "display:none;";
367 <div id='note_columns_div' style="align:center; background-color:#CAE8EA; padding:4px; width:800px; $note_display">
368 <table align=center><tr><td valign=top>
369 This tab allows you to customize the columns in the node tables, below. Information on the nodes comes from a variety of monitoring sources. If you, as either a user or a provider of monitoring data, would like to see additional columns made available, please send us your request in mail to <a href="mailto:support@myslice.info">support@myslice.info</a>. You can find more information about the MySlice project at <a href="http://trac.myslice.info">http://trac.myslice.info</a>.
370 </td><td valign=top><span onClick=closeMessage('columns')><img class='reset' src="/planetlab/icons/clear.png" alt="hide message permanently"></span>
375 $ConfigureColumns->configuration_panel_html(true);
376 $ConfigureColumns->javascript_init();
377 $toggle_nodes->end();
379 $table_options = array('notes'=>$notes,
382 'configurable'=>true);
384 # initial sort on hostnames
385 $table=new PlekitTable ("nodes",$headers,3+$offset, $table_options);
388 $peers = new Peers ($api);
390 foreach ($nodes as $node) {
391 //$node_obj = new Node ($node);
392 $hostname=$node['hostname'];
393 $node_id=$node['node_id'];
394 $site_id=$node['site_id'];
395 $site=$site_hash[$site_id];
396 $login_base = $site['login_base'];
397 $ip=$interface_hash[$node['node_id']]['ip'];
398 $interface_id=$interface_hash[$node['node_id']]['interface_id'];
399 $peer_id=$node['peer_id'];
402 $table->cell($node['node_id'], array('display'=>'none'));
403 if (plc_is_admin()) $table->cell(l_node_t($node_id,$node_id));
404 $table->cell (l_node_t($node_id,$hostname));
405 $peers->cell ($table,$peer_id);
407 //prefetch some columns
408 $node['domain'] = topdomain($hostname);
409 $node['sitename'] = l_site_t($site_id,$login_base);
411 $node['ipaddress'] = l_interface_t($interface_id,$ip);
413 $node['ipaddress'] = "n/a";
415 list($label,$class) = Node::status_label_class_($node);
416 $table->cell ($label,array('class'=>$class));
417 $table->cell( ($node['node_type']=='reservable')?reservable_mark():"" );
418 //$table->cell (count($node['slice_ids']));
419 //foreach ($visiblecolumns as $tagname) $table->cell($node[$tagname]);
420 $ConfigureColumns->cells($table, $node);
421 $table->cell (node_status($node));
429 //plekit_linetabs ($tabs,"bottom");
432 include 'plc_footer.php';