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