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