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 plc_redirect( l_slices());
39 // get slice id from GET or POST
41 $slice_id= intval( $_GET['id'] );
42 elseif ( $_POST['id'] )
43 $slice_id= intval( $_POST['id'] );
45 echo "no slice_id<br />\n";
48 // if add node submitted add the nodes to slice
50 $add_nodes= $_POST['add_nodes'];
52 foreach( $add_nodes as $nodes) {
53 $new_nodes[]= intval( $nodes );
57 $api->AddSliceToNodes( $slice_id, $new_nodes );
59 $errors= $api->error();
61 if( empty( $errors ) )
62 $added= "<font color=blue>Nodes Added.</font><br /><br />";
64 $added= "<font color=red>Error: '$errors'</font><br /><br />";
67 // if rem node submitted remove the nodes from slice
68 if( $_POST['remove'] ) {
69 $rem_nodes= $_POST['rem_nodes'];
71 foreach( $rem_nodes as $nodes) {
72 $new_nodes[]= intval( $nodes );
76 $api->DeleteSliceFromNodes( $slice_id, $new_nodes );
78 $errors= $api->error();
80 if( empty( $errors ) )
81 $removed= "<font color=blue>Nodes Removed.</font><br />";
83 $removed= "<font color=red>Error: '$errors'</font><br /><br />";
89 $slice_info= $adm->GetSlices( array( $slice_id ), array( "name", "node_ids", "peer_id" ) );
90 $slice_readonly = $slice_info[0]['peer_id'];
91 drupal_set_title("Slice " . $slice_info[0]['name'] . " - Nodes");
94 if( !empty( $slice_info[0]['node_ids'] ) )
95 $node_info= $adm->GetNodes( $slice_info[0]['node_ids'], array( "hostname", "node_id", "site_id" , "peer_id") );
97 // get site names and ids
98 $site_info= $adm->GetSites( NULL, array( "site_id", "name", "peer_id" ) );
99 sort_sites( $site_info );
101 // if site_id is in post use it, if not use the user's primary
102 if( $_POST['site_id'] )
103 $site_id= $_POST['site_id'];
105 $site_id= $_person['site_ids'][0];
108 // get site nodes for $site_id
109 if( $site_id == 'all_site' ) {
110 $full_node_info= $adm->GetNodes( array("node_type","regular"),
111 array( "hostname", "node_id" , "peer_id", "boot_state","last_updated") );
113 $snode_info= array();
114 foreach( $full_node_info as $full_node ) {
115 if( !in_array( $full_node['node_id'], $slice_info[0]['node_ids'] ) )
116 $snode_info[]= $full_node;
120 $sid= intval( $site_id );
121 $site_node_info= $adm->GetSites( array( $sid ), array( "node_ids" ) );
122 $site_nodes= $site_node_info[0]['node_ids'];
124 // gets all node_ids from site that arent already associated with the slice
125 foreach( $site_nodes as $snode) {
126 if( !in_array( $snode, $slice_info[0]['node_ids'] ) )
130 // Get node info from new list
131 if( !empty( $snodes ) )
132 $snode_info= $adm->GetNodes( $snodes, array( "hostname", "node_id" , "peer_id", "boot_state","last_updated" ) );
137 if ( $slice_readonly)
138 echo "<div class='plc-foreign'>";
140 echo "<form action='slice_nodes.php?id=$slice_id' method=post>\n";
142 // section for adding nodes : for local slices only
143 if ( ! $slice_readonly ) {
145 echo "<h5> Select a site to add nodes from.</h5>\n";
146 echo "<table><tr><td>";
147 if ($site_id != 'all_site') {
148 echo plc_comon_button("site_id",$site_id,"_blank");
151 echo "<select name='site_id' onChange='submit()'>\n";
152 echo "<option value='all_site'";
153 if( $site_id == 'all_site' )
155 echo ">--All Sites--</option>\n";
157 foreach( $site_info as $site ) {
158 echo "<option value=". $site['site_id'];
159 if( $site['site_id'] == $site_id )
161 if ($site["peer_id"])
162 echo " class='plc-foreign'";
163 echo ">". $site['name'] ."</option>\n";
167 echo "</select></td></tr></table>\n";
169 // show all availible nodes at $site_id
170 //echo "<pre>"; print_r( $snode_info ); echo "</pre>";
173 echo "<table cellpadding=2><tbody >\n<tr>";
174 echo "<th></th> <th> check </th><th>Hostname</th><th> Boot State </th><th> Last Update</th>
176 foreach( $snode_info as $snodes ) {
178 if ($snodes['peer_id']) {
179 $class="class='plc-foreign'";
181 echo "<tr " . $class . "><td>";
182 echo plc_comon_button("node_id",$snodes['node_id'],"_blank");
184 echo "<input type=checkbox name='add_nodes[]' value=". $snodes['node_id'] .">";
185 echo "</td><td align='center'>";
186 echo $snodes['hostname'];
187 echo "</td><td align='center'>";
188 echo $snodes['boot_state'];
189 echo "</td><td align='center'>";
190 echo date('Y-m-d',$snodes['last_updated']);
194 echo "</tbody></table>\n";
195 echo "<p><input type=submit value='Add Nodes' name='add'>\n";
197 echo "<p>No site nodes or all are already added.\n";
203 // show all nodes currently associated
205 echo "<h5>Nodes currently associated with slice</h5>\n";
207 if ( ! $slice_readonly) {
208 echo "<u>Check boxes of nodes to remove:</u>\n";
209 echo "<table cellpadding=2><tbody><tr>\n";
210 echo "<th></th> <th> check </th><th>Hostname</th><th> Boot State </th><th> Last Update</th>
213 echo "<table cellpadding=2><tbody><tr>\n";
214 echo "<th></th> <th> check </th><th>Hostname</th><th> Boot State </th><th> Last Update</th>
218 foreach( $node_info as $node ) {
220 if ($node['peer_id']) {
221 $class="class='plc-foreign'";
223 if ( ! $slice_readonly) {
224 echo "<tr " . $class . "><td>";
225 echo plc_comon_button("node_id",$node['node_id'],"_blank");
227 echo "<input type=checkbox name='rem_nodes[]' value=". $node['node_id'] .">";
229 echo $node['hostname'];
230 echo "</td><td align='center'>";
231 echo $snodes['boot_state'];
232 echo "</td><td align='center'>";
233 echo date('Y-m-d',$snodes['last_updated']);
236 echo "<tr " . $class . "><td>";
237 echo plc_comon_button("node_id",$node['node_id'],"_blank");
239 echo $node['hostname'];
245 echo "</tbody></table>\n";
246 if ( ! $slice_readonly)
247 echo "<p><input type=submit value='Remove Nodes' name='remove'>\n";
250 echo "<p>No nodes associated with slice.\n";
258 echo "<p><a href='index.php?id=$slice_id'>Back to Slice</a>\n";
262 include 'plc_footer.php';