// Common functions
require_once 'plc_functions.php';
-require_once 'plc_minitabs.php';
-require_once 'plc_tables.php';
+require_once 'plc_peers.php';
+require_once 'linetabs.php';
+require_once 'table.php';
+require_once 'nifty.php';
+
+ini_set("memory_limit","64M");
// --------------------
// recognized URL arguments
$pattern=$_GET['pattern'];
$site_id=intval($_GET['site_id']);
$slice_id=intval($_GET['slice_id']);
+$person_id=intval($_GET['person_id']);
// --- decoration
$title="Nodes";
-$tabs["Logout"]=array('url'=>l_logout(),
- 'bubble'=>'Logout ' . $plc->person['email']);
+$tabs=array();
+$tabs []= tab_nodes();
+if (count (plc_my_site_ids()) == 1) {
+ $tabs []= tab_nodes_mysite();
+} else {
+ $tabs []= tab_nodes_all_mysite();
+}
+$tabs []= tab_nodes_local();
// --------------------
-$peer_filter=array();
$node_filter=array();
//////////////////
// performs sanity check and summarize the result in a single column
function node_status ($node) {
- $messages=array();
-
// do all this stuff on local nodes only
- if ( ! $node['peer_id'] ) {
- // check that the node has keys
- if (count($node['interface_ids']) == 0) {
- $messages [] = "No interface";
- }
+ if ( $node['peer_id'] )
+ return "n/a";
+
+ $messages=array();
+ // check that the node has interfaces
+ if (count($node['interface_ids']) == 0) {
+ $messages [] = "No interface";
}
- return plc_make_table('plc-warning',$messages);
+ return plc_vertical_table($messages,'plc-warning');
}
-
-// fetch nodes - set pattern in the url for server-side filtering
-$node_columns=array('hostname','node_type','site_id','node_id','boot_state','interface_ids','peer_id');
+// fetch nodes
+$node_columns=array('hostname','node_type','site_id','node_id','boot_state','run_level','interface_ids','peer_id', 'arch','slice_ids');
+// server-side filtering - set pattern in $_GET for filtering on hostname
if ($pattern) {
$node_filter['hostname']=$pattern;
$title .= " matching " . $pattern;
}
// server-side selection on peerscope
-list ( $peer_filter, $peer_label) = plc_peer_info($api,$_GET['peerscope']);
-$node_filter=array_merge($node_filter,$peer_filter);
+$peerscope=new PeerScope($api,$_GET['peerscope']);
+$node_filter=array_merge($node_filter,$peerscope->filter());
+$title .= ' - ' . $peerscope->label();
if ($site_id) {
- $sites=$api->GetSites(array($site_id),array("name","login_base"));
+ $sites=$api->GetSites(array($site_id));
$site=$sites[0];
$name=$site['name'];
$login_base=$site['login_base'];
$title .= t_site($site);
- $tabs = array_merge($tabs,tabs_site($site));
+ $tabs []= tab_site($site);
$node_filter['site_id']=array($site_id);
}
$slices=$api->GetSlices(array($slice_id),array('node_ids','name'));
$slice=$slices[0];
$title .= t_slice($slice);
- $tabs = array_merge($tabs,tabs_slice($slice));
+ $tabs []= tab_slice($slice);
$node_filter['node_id'] = $slice['node_ids'];
}
+// person_id is set : this is mostly oriented towards people managing several sites
+if ($person_id) {
+ // avoid doing a useless call to GetPersons if the person_id is already known though $plc,
+ // as this is mostly done for the 'all my sites nodes' link
+ if ($person_id == plc_my_person_id()) {
+ $person=plc_my_person();
+ $site_ids = plc_my_site_ids();
+ } else {
+ // fetch the person's site_ids
+ $persons = $api->GetPersons(array('person_id'=>$person_id),array('person_id','email','site_ids'));
+ $person=$persons[0];
+ $site_ids=$person['site_ids'];
+ }
+ $title .= t_person($person);
+ $node_filter['site_id']=$site_ids;
+ }
+
// go
$nodes=$api->GetNodes($node_filter,$node_columns);
$interfaces=$api->GetInterfaces($interface_filter,$interface_columns);
$interface_hash=array();
-foreach ($interfaces as $interface) {
- $interface_hash[$interface['node_id']]=$interface;
-}
+foreach ($interfaces as $interface) $interface_hash[$interface['node_id']]=$interface;
// fetch related sites
$site_columns=array('site_id','login_base');
$sites=$api->GetSites($site_filter,$site_columns);
$site_hash=array();
-foreach ($sites as $site) {
- $site_hash[$site['site_id']]=$site;
-}
+foreach ($sites as $site) $site_hash[$site['site_id']]=$site;
// --------------------
drupal_set_title($title);
-plc_tabs($tabs);
+plekit_linetabs($tabs);
if ( ! $nodes ) {
drupal_set_message ('No node found');
return;
}
-$columns = array ("Peer"=>"string",
- "Region"=>"string",
- "Site"=>"string",
- "State"=>"string",
- "Hostname"=>"string",
- "IP"=>"IPAddress",
- "Type"=>"string",
- "?"=>"string",
- "Int"=>"int",
- "Float"=>"float");
+$nifty=new PlekitNifty ('','objects-list','big');
+$nifty->start();
+$headers = array (); $offset=0;
+if (plc_is_admin()) { $headers["I"]="int"; $offset=1; }
+$headers["P"]="string";
+$headers["R"]="string";
+$headers["Site"]="string";
+$headers["State"]="string";
+$headers["Hostname"]="string";
+$headers["Type"]="string";
+$headers["IP"]="sortIPAddress";
+$headers["A"]="string";
+$headers["S"]='int';
+$headers["?"]="string";
# initial sort on hostnames
-plc_table_start("nodes",$columns,4);
+$table=new PlekitTable ("nodes",$headers,4+$offset);
+$table->start();
-$peer_hash = plc_peer_get_hash ($api);
+$peers = new Peers ($api);
// write rows
-$fake1=1; $fake2=3.14; $fake_i=0;
foreach ($nodes as $node) {
- $hostname=$node['hostname'];
- $node_id=$node['node_id'];
- $site_id=$node['site_id'];
- $site=$site_hash[$site_id];
- $login_base = $site['login_base'];
- $node_id=$node['node_id'];
- $ip=$interface_hash[$node['node_id']]['ip'];
- $interface_id=$interface_hash[$node['node_id']]['interface_id'];
- $shortname = plc_peer_shortname ($peer_hash,$node['peer_id']);
- $node_type = $node['node_type'];
-
- plc_table_row_start($hostname);
- plc_table_cell ($shortname);
- plc_table_cell (topdomain($hostname));
- plc_table_cell (l_site2($site_id,$login_base));
- plc_table_cell ($node['boot_state']);
- plc_table_cell (l_node2($node_id,$hostname));
- plc_table_cell (l_interface2($interface_id,$ip));
- plc_table_cell ($node_type);
- plc_table_cell (node_status($node));
- plc_table_cell ($fake1);
- plc_table_cell ($fake2);
- plc_table_row_end();
-
- if ($fake_i % 5 == 0) $fake1 += 3;
- if ($fake_i % 3 == 0) $fake2 +=5; else $fake2 -= $fake_i;
- $fake_i += 1;
+ $hostname=$node['hostname'];
+ $node_id=$node['node_id'];
+ $site_id=$node['site_id'];
+ $site=$site_hash[$site_id];
+ $login_base = $site['login_base'];
+ $ip=$interface_hash[$node['node_id']]['ip'];
+ $interface_id=$interface_hash[$node['node_id']]['interface_id'];
+ $peer_id=$node['peer_id'];
+ $node_type = $node['node_type'];
+
+ $table->row_start();
+ if (plc_is_admin()) $table->cell(l_node_t($node_id,$node_id));
+ $peers->cell ($table,$peer_id);
+ $table->cell (topdomain($hostname));
+ $table->cell (l_site_t($site_id,$login_base));
+ if ($node['run_level']) {
+ $table->cell($node['run_level']);
+ } else {
+ $table->cell ($node['boot_state'] . '*');
+ }
+ $table->cell (l_node_t($node_id,$hostname));
+ $table->cell ($node_type);
+ $table->cell (l_interface_t($interface_id,$ip),array('only-if'=> !$peer_id));
+ $table->cell ($node['arch'],array('only-if'=> !$peer_id));
+ $table->cell (count($node['slice_ids']));
+ $table->cell (node_status($node));
+ $table->row_end();
+
}
-plc_table_end();
+$notes=array();
+if (plc_is_admin()) $notes []= "I = node_id";
+$notes []= "R = region";
+$notes []= "A = arch";
+$notes []= "S = number of slivers";
+$notes []= "? = status";
+$notes []= "status* = node doesn't have an observed state, preferred state is displayed";
+$table->end(array('notes'=>$notes));
+$nifty->end();
-plc_table_notes();
-?>
+//plekit_linetabs ($tabs,"bottom");
+// Print footer
+include 'plc_footer.php';
+
+?>