set omf_control is checkbox checked - tweak creation/renewal message
[plewww.git] / planetlab / slices / slice_add.php
index 980654c..704e0fe 100644 (file)
@@ -87,11 +87,16 @@ if ( $_POST['add-slice'] ) {
     // add it!
     $slice_id= $api->AddSlice( $fields );
 
-    if ($slice_id < 0) {
-      drupal_set_error("Could not create slice $name " . $api->error() );
-      $check=false;
-    } else {
+    if ($slice_id > 0) {
       drupal_set_message ("Slice $slice_id created");
+      if (isset($_POST['omf-control'])) {
+       if ($api->SetSliceOmfControl($slice_id,'yes') != 'yes') {
+         drupal_set_error("Could not set the 'omf_control' tag on newly created slice...");
+       } else {
+         drupal_set_message("Successfully set the 'omf_control' tag on slice");
+       }
+      }
+
       if ($person_ids) {
         // Add people
        $success=true;
@@ -111,6 +116,9 @@ if ( $_POST['add-slice'] ) {
          drupal_set_error ("Could not add all selected persons, only $counter were added");
       }
       plc_redirect(l_slice($slice_id) );
+    } else {
+      drupal_set_error("Could not create slice $name " . $api->error() );
+      $check=false;
     }
   }
  }
@@ -129,7 +137,9 @@ if ( ! $_POST['name'])
 
 // propose to add all 'reachable' persons 
 $site_person_ids=$site['person_ids'];
-$persons=$api->GetPersons($site_person_ids,array('email','enabled','first_name','last_name','person_id'));
+$persons_filter=array("person_id"=>$site_person_ids,
+                      "enabled"=>true);
+$persons=$api->GetPersons($persons_filter,array('email','enabled','first_name','last_name','person_id'));
 
 drupal_set_title('Create slice in site "' . $sitename . '"');
 
@@ -148,30 +158,50 @@ if( $error['description'] )
   $desc_error= " class='plc-warning'";
 
 
-// add javaScript code
-print <<< EOF
-<script type='text/javascript'>
-  function update(str1) {
-  var temp= new Array()
-  temp= str1.split('->');
-  var c= ( temp[1] + '_' )
-  document.getElementById('textbox').value = c;
-}
-</script>
-EOF;
+// is there a need to consider several sites ?
+$multiple_sites=false;
+$site_columns=array('name','login_base','site_id');
+if (plc_is_admin ()) {
+  $multiple_sites=true;
+  $filter=array('-SORT'=>'name');
+ } else if (count (plc_my_site_ids()) > 1) {
+  $multiple_sites=true;
+  $filter=array('-SORT'=>'name','site_id'=>plc_my_site_ids());
+ }
+
+if ($multiple_sites) {
+  print "<div id='create-slice-in-site'>";
+  $other_sites=$api->GetSites($filter,$site_columns);
+  $selectors=array();
+  foreach ($other_sites as $other_site) {
+    $selector=array('display'=>$other_site['name'],
+                   'value'=>$other_site['site_id']);
+    if ($other_site['site_id']==$site_id) $selector['selected']='selected';
+    $selectors []= $selector;
+  }
 
+  $site_form = new  PleKitForm (l_slice_add(),array(),array('method'=>'get'));
+  $site_form->start();
+  print $site_form->label_html('site_id','Or choose some other site');
+  print $site_form->select_html('site_id',$selectors,array('autosubmit'=>true,
+                                                          'id'=>'create-slice-choose-site'));
+  $site_form->end();
+  print "</div>";
+ }
+                 
 print <<< EOF
-<div class='slice_add'>
-<p>You must provide a short description of the new slice 
-as well as a link to a project website before creating it. 
-<br/>
-Do <strong>not</strong> provide bogus information; if a complaint 
-is lodged against your slice and your PlanetLab Operations Center
-is unable to determine what the normal behavior of your slice is, 
-your slice may be deleted to resolve the complaint.
-</p>
-<p><strong>NOTE</strong>: 
-All PlanetLab users are <strong>strongly</strong> encouraged to join the PlanetLab 
+<div class='create-slice-instantiations'>
+<p>You <span class='bold'>must</span> provide a short description, 
+as well as a link to a project website, before creating it.
+
+<br/> Please make sure to provide reasonable details on <span class='bold'>
+the kind of traffic</span>, and <span class='bold'>copyrights</span> if relevant. 
+Do <span class='bold'>not</span> provide bogus information; if a complaint is lodged against 
+your slice  and your PlanetLab Operations Center is unable to determine what the normal behavior 
+of your slice is, your slice may be deleted to resolve the complaint.</p>
+
+<p><span class='bold'>NOTE</span>: All PlanetLab users are <span class='bold'>strongly</span>
+ encouraged to join the PlanetLab 
 <a href='https://lists.planet-lab.org/mailman/listinfo/users'>Users</a> 
 mailing list. Most questions about running software on PlanetLab can be answered by 
 posting to this list. 
@@ -181,38 +211,22 @@ New software releases and available services are announced here as well.
 </div>
 EOF;
 
+$toggle = new PlekitToggle ('create-slice-details','Slice Details',
+                           array ('visible'=>get_arg('show_slice',true)));
 $details = new PlekitDetails(TRUE);
 
 $form_variables = array('site_id'=>plc_my_site_id());
 $form = $details -> form_start("/db/slices/slice_add.php",$form_variables);
 print $form->hidden_html("site_id",$site_id);
 
+$toggle->start();
 $details->start();
 
-// is the user on several sites ?
-if (plc_is_admin () || count (plc_my_site_ids()) > 1) {
-  // site selector - not implemented yet
-//// // displays a site select list for admins and multi-site users
-//// if( count( $_person['site_ids'] ) > 1 || in_array( 10, $_roles ) ) {
-////   // get sites depending on role and sites associated.
-////   if( in_array( 10, $_roles ) )
-////     $site_info= $api->GetSites( NULL, array( "name", "site_id", "login_base" ) );
-////   elseif( count( $_person['site_ids'] ) > 1 )
-////     $site_info= $api->GetSites( $_person['site_ids'], array( "name", "site_id", "login_base" ) );
-//// 
-////   echo "<tr><th>Site: </th><td><select onchange='update(this[selectedIndex].text)' name='site_id'>\n";
-//// 
-////   foreach( $site_info as $site ) {
-////     echo "<option value=". $site['site_id'];
-////     if( $site['site_id'] == $_person['site_ids'][0] )
-////       echo " selected";
-////     echo ">". $site['name'] ."->". $site['login_base'] ."</option>\n";
-////   }
-//// 
-////   echo "</select></td><td></td></tr>\n";
-
-}
-
+$running=count($site['slice_ids']);
+$max=$site['max_slices'];
+$allocated = " $running running / $max max";
+if ($running >= $max) $allocated = plc_warning_html($allocated);
+$details->th_td("Allocated slices",$allocated);
 $details->th_td("Name",$name ? $name : $base, "name");
 $details->th_td("URL",$url,"url");
 $details->th_td("Description",$description,"description",
@@ -220,29 +234,46 @@ $details->th_td("Description",$description,"description",
                      'width'=>50,'height'=>5));
 $selectors=array(array('display'=>"PLC",'value'=>'plc-instantiated'),
                 array('display'=>"Delegated",'value'=>'delegated'),
+                array('display'=>"Controller",'value'=>'nm-controller'),
                 array('display'=>"None",'value'=>'not-instantiated'));
 
-$instanciation_select = $form->select_html ("instantiation", $selectors);
-$details->th_td("Instanciation",$instanciation_select,"instantiation",
+$instantiation_select = $form->select_html ("instantiation", $selectors);
+$details->th_td("Instantiation",$instantiation_select,"instantiation",
                array('input_type'=>'select', 'value'=>$instantiation));
 
+// display the current settings if any (like, we've screwed up the first time)
+if (isset($_POST['omf-control'])) {
+  $omf_options=array('checked'=>'checked');
+} else {
+  $omf_options=array();
+}
+$details->th_td("OMF friendly",
+               $form->checkbox_html('omf-control','yes',$omf_options));
 
-$details->end();
-
-print <<< EOF
-<div class='slice_add'>
-<p>There are three possible "instantiation" states for a slice.</p>
+$instantiation_text = <<< EOF
+<div class='create-slice-instantiations'>
+<p>There are four possible "instantiation" states for a slice.</p>
 <ul>
-<li> <strong>PLC</strong> creates a slice with default settings. </li>
-<li><strong>Delegated</strong> creates a ticket to use on each node. </li>
-<li><strong>None</strong> allows you to reserve a slice name; you may instantiate the slice later.</li>
+<li> <span class='bold'>PLC</span> creates a slice with default settings. </li>
+<li><span class='bold'>Delegated</span> creates a ticket to use on each node. </li>
+<li><span class='bold'>Controller</span> creates a slice on all nodes to manipulate Delegated slices. </li>
+<li><span class='bold'>None</span> allows you to reserve a slice name; you may instantiate the slice later.</li>
 </ul>
+<p>PLC instantiated slices can be defined as <span class='bold'>OMF friendly</span>, 
+in which case slivers come with the OMF <span class='bold'>Resource Controller</span> pre-installed and pre-configured. 
+Such slivers can then be easily managed through a centralized tool, the OMF Experiment Controller.
+</p>
 </div>
 EOF;
 
+$details->tr($instantiation_text);
+
+$details->end();
+$toggle->end();
+
 if ($persons) {
   $title = count($persons) . " people can be added in slice";
-  $toggle=new PlekitToggle ('persons',$title,
+  $toggle=new PlekitToggle ('create-slice-persons',$title,
                          array('visible'=>get_arg('show_persons',true)));
   $toggle->start();