checkpoint
[plewww.git] / planetlab / nodes / node.php
1 <?php
2
3 // $Id: index.php 11577 2009-01-16 06:29:51Z thierry $
4
5 // Require login
6 require_once 'plc_login.php';
7
8 // Get session and API handles
9 require_once 'plc_session.php';
10 global $plc, $api;
11
12 // Print header
13 require_once 'plc_drupal.php';
14 include 'plc_header.php';
15
16 // Common functions
17 require_once 'plc_functions.php';
18 require_once 'plc_minitabs.php';
19 require_once 'plc_tables.php';
20
21 // tmp 
22 //require_once 'plc_sorts.php';
23 // find person roles
24 $_person= $plc->person;
25 $_roles= $_person['role_ids'];
26
27 // -------------------- 
28 // recognized URL arguments
29 $node_id=intval($_GET['id']);
30 if ( ! $node_id ) { plc_error('Malformed URL - id not set'); return; }
31
32 ////////////////////
33 // Get all columns as we focus on only one entry
34 $nodes= $api->GetNodes( array($node_id));
35
36 if (empty($nodes)) {
37   drupal_set_message ("Node " . $node_id . " not found");
38  } else {
39   $node=$nodes[0];
40     // node info
41   $hostname= $node['hostname'];
42   $boot_state= $node['boot_state'];
43   $site_id= $node['site_id'];
44   $model= $node['model'];
45   $version= $node['version'];
46   $node_type = $node['node_type'];
47
48   // arrays of ids of node info
49   $slice_ids= $node['slice_ids'];
50   $conf_file_ids= $node['conf_file_ids'];
51   $interface_ids= $node['interface_ids'];
52   $nodegroup_ids= $node['nodegroup_ids'];
53   $pcu_ids= $node['pcu_ids'];
54
55   // get peer
56   $peer_id= $node['peer_id'];
57
58   // gets site info
59   $sites= $api->GetSites( array( $site_id ) );
60   $site=$sites[0];
61   $site_name= $site['name'];
62   $site_node_ids= $site['node_ids'];
63
64   $site_node_hash=array();
65   if( !empty( $site_node_ids ) ) {
66     // get site node info basics
67     $site_nodes= $api->GetNodes( $site_node_ids );
68     
69     foreach( $site_nodes as $site_node ) {
70       $site_node_hash[$site_node['node_id']]= $site_node['hostname'];
71     }
72   }
73   
74   // gets slice info for each slice
75   if( !empty( $slice_ids ) )
76     $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" , "peer_id" ) );
77
78   // gets conf file info
79   if( !empty( $conf_file_ids ) )
80     $conf_files= $api->GetConfFiles( $conf_file_ids );
81
82   // get interface info
83   if( !empty( $interface_ids ) )
84     $interfaces= $api->GetInterfaces( $interface_ids );
85
86   // gets nodegroup info
87   if( !empty( $nodegroup_ids ) )
88     $nodegroups= $api->GetNodeGroups( $nodegroup_ids, array("groupname","tag_type_id","value"));
89
90   // xxx Thierry : disabling call to GetEvents, that gets the session deleted in the DB
91   // needs being reworked
92
93   // gets pcu and port info key to both is $pcu_id
94   if( !empty( $pcu_ids ) )
95     $PCUs= $api->GetPCUs( $pcu_ids );
96
97
98   // display node info
99   plc_peer_block_start ($peer_hash,$peer_id);
100   
101   drupal_set_title("Details for node " . $hostname);
102   
103   // extra privileges to admins, and (pi||tech) on this site
104   $extra_privileges = plc_is_admin () || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech()));
105   
106   $tabs=array();
107   // available actions
108   if ( ! $peer_id  && $extra_privileges ) {
109     
110     $tabs["All nodes"]=l_nodes();
111     // xxx subject to roles
112     $tabs["Add Interface"]=l_interface_add_u($node_id);
113     $tabs["Comon"]=l_comon("node_id",$node_id);
114     if ($extra_privileges) {
115       $tabs["Events"]=l_event("Node","node",$node_id);
116     }
117     plc_tabs($tabs);
118
119     // the javascript callback we set on the form; this
120     // (*) checks whether we clicked on 'delete'
121     // (*) in this case performs a javascript 'confirm'
122     // (*) then, notice that if we select delete, then cancel, we can select back 'Choose action' 
123     //     so submit only when value is not empty
124     $change='if (document.actions.action.value=="delete") if (! confirm("Are you sure you want to delete ' . $hostname . ' ? ") ) return false; if (document.actions.action.value!="") submit();';
125     
126     echo "<table><tr><td>";
127     echo "</td><td>";
128     echo "<form name='actions' action='/db/nodes/node_actions.php' method='post'>\n";
129     echo "<input type=hidden name='node_id' value='$node_id'></input>\n";
130     echo "<select name='action' onChange='$change'>\n";
131     echo "<option value='' selected='selected'> Choose Action </option>\n";
132     echo "<option value='prompt-update'> Update $hostname </option>\n";
133     echo "<option value='delete'> Delete $hostname </option>\n";
134     echo "</select></form>\n";
135     
136     echo "</td></tr></table>";
137   }    
138   
139   echo "<hr />";
140   echo "<table><tbody>\n";
141   
142   echo "<tr><th>Hostname: </th><td> $hostname </td></tr>\n";
143   echo "<tr><th>Type: </th><td> $node_type</td></tr>\n";
144   echo "<tr><th>Model: </th><td> $model</td></tr>\n";
145   echo "<tr><th>Version: </th><td> $version</td></tr>\n";
146     
147   echo "<tr><th>Boot State: </th><td>";
148   if ($peer_id) {
149     echo $boot_state;
150   } else {
151     echo "<form name='bootstate' action='/db/nodes/node_actions.php' method=post>\n";
152     echo "<input type=hidden name='node_id' value='$node_id'>\n";
153     echo "<input type=hidden name='action' value='boot-state'>\n";
154     echo "<select name='boot_state' onChange=\"submit();\">\n";
155
156     $states= array( 'boot'=>'Boot', 'dbg'=>'Debug', 'inst'=>'Install', 'rins'=>'Reinstall', 'rcnf'=>'Reconfigure', 'new'=>'New' );
157
158     foreach( $states as $key => $val ) {
159       echo "<option value='$key'";
160       
161       if( $key == $boot_state )
162         echo " selected";
163       
164       echo ">$val</option>\n";
165       
166     }
167   
168     echo "</select></input></form>";
169   }
170   echo "</td></tr>\n";
171
172   if ( ! $peer_id  && $extra_privileges) {
173
174     echo "<tr><th>Download </th><td>";
175     echo "<form name='download' action='/db/nodes/node_actions.php' method='post'>\n";
176     echo "<input type=hidden name='node_id' value='$node_id'></input>\n";
177     echo "<select name='action' onChange='submit();'>\n";
178     echo "<option value='' selected='selected'> Download Mode </option>\n";
179     echo "<option value='' disabled='disabled'> -- All in one images -- </option>"; 
180     echo "<option value='download-node-iso' $new_api_only> Download ISO image for $hostname</option>\n";
181     echo "<option value='download-node-usb' $new_api_only> Download USB image for $hostname</option>\n";
182     echo "<option value='' disabled='disabled'> -- Floppy + generic image -- </option>"; 
183     echo "<option value='download-node-floppy'> Download Floppy file for $hostname</option>\n";
184     echo "<option value='download-generic-iso' $new_api_only> Download generic ISO image (requires floppy) </option>\n";
185     echo "<option value='download-generic-usb' $new_api_only> Download generic USB image (requires floppy) </option>\n";
186     echo "</select></form>";
187     echo "</td></tr>\n";
188
189   }
190
191   // site info and all site nodes
192   echo "<tr><td colspan=2>&nbsp;</td></tr>\n";
193   echo "<tr><th>Site: </th><td> <a href='/db/sites/index.php?id=$site_id'>$site_name</a></td></tr>\n";
194   echo "<tr><th>All site nodes: </th><td>";
195   if (empty($site_node_hash)) {
196     echo "<span class='plc-warning'>Site has no node</span>";
197   } else {
198     foreach( $site_node_hash as $key => $val ) {
199       echo "<a href=index.php?id=$key>$val</a><br />";
200     }
201   }
202   echo "</td></tr>\n";
203
204   echo "</tbody></table><br />\n";
205     
206   //////////////////////////////////////////////////////////// interfaces
207   if ( ! $peer_id ) {
208
209     // display interfaces
210     if( ! $interfaces ) {
211       echo "<p><span class='plc-warning'>No interface</span>.  Please add an interface to make this a usable PLC node</p>.\n";
212     } else {
213       $columns=array();
214       if ( $extra_privileges ) {
215         // a single symbol, marking 'p' for primary and a delete button for non-primary
216         $columns[' ']='string';
217       }
218          
219       $columns["IP"]="IPAddress";
220       $columns["Method"]="string";
221       $columns["Type"]="string";
222       $columns["MAC"]="string";
223       $columns["bw limit"]="FileSize";
224
225       print "<hr/>\n";
226       plc_table_title('Interfaces');
227       plc_table_start("interfaces",$columns,2,false);
228         
229       foreach ( $interfaces as $interface ) {
230         $interface_id= $interface['interface_id'];
231         $interface_ip= $interface['ip'];
232         $interface_broad= $interface['broadcast'];
233         $interface_primary= $interface['is_primary'];
234         $interface_network= $interface['network'];
235         $interface_dns1= $interface['dns1'];
236         $interface_dns2= $interface['dns2'];
237         $interface_hostname= $interface['hostname'];
238         $interface_netmaks= $interface['netmask'];
239         $interface_gatewary= $interface['gateway'];
240         $interface_mac= $interface['mac'];
241         $interface_bwlimit= $interface['bwlimit'];
242         $interface_type= $interface['type'];
243         $interface_method= $interface['method'];
244
245         plc_table_row_start($interface['ip']);
246         if ( $extra_privileges ) {
247           if (!$interface_primary) {
248             // xxx 
249             plc_table_cell (plc_delete_link_button ('interfaces.php?id=' . $interface_id . '&delete=1&submitted=1', 
250                                                     '\\nInterface ' . $interface_ip));
251           } else {
252             plc_table_cell('p');
253           }
254         }
255         plc_table_cell(l_interface2($interface_id,$interface_ip));
256         plc_table_cell($interface_method);
257         plc_table_cell($interface_type);
258         plc_table_cell($interface_mac);
259         plc_table_cell($interface_bwlimit);
260         plc_table_row_end();
261       }
262       plc_table_end();
263     }
264       
265   }
266
267   //////////////////////////////////////////////////////////// slices
268   // display slices
269   $peer_hash = plc_peer_get_hash ($api);
270
271   print "<hr/>\n";
272   plc_table_title ("Slices");
273   if ( ! $slices  ) {
274     echo "<p><span class='plc-warning'>This node is not associated to any slice.</span></p>\n";
275   } else {
276     $columns=array();
277     $columns['Peer']="string";
278     $columns['Name']="string";
279     $columns['Slivers']="string";
280     plc_table_start ("slivers",$columns,1);
281
282     foreach ($slices as $slice) {
283       plc_table_row_start($slice['name']);
284       plc_table_cell (plc_peer_shortname($peer_hash,$slice['peer_id']));
285       plc_table_cell (l_slice2 ($slice['slice_id'],$slice['name']));
286       plc_table_cell (l_sliver3 ($node_id,$slice['slice_id'],'view'));
287       plc_table_row_end();
288     }
289     plc_table_end();
290   }
291
292   //////////////////////////////////////////////////////////// nodegroups
293   // display node group info
294   if ( ! $nodegroups ) {
295     echo "<p><span class='plc-warning'>This node is not in any nodegroup.</span></p>\n";
296   } else {
297     $columns=array();
298     $columns['Name']="string";
299     $columns['Tag']="string";
300     $columns['Value']="string";
301       
302     print "<hr/>\n";
303     plc_table_title("Nodegroups");
304     plc_table_start("nodegroups",$columns,0,false);
305
306     foreach( $nodegroups as $nodegroup ) {
307       plc_table_row_start();
308       plc_table_cell(l_nodegroup2($nodegroup_id,$nodegroup['groupname']));
309       $tag_types=$api->GetTagTypes(array($nodegroup['tag_type_id']));
310       plc_table_cell($tag_types[0]['tagname']);
311       plc_table_cell($nodegroup['value']);
312       plc_table_row_end();
313     }
314     plc_table_end();
315   }    
316
317   ////////////////////////////////////////////////////////////
318   plc_peer_block_end();
319 }
320
321 // Print footer
322 include 'plc_footer.php';
323
324 ?>