moving the onelab www to a fresh location
[plewww.git] / planetlab / nodes / slivers.php
1 <?php
2
3 // Require login
4 require_once 'plc_login.php';
5
6 // Get session and API handles
7 require_once 'plc_session.php';
8 global $plc, $api;
9
10 // Print header
11 require_once 'plc_drupal.php';
12 drupal_set_title('Slivers');
13 include 'plc_header.php';
14
15 // Common functions
16 require_once 'plc_functions.php';
17 require_once 'plc_sorts.php';
18
19 // find person roles
20 $_person= $plc->person;
21 $_roles= $_person['role_ids'];
22
23 //print_r( $_person );
24
25
26 // if add is set, diplay add sliver form
27 if( $_GET['add'] ) {
28   $node_id= $_GET['add'];
29   $slice_id= $_GET['slice'];
30
31   // slice info
32   $slice_info= $api->GetSlices( array( intval( $slice_id ) ), array( "name" ) );
33
34   // node info
35   $node_info= $api->GetNodes( array( intval( $node_id ) ), array( "hostname" ) );
36
37   // get tag types
38   $type_info= $api->GetTagTypes( NULL, array( "tag_type_id", "tagname" ) );
39   
40   // get the slivers for this node
41   $sliver_info= $api->GetSliceTags( array( "node_id"=>intval( $node_id ), "slice_id"=>intval( $slice_id ) ), array( "tag_type_id", "name" ) );
42
43     $types_left= $type_info;
44
45
46   // start form
47   echo "<form action='sliver_action.php' method=post>\n
48   <h2>Add a Sliver Tag to ". $slice_info[0]['name'] ." on node ". $node_info[0]['hostname'] ."</h2>\n
49   <table class='list_set' border=0 cellpadding=2><tbody>\n
50   <tr class='list_set'><th class='list_set'>Tag: </th><td class='list_set'><select name='sliver'>\n";
51
52   foreach( $types_left as $type ) {
53     echo "<option value='". $type['tag_type_id'] ."'>". $type['name'] ."</option>\n";
54
55   }
56
57   echo "</td><td class='list_set'></td></tr>\n
58   <tr class='list_set'><th class='list_set'>Value: </th><td class='list_set'><input type=text name='value'></td></tr>\n
59   </tbody></table>\n
60   <input type=hidden name='node_id' value='$node_id'><input type=hidden name='slice_id' value='$slice_id'>
61   <p><input type=submit name='add_sub' value='Add Sliver Tag'>\n";
62
63   echo "<p><a href='index.php?id=$node_id'>Back to Node</a>\n</form>\n";
64   
65 }
66
67
68 // if slice and node ids are passed display slivers and tags
69 if( $_GET['slice'] && $_GET['node'] ) {
70   $slice_id= $_GET['slice'];
71   $node_id= $_GET['node'];
72
73   // slice info
74   $slice_info= $api->GetSlices( array( intval( $slice_id ) ), array( "name" ) );
75
76   // node info
77   $node_info= $api->GetNodes( array( intval( $node_id ) ), array( "hostname" ) );
78
79   // get the slivers for this node
80   $sliver_info= $api->GetSliceTags( array( "node_id"=>intval( $node_id ), "slice_id"=>intval( $slice_id ) ), array( "slice_tag_id", "name", "value", "min_role_id", "description" ) );
81
82   // get the attrbibutes for this slice
83   $tag_info= $api->GetSliceTags( array( intval( $slice_id ) ), array( "slice_tag_id", "name", "value", "min_role_id", "description" ) );
84
85
86   // start form
87   echo "<form action='slivers.php' method=post>\n<h2>Sliver Details for slice ". $slice_info[0]['name'] ." on node ". $node_info[0]['hostname'] ."</h2>\n";
88
89   // sliver tags of slice
90   if( empty( $sliver_info ) )
91     // if no sliver exists tell user
92     echo "No sliver tag for this node/slice sliver combination.\n";
93   else {
94     echo "<p><table class='list_set' border=0 cellpadding=2>\n<caption class='list_set'>Slivers</caption>\n<thead><tr class='list_set'><th class='list_set'>Name</th><th class='list_set'>Value</th><th class='list_set'>Min Roll</th><th class='list_set'>Description</th>";
95     if ( in_array( 10, $_roles ) || ( in_array( 20, $_roles ) && in_array( $node_info, $_person['site_ids'] ) ) ) echo "<th></th><th></th>";
96     echo "</tr></thead><tbody>\n";
97
98     foreach( $sliver_info AS $sliver ) {
99       echo "<tr><td>". $sliver['name'] ."</td><td>". $sliver['value'] ."</td><td>". $sliver['min_role_id'] ."</td><td>". $sliver['description'] ."</td>";
100       if ( in_array( 10, $_roles ) || ( in_array( 20, $_roles ) && in_array( $node_info, $_person['site_ids'] ) ) ) echo "<td><a href='/db/slices/tags.php?type=slice&id=". $sliver['slice_tag_id'] ."'>Edit</a></td><td><a href='sliver_action.php?rem_id=". $sliver['slice_tag_id'] ."' onclick=\"javascript:return confirm('Are you sure you want to remove ". $sliver['name'] ." from node ". $node_info[0]['hostname'] ."?')\">Remove</a></td>";
101       echo "</tr>\n";
102
103
104     }
105
106     echo "</tbody></table>\n";
107
108   }
109   
110   if ( in_array( 10, $_roles ) || ( in_array( 20, $_roles ) && in_array( $node_info, $_person['site_ids'] ) ) ) echo "<p><a href='slivers.php?add=$node_id&slice=$slice_id'>Add Sliver Tag</a>\n";
111
112   echo "<br /><hr />";
113
114   // regular tags of slice
115   if( empty( $tag_info ) )
116     // if no tags exist tell user
117     echo "No Tags for this slice.\n";
118   else {
119     echo "<p><table class='list_set' border=0 cellpadding=2>\n<caption class='list_set'>Tags</caption>\n<thead><tr class='list_set'><th class='list_set'>Name</th><th class='list_set'>Value</th><th class='list_set'>Min Roll</th><th class='list_set'>Description</th>";
120     if ( in_array( 10, $_roles ) || ( in_array( 20, $_roles ) && in_array( $node_info, $_person['site_ids'] ) ) ) echo "<th></th>";
121     echo "</tr></thead><tbody>\n";
122
123     foreach( $tag_info AS $tag ) {
124       echo "<tr><td>". $tag['name'] ."</td><td>". $tag['value'] ."</td><td>". $tag['min_role_id'] ."</td><td>". $tag['description'] ."</td>";
125       if ( in_array( 10, $_roles ) || ( in_array( 20, $_roles ) && in_array( $node_info, $_person['site_ids'] ) ) ) echo "<td><a href='tags.php?type=slice&id=". $tag['slice_tag_id'] ."'>Edit</a></td>";
126       echo "</tr>\n";
127
128
129     }
130
131     echo "</tbody></table>\n";
132
133   }
134
135
136   echo "<p><a href='index.php?id=$node_id'>Back to Node</a>\n</form>\n";
137
138 }
139
140
141 // Print footer
142 include 'plc_footer.php';
143
144 ?>