nodes can set tags, tags and nodegroups are mostly OK
[plewww.git] / planetlab / sites / site.php
1 <?php
2
3   // $Id: index.php 11750 2009-01-29 10:11:53Z 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_peers.php';
19 require_once 'plc_minitabs.php';
20 require_once 'plc_tables.php';
21 require_once 'plc_details.php';
22 require_once 'plc_forms.php';
23
24 // -------------------- 
25 // recognized URL arguments
26 $site_id=intval($_GET['id']);
27 if ( ! $site_id ) { plc_error('Malformed URL - id not set'); return; }
28
29 ////////////////////
30 // Get all columns as we focus on only one entry
31 $sites= $api->GetSites( array($site_id));
32
33 if (empty($sites)) {
34   drupal_set_message ("Site " . $site_id . " not found");
35   return;
36  }
37
38 $site=$sites[0];
39 // var names to api return
40 $sitename= htmlentities($site['name']);
41 $abbrev_name= htmlentities($site['abbreviated_name']);
42 $site_url= $site['url'];
43 $login_base= $site['login_base'];
44 $site_lat= $site['latitude'];
45 $site_long= $site['longitude'];
46 $max_slivers= $site['max_slivers'];
47 $max_slices= $site['max_slices'];
48
49 $enabled = $site['enabled'];
50
51 // extra privileges to admins, and (pi||tech) on this site
52 $privileges = plc_is_admin () || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech()));
53   
54 // get peer details
55 $peer_id= $site['peer_id'];
56 $peers = new Peers ($api);
57
58 $adress_ids= $site['address_ids'];
59 $pcu_ids= $site['pcu_ids'];
60 $node_ids= $site['node_ids'];
61 $person_ids= $site['person_ids'];
62 $slice_ids= $site['slice_ids'];
63
64 $api->begin();
65 // gets address info
66 $api->GetAddresses( $adress_ids );
67
68 // gets pcu info
69 // GetPCUs is not accessible to the 'user' role
70 //$api->GetPCUs( $pcu_ids );
71
72 // gets node info
73 $api->GetNodes( $node_ids, array( "node_id", "hostname", "boot_state" ) );
74
75 // gets person info
76 $api->GetPersons( $person_ids, array( "role_ids", "person_id", "first_name", "last_name", "email", "enabled" ) );
77
78 $api->GetSlices ( $slice_ids, array ("slice_id", "name", "instantiation" ) );
79
80 //list( $addresses, $pcus, $nodes, $persons, $slices )= $api->commit();
81 list( $addresses, $nodes, $persons, $slices )= $api->commit();
82   
83 $techs = array();
84 $pis = array();
85 foreach( $persons as $person ) {
86   $role_ids= $person['role_ids'];
87   if( in_array( '40', $role_ids ))
88     $techs[] = $person;
89   
90   if( in_array( '20', $role_ids ))
91     $pis[] = $person;
92   
93 }
94
95 drupal_set_title("Details for site " . $sitename);
96 $local_peer = ! $peer_id;
97   
98 // extra privileges to admins, and pi on this site
99 $privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi());
100   
101 $tabs=array();
102 // available actions
103 if ( $local_peer  && $privileges ) {
104   
105   $tabs['Update']=array('url'=>l_site_update($site_id),
106                         'bubble'=>"Update details of $sitename");
107   // not avail to PI
108   $tabs['Expire slices'] = array('url'=>l_actions(),
109                                  'method'=>'POST',
110                                  'values'=>array('site_id'=>$site_id,
111                                                  'action'=>'expire-all-slices-in-site'),
112                                  'bubble'=>"Expire all slices and prevent creation of new slices",
113                                  'confirm'=>"Suspend all slices in $login_base");
114   if (plc_is_admin())
115     $tabs['Delete']=array('url'=>l_actions(),
116                           'method'=>'POST',
117                           'values'=>array('site_id'=>$site_id,
118                                           'action'=>'delete-site'),
119                           'bubble'=>"Delete site $sitename",
120                           'confirm'=>"Are you sure you want to delete site $login_base");
121   $tabs["Events"]=array_merge (tabs_events(),
122                                array('url'=>l_event("Site","site",$site_id),
123                                      'bubble'=>"Events for site $sitename"));
124   $tabs["Comon"]=array_merge(tabs_comon(),
125                              array('url'=>l_comon("site_id",$site_id),
126                                    'bubble'=>"Comon page for $sitename"));
127
128   if (plc_is_admin()) 
129     $tabs['Pending'] = array ('url'=>l_sites_pending(),
130                               'bubble'=>'Review pending join requests');
131  }
132
133 $tabs["All sites"]=l_sites();
134
135 plc_tabs($tabs);
136
137 // show gray background on foreign objects : start a <div> with proper class
138 $peers->block_start ($peer_id);
139
140 if ( ! $enabled ) 
141   plc_warning ("This site is not enabled - Please visit " . 
142                href (l_sites_pending(),"this page") . 
143                " to review pending applications.");
144
145 plc_details_start();
146 plc_details_line("Full name",$sitename);
147 plc_details_line("Login base",$login_base);
148 plc_details_line("Abbreviated name",$abbrev_name);
149 plc_details_line("URL",$site_url);
150 plc_details_line("Latitude",$site_lat);
151 plc_details_line("Longitude",$site_long);
152 plc_details_line("Peer",$peers->peer_link($peer_id));
153
154 if ( $local_peer ) {
155
156   // Addresses
157   if ($addresses) {
158     plc_details_space_line();
159     plc_details_line("Addresses","");
160     foreach ($addresses as $address) {
161       plc_details_line(plc_vertical_table($address['address_types']),
162                        plc_vertical_table(array($address['line1'],
163                                                 $address['line2'],
164                                                 $address['line3'],
165                                                 $address['city'],
166                                                 $address['state'],
167                                                 $address['postalcode'],
168                                                 $address['country'])));
169     }
170   }
171
172   // Nodes
173   plc_details_space_line();
174   $nb_boot = 0;
175   if ($nodes) foreach ($nodes as $node) if ($node['boot_state'] == 'boot') $nb_boot ++;
176   $node_text = $nb_boot . " boot / " .  count($nodes) . " total";
177   plc_details_line("# Nodes", href(l_nodes_site($site_id),$node_text));
178   function n_link ($n) { return l_node_t($n['node_id'],$n['hostname'] . " (" . $n['boot_state'] . ")");}
179   $nodes_text= plc_vertical_table(array_map ("n_link",$nodes));
180   plc_details_line ("hostnames",$nodes_text);
181                    
182   // Users
183   plc_details_space_line();
184   $user_text = count($person_ids) . " total / " .
185     count ($pis) . " PIs / " .
186     count ($techs) . " techs";
187   if ( (count ($pis) == 0) || (count ($techs) == 0) || (count($person_ids) >=50)) 
188     $user_text = plc_warning_text ($user_text);
189   plc_details_line ("# Users",href(l_persons_site($site_id),$user_text));
190   function p_link ($p) { return l_person_t($p['person_id'],$p['email']); }
191   // PIs
192   $pi_text = plc_vertical_table (array_map ("p_link",$pis));
193   plc_details_line("PI's",$pi_text);
194   // PIs
195   $tech_text = plc_vertical_table (array_map ("p_link",$techs));
196   plc_details_line("techs's",$tech_text);
197
198   // Slices
199   plc_details_space_line();
200   // summary on # slices
201   $slice_text = count($slice_ids) . " running / " . $max_slices . " max";
202   if (count($slice_ids) >= $max_slices) $slice_text = plc_warning_text ($slice_text);
203   plc_details_line("# Slices", href(l_slices_site($site_id),$slice_text));
204   if ($slices) foreach ($slices as $slice)
205      plc_details_line($slice['instantiation'],l_slice_text($slice));
206
207
208  }
209
210 plc_details_end();
211
212 ////////////////////////////////////////
213 $peers->block_end($peer_id);
214
215 // Print footer
216 include 'plc_footer.php';
217
218 ?>