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