4 // Thierry on 2007-02-20
5 // There's no reason why we should see this page with a foreign slice, at least
6 // so long as the UI is used in a natural way, given the UI's logic as of now
7 // however it's always possible that someone forges her own url like
8 // http://one-lab.org/db/slices/slice_nodes?id=176
9 // So just to be consistent, we protect ourselves against such a usage
12 require_once 'plc_login.php';
14 // Get session and API handles
15 require_once 'plc_session.php';
16 global $plc, $api, $adm;
19 require_once 'plc_drupal.php';
20 drupal_set_title('Slices');
21 include 'plc_header.php';
24 require_once 'plc_functions.php';
25 require_once 'plc_sorts.php';
28 $_person= $plc->person;
29 $_roles= $_person['role_ids'];
31 //print_r( $_person );
33 // if no id ... redirect to slice index
34 if( !$_GET['id'] && !$_POST['id'] ) {
35 header( "location: index.php" );
40 // get slice id from GET or POST
42 $slice_id= intval( $_GET['id'] );
43 elseif ( $_POST['id'] )
44 $slice_id= intval( $_POST['id'] );
46 echo "no slice_id<br />\n";
49 // if add node submitted add the nodes to slice
51 $add_nodes= $_POST['add_nodes'];
53 foreach( $add_nodes as $nodes) {
54 $new_nodes[]= intval( $nodes );
58 $api->AddSliceToNodes( $slice_id, $new_nodes );
60 $errors= $api->error();
62 if( empty( $errors ) )
63 $added= "<font color=blue>Nodes Added.</font><br /><br />";
65 $added= "<font color=red>Error: '$errors'</font><br /><br />";
68 // if rem node submitted remove the nodes from slice
69 if( $_POST['remove'] ) {
70 $rem_nodes= $_POST['rem_nodes'];
72 foreach( $rem_nodes as $nodes) {
73 $new_nodes[]= intval( $nodes );
77 $api->DeleteSliceFromNodes( $slice_id, $new_nodes );
79 $errors= $api->error();
81 if( empty( $errors ) )
82 $removed= "<font color=blue>Nodes Removed.</font><br />";
84 $removed= "<font color=red>Error: '$errors'</font><br /><br />";
90 $slice_info= $adm->GetSlices( array( $slice_id ), array( "name", "node_ids", "peer_id" ) );
91 $slice_readonly = $slice_info[0]['peer_id'];
92 drupal_set_title("Slice " . $slice_info[0]['name'] . " - Nodes");
95 if( !empty( $slice_info[0]['node_ids'] ) )
96 $node_info= $adm->GetNodes( $slice_info[0]['node_ids'], array( "hostname", "node_id", "site_id" , "peer_id") );
98 // get site names and ids
99 $site_info= $adm->GetSites( NULL, array( "site_id", "name", "peer_id" ) );
100 sort_sites( $site_info );
102 // if site_id is in post use it, if not use the user's primary
103 if( $_POST['site_id'] )
104 $site_id= $_POST['site_id'];
106 $site_id= $_person['site_ids'][0];
109 // get site nodes for $site_id
110 if( $site_id == 'all_site' ) {
111 $full_node_info= $adm->GetNodes( array("node_type","regular"),
112 array( "hostname", "node_id" , "peer_id", "boot_state","last_updated") );
114 $snode_info= array();
115 foreach( $full_node_info as $full_node ) {
116 if( !in_array( $full_node['node_id'], $slice_info[0]['node_ids'] ) )
117 $snode_info[]= $full_node;
121 $sid= intval( $site_id );
122 $site_node_info= $adm->GetSites( array( $sid ), array( "node_ids" ) );
123 $site_nodes= $site_node_info[0]['node_ids'];
125 // gets all node_ids from site that arent already associated with the slice
126 foreach( $site_nodes as $snode) {
127 if( !in_array( $snode, $slice_info[0]['node_ids'] ) )
131 // Get node info from new list
132 if( !empty( $snodes ) )
133 $snode_info= $adm->GetNodes( $snodes, array( "hostname", "node_id" , "peer_id", "boot_state","last_updated" ) );
138 if ( $slice_readonly)
139 echo "<div class='plc-foreign'>";
141 echo "<form action='slice_nodes.php?id=$slice_id' method=post>\n";
143 // section for adding nodes : for local slices only
144 if ( ! $slice_readonly ) {
146 echo "<h5> Select a site to add nodes from.</h5>\n";
147 echo "<table><tr><td>";
148 if ($site_id != 'all_site') {
149 echo plc_comon_button("site_id",$site_id,"_blank");
152 echo "<select name='site_id' onChange='submit()'>\n";
153 echo "<option value='all_site'";
154 if( $site_id == 'all_site' )
156 echo ">--All Sites--</option>\n";
158 foreach( $site_info as $site ) {
159 echo "<option value=". $site['site_id'];
160 if( $site['site_id'] == $site_id )
162 if ($site["peer_id"])
163 echo " class='plc-foreign'";
164 echo ">". $site['name'] ."</option>\n";
168 echo "</select></td></tr></table>\n";
170 // show all availible nodes at $site_id
171 //echo "<pre>"; print_r( $snode_info ); echo "</pre>";
174 echo "<table cellpadding=2><tbody >\n<tr>";
175 echo "<th></th> <th> check </th><th>Hostname</th><th> Boot State </th><th> Last Update</th>
177 foreach( $snode_info as $snodes ) {
179 if ($snodes['peer_id']) {
180 $class="class='plc-foreign'";
182 echo "<tr " . $class . "><td>";
183 echo plc_comon_button("node_id",$snodes['node_id'],"_blank");
185 echo "<input type=checkbox name='add_nodes[]' value=". $snodes['node_id'] .">";
186 echo "</td><td align='center'>";
187 echo $snodes['hostname'];
188 echo "</td><td align='center'>";
189 echo $snodes['boot_state'];
190 echo "</td><td align='center'>";
191 echo date('Y-m-d',$snodes['last_updated']);
195 echo "</tbody></table>\n";
196 echo "<p><input type=submit value='Add Nodes' name='add'>\n";
198 echo "<p>No site nodes or all are already added.\n";
204 // show all nodes currently associated
206 echo "<h5>Nodes currently associated with slice</h5>\n";
208 if ( ! $slice_readonly) {
209 echo "<u>Check boxes of nodes to remove:</u>\n";
210 echo "<table cellpadding=2><tbody><tr>\n";
211 echo "<th></th> <th> check </th><th>Hostname</th><th> Boot State </th><th> Last Update</th>
214 echo "<table cellpadding=2><tbody><tr>\n";
215 echo "<th></th> <th> check </th><th>Hostname</th><th> Boot State </th><th> Last Update</th>
219 foreach( $node_info as $node ) {
221 if ($node['peer_id']) {
222 $class="class='plc-foreign'";
224 if ( ! $slice_readonly) {
225 echo "<tr " . $class . "><td>";
226 echo plc_comon_button("node_id",$node['node_id'],"_blank");
228 echo "<input type=checkbox name='rem_nodes[]' value=". $node['node_id'] .">";
230 echo $node['hostname'];
231 echo "</td><td align='center'>";
232 echo $snodes['boot_state'];
233 echo "</td><td align='center'>";
234 echo date('Y-m-d',$snodes['last_updated']);
237 echo "<tr " . $class . "><td>";
238 echo plc_comon_button("node_id",$node['node_id'],"_blank");
240 echo $node['hostname'];
246 echo "</tbody></table>\n";
247 if ( ! $slice_readonly)
248 echo "<p><input type=submit value='Remove Nodes' name='remove'>\n";
251 echo "<p>No nodes associated with slice.\n";
259 echo "<p><a href='index.php?id=$slice_id'>Back to Slice</a>\n";
263 include 'plc_footer.php';