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_peers.php';
19 require_once 'linetabs.php';
20 require_once 'table.php';
21 require_once 'nifty.php';
23 ini_set("memory_limit","64M");
25 // --------------------
26 // recognized URL arguments
27 $peerscope=$_GET['peerscope'];
28 $pattern=$_GET['pattern'];
29 $site_id=intval($_GET['site_id']);
30 $slice_id=intval($_GET['slice_id']);
31 $person_id=intval($_GET['person_id']);
36 $tabs []= tab_nodes();
37 if (count (plc_my_site_ids()) == 1) {
38 $tabs []= tab_nodes_mysite();
40 $tabs []= tab_nodes_all_mysite();
42 $tabs []= tab_nodes_local();
44 // --------------------
48 // performs sanity check and summarize the result in a single column
49 function node_status ($node) {
51 // do all this stuff on local nodes only
52 if ( $node['peer_id'] )
56 // check that the node has interfaces
57 if (count($node['interface_ids']) == 0) {
58 $messages [] = "No interface";
60 return plc_vertical_table($messages,'plc-warning');
64 $node_columns=array('hostname','node_type','site_id','node_id','boot_state','run_level','interface_ids','peer_id', 'arch','slice_ids');
65 // server-side filtering - set pattern in $_GET for filtering on hostname
67 $node_filter['hostname']=$pattern;
68 $title .= " matching " . $pattern;
70 $node_filter['hostname']="*";
73 // server-side selection on peerscope
74 $peerscope=new PeerScope($api,$_GET['peerscope']);
75 $node_filter=array_merge($node_filter,$peerscope->filter());
76 $title .= ' - ' . $peerscope->label();
79 $sites=$api->GetSites(array($site_id));
82 $login_base=$site['login_base'];
83 $title .= t_site($site);
84 $tabs []= tab_site($site);
85 $node_filter['site_id']=array($site_id);
89 $slices=$api->GetSlices(array($slice_id),array('node_ids','name'));
91 $title .= t_slice($slice);
92 $tabs []= tab_slice($slice);
93 $node_filter['node_id'] = $slice['node_ids'];
96 // person_id is set : this is mostly oriented towards people managing several sites
98 // avoid doing a useless call to GetPersons if the person_id is already known though $plc,
99 // as this is mostly done for the 'all my sites nodes' link
100 if ($person_id == plc_my_person_id()) {
101 $person=plc_my_person();
102 $site_ids = plc_my_site_ids();
104 // fetch the person's site_ids
105 $persons = $api->GetPersons(array('person_id'=>$person_id),array('person_id','email','site_ids'));
107 $site_ids=$person['site_ids'];
109 $title .= t_person($person);
110 $node_filter['site_id']=$site_ids;
114 $nodes=$api->GetNodes($node_filter,$node_columns);
116 // build site_ids - interface_ids
118 $interface_ids=array();
119 if ($nodes) foreach ($nodes as $node) {
120 $site_ids []= $node['site_id'];
121 $interface_ids = array_merge ($interface_ids,$node['interface_ids']);
124 // fetch related interfaces
125 $interface_columns=array('ip','node_id','interface_id');
126 $interface_filter=array('is_primary'=>TRUE,'interface_id'=>$interface_ids);
127 $interfaces=$api->GetInterfaces($interface_filter,$interface_columns);
129 $interface_hash=array();
130 foreach ($interfaces as $interface) $interface_hash[$interface['node_id']]=$interface;
132 // fetch related sites
133 $site_columns=array('site_id','login_base');
134 $site_filter=array('site_id'=>$site_ids);
135 $sites=$api->GetSites($site_filter,$site_columns);
138 foreach ($sites as $site) $site_hash[$site['site_id']]=$site;
140 // --------------------
141 drupal_set_title($title);
143 plekit_linetabs($tabs);
146 drupal_set_message ('No node found');
150 $nifty=new PlekitNifty ('','objects-list','big');
152 $headers = array (); $offset=0;
153 if (plc_is_admin()) { $headers["I"]="int"; $offset=1; }
154 $headers["P"]="string";
155 $headers["R"]="string";
156 $headers["Site"]="string";
157 $headers["State"]="string";
158 $headers["Hostname"]="string";
159 $headers["Type"]="string";
160 $headers["IP"]="sortIPAddress";
161 $headers["A"]="string";
163 $headers["?"]="string";
165 # initial sort on hostnames
166 $table=new PlekitTable ("nodes",$headers,4+$offset);
169 $peers = new Peers ($api);
171 foreach ($nodes as $node) {
172 $hostname=$node['hostname'];
173 $node_id=$node['node_id'];
174 $site_id=$node['site_id'];
175 $site=$site_hash[$site_id];
176 $login_base = $site['login_base'];
177 $ip=$interface_hash[$node['node_id']]['ip'];
178 $interface_id=$interface_hash[$node['node_id']]['interface_id'];
179 $peer_id=$node['peer_id'];
180 $node_type = $node['node_type'];
183 if (plc_is_admin()) $table->cell(l_node_t($node_id,$node_id));
184 $peers->cell ($table,$peer_id);
185 $table->cell (topdomain($hostname));
186 $table->cell (l_site_t($site_id,$login_base));
187 if ($node['run_level']) {
188 $table->cell($node['run_level']);
190 $table->cell ($node['boot_state'] . '*');
192 $table->cell (l_node_t($node_id,$hostname));
193 $table->cell ($node_type);
194 $table->cell (l_interface_t($interface_id,$ip),array('only-if'=> !$peer_id));
195 $table->cell ($node['arch'],array('only-if'=> !$peer_id));
196 $table->cell (count($node['slice_ids']));
197 $table->cell (node_status($node));
203 if (plc_is_admin()) $notes []= "I = node_id";
204 $notes []= "R = region";
205 $notes []= "A = arch";
206 $notes []= "S = number of slivers";
207 $notes []= "? = status";
208 $notes []= "status* = node doesn't have an observed state, preferred state is displayed";
209 $table->end(array('notes'=>$notes));
212 //plekit_linetabs ($tabs,"bottom");
215 include 'plc_footer.php';