4 require_once 'plc_login.php';
6 // Get session and API handles
7 require_once 'plc_session.php';
11 require_once 'plc_functions.php';
12 require_once 'details.php';
13 require_once 'table.php';
14 require_once 'toggle.php';
16 //plc_debug('POST',$_POST);
18 // if not a PI or admin then redirect to slice index
19 $has_privileges = plc_is_admin() || plc_is_pi();
20 if ( ! $has_privileges ) {
21 drupal_set_error("Insufficient privilege to add a slice");
22 header( "index.php" );
26 // find out which site the slice should be added to
27 // without site_id set in GET, we use the first site that this user is in
28 if (isset($_GET['site_id'])) {
29 $site_id=intval($_GET['site_id']);
30 } else if (isset ($_POST['site_id'])) {
31 $site_id=intval($_POST['site_id']);
33 $site_id=plc_my_site_id();
36 //////////////////// action
37 if ( $_POST['add-slice'] ) {
40 $instantiation= $_POST['instantiation'];
41 $name= $_POST['name'];
42 $description= $_POST['description'];
43 $person_ids = $_POST['person_ids'];
47 $sites=$api->GetSites(array('site_id'=>$site_id));
49 drupal_set_error("Cannot find site_id $site_id");
53 $base=$site['login_base'] . '_';
56 if( $name == $base ) {
57 drupal_set_error("You must enter a name for your slice");
59 } else if (strpos($name,$base) != 0) {
60 drupal_set_error("Slice name $name should begin with $base");
63 // make sure slice name doesnt exist
64 $slices = $api->GetSlices( array( $name ), array( "slice_id" ) );
65 if ( count($slices) != 0) {
66 drupal_set_error("Slice name $name already in use, please choose another");
71 if ( ($url == "http://") || ( $url=="" ) ) {
72 drupal_set_error("You must enter a URL for your slice's info");
76 if( $description == "" ) {
77 drupal_set_error("Your must enter a description for you slice.");
81 // if no errors then add
83 $fields= array( "url" => $url,
84 "instantiation" => $instantiation,
86 "description" => $description );
88 $slice_id= $api->AddSlice( $fields );
91 drupal_set_message ("Slice $slice_id created");
96 foreach ($person_ids as $person_id) {
97 $person_id=intval($person_id);
98 if ($api->AddPersonToSlice($person_id,$slice_id) != 1) {
99 drupal_set_error("Could not add person $person_id in slice :" . $api->error());
106 drupal_set_message ("Added $counter person(s)");
108 drupal_set_error ("Could not add all selected persons, only $counter were added");
110 plc_redirect(l_slice($slice_id) );
112 drupal_set_error("Could not create slice $name " . $api->error() );
118 //////////////////// still here : either it's a blank form or something was wrong
121 require_once 'plc_drupal.php';
122 include 'plc_header.php';
124 $sites=$api->GetSites(array($site_id));
126 $sitename=$site['name'];
127 if ( ! $_POST['name'])
128 $base= $site['login_base'] ."_";
130 // propose to add all 'reachable' persons
131 $site_person_ids=$site['person_ids'];
132 $persons_filter=array("person_id"=>$site_person_ids,
134 $persons=$api->GetPersons($persons_filter,array('email','enabled','first_name','last_name','person_id'));
136 drupal_set_title('Create slice in site "' . $sitename . '"');
139 $url = $_POST['url'];
140 if( !$url ) $url= "http://";
142 // check for errors and set error styles
144 $name_error= " class='plc-warning'";
147 $url_error= " class='plc-warning'";
149 if( $error['description'] )
150 $desc_error= " class='plc-warning'";
153 // is there a need to consider several sites ?
154 $multiple_sites=false;
155 $site_columns=array('name','login_base','site_id');
156 if (plc_is_admin ()) {
157 $multiple_sites=true;
159 } else if (count (plc_my_site_ids()) > 1) {
160 $multiple_sites=true;
161 $filter=plc_my_site_ids();
164 if ($multiple_sites) {
165 print "<div id='add_slice_in_site'>";
166 $other_sites=$api->GetSites($filter,$site_columns);
168 foreach ($other_sites as $other_site) {
169 $selector=array('display'=>$other_site['name'],
170 'value'=>$other_site['site_id']);
171 if ($other_site['site_id']==$other_site_id) $selector['selected']='selected';
172 $selectors []= $selector;
175 $site_form = new PleKitForm (l_slice_add(),array(),'get');
177 print $site_form->label_html('site_id','Or choose some other site');
178 print $site_form->select_html('site_id',$selectors,array('autosubmit'=>true,
179 'id'=>'add_slice_choose_site'));
185 <div class='slice_add'>
186 <p>You must provide a short description of the new slice
187 as well as a link to a project website before creating it.
189 Do <strong>not</strong> provide bogus information; if a complaint
190 is lodged against your slice and your PlanetLab Operations Center
191 is unable to determine what the normal behavior of your slice is,
192 your slice may be deleted to resolve the complaint.
194 <p><strong>NOTE</strong>:
195 All PlanetLab users are <strong>strongly</strong> encouraged to join the PlanetLab
196 <a href='https://lists.planet-lab.org/mailman/listinfo/users'>Users</a>
197 mailing list. Most questions about running software on PlanetLab can be answered by
198 posting to this list.
199 <br/>Site administrators often use this list to post announcements about service outages.
200 New software releases and available services are announced here as well.
205 $details = new PlekitDetails(TRUE);
207 $form_variables = array('site_id'=>plc_my_site_id());
208 $form = $details -> form_start("/db/slices/slice_add.php",$form_variables);
209 print $form->hidden_html("site_id",$site_id);
213 $running=count($site['slice_ids']);
214 $max=$site['max_slices'];
215 $allocated = " $running running / $max max";
216 if ($running >= $max) $allocated = plc_warning_html($allocated);
217 $details->th_td("Allocated slices",$allocated);
218 $details->th_td("Name",$name ? $name : $base, "name");
219 $details->th_td("URL",$url,"url");
220 $details->th_td("Description",$description,"description",
221 array('input_type'=>'textarea',
222 'width'=>50,'height'=>5));
223 $selectors=array(array('display'=>"PLC",'value'=>'plc-instantiated'),
224 array('display'=>"Delegated",'value'=>'delegated'),
225 array('display'=>"Controller",'value'=>'nm-controller'),
226 array('display'=>"None",'value'=>'not-instantiated'));
228 $instanciation_select = $form->select_html ("instantiation", $selectors);
229 $details->th_td("Instanciation",$instanciation_select,"instantiation",
230 array('input_type'=>'select', 'value'=>$instantiation));
236 <div class='slice_add'>
237 <p>There are three possible "instantiation" states for a slice.</p>
239 <li> <strong>PLC</strong> creates a slice with default settings. </li>
240 <li><strong>Delegated</strong> creates a ticket to use on each node. </li>
241 <li><strong>Controller</strong> creates a slice on all nodes to manipulate Delegated slices. </li>
242 <li><strong>None</strong> allows you to reserve a slice name; you may instantiate the slice later.</li>
248 $title = count($persons) . " people can be added in slice";
249 $toggle=new PlekitToggle ('persons',$title,
250 array('visible'=>get_arg('show_persons',true)));
254 $headers['email']='string';
255 $headers['first']='string';
256 $headers['last']='string';
257 $headers['+']='none';
258 $table = new PlekitTable ('persons_in_slice',$headers,0);
260 foreach ($persons as $person) {
262 $table->cell($person['email']);
263 $table->cell($person['first_name']);
264 $table->cell($person['last_name']);
265 $table->cell ($form->checkbox_html('person_ids[]',$person['person_id']));
272 $add_button = $form->submit_html ("add-slice","Create Slice");
273 print ("<div id='slice_add_button'> $add_button </div>");
278 include 'plc_footer.php';