X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetlab%2Fslices%2Fslice_add.php;h=59c0efc5c6f73af06f7b4bd6da8145110d1e639f;hb=1ce86fd37ce8da9b475847a59394c0241a8dbbff;hp=5baa8ba1b7002dd7e4361d653593d3108a71f280;hpb=8f165fbbfab8f33f5b92fbf015fabf9afc80c872;p=plewww.git diff --git a/planetlab/slices/slice_add.php b/planetlab/slices/slice_add.php index 5baa8ba..59c0efc 100644 --- a/planetlab/slices/slice_add.php +++ b/planetlab/slices/slice_add.php @@ -9,77 +9,148 @@ global $plc, $api; // Common functions require_once 'plc_functions.php'; +require_once 'details.php'; +require_once 'table.php'; +require_once 'toggle.php'; -// find person roles -$_person= $plc->person; -$_roles= $_person['role_ids']; - -//print_r( $_person ); +//plc_debug('POST',$_POST); // if not a PI or admin then redirect to slice index -if( !in_array( '10', $_roles ) && !in_array( '20', $_roles ) ) +$has_privileges = plc_is_admin() || plc_is_pi(); +if ( ! $has_privileges ) { + drupal_set_error("Insufficient privilege to add a slice"); header( "index.php" ); - -if( !$_POST['name'] ) { - // get default site base - $site_info= $api->GetSites( array( $_person['site_ids'][0] ), array( "login_base" ) ); - $base= $site_info[0]['login_base'] ."_"; + return 0; } -// add it -if( $_POST['add'] ) { +// find out which site the slice should be added to +// without site_id set in GET, we use the first site that this user is in +if (isset($_GET['site_id'])) { + $site_id=intval($_GET['site_id']); + } else if (isset ($_POST['site_id'])) { + $site_id=intval($_POST['site_id']); + } else { + $site_id=plc_my_site_id(); + } + +//////////////////// action +if ( $_POST['add-slice'] ) { // get post vars $url= $_POST['url']; $instantiation= $_POST['instantiation']; $name= $_POST['name']; $description= $_POST['description']; + $person_ids = $_POST['person_ids']; + + $check=true; + + $sites=$api->GetSites(array('site_id'=>$site_id)); + if ( ! $sites) { + drupal_set_error("Cannot find site_id $site_id"); + $check=false; + } + $site=$sites[0]; + $base=$site['login_base'] . '_'; // validate input - if( $name == $base ) - $error['name']= "You must enter a name for your slice."; - else { - $slice_name= $name; + if( $name == $base ) { + drupal_set_error("You must enter a name for your slice"); + $check=false; + } else if (strpos($name,$base) != 0) { + drupal_set_error("Slice name $name should begin with $base"); + $check=false; + } else { // make sure slice name doesnt exist - $slice_info= $api->GetSlices( array( $slice_name ), array( "slice_id" ) ); - - if( !empty( $slice_info ) ) { - $error['name']= "Slice name already in use. Please choose another."; - $name= ""; + $slices = $api->GetSlices( array( $name ), array( "slice_id" ) ); + if ( count($slices) != 0) { + drupal_set_error("Slice name $name already in use, please choose another"); + $check=false; } - } - if( $url == "http://" || "" ) - $error['url']= "You must enter a URL for your slice's info."; + if ( ($url == "http://") || ( $url=="" ) ) { + drupal_set_error("You must enter a URL for your slice's info"); + $check=false; + } - if( $description == "" ) - $error['description']= "Your must enter a description for you slice."; + if( $description == "" ) { + drupal_set_error("Your must enter a description for you slice."); + $check=false; + } // if no errors then add - if( !$error ) { - $fields= array( "url" => $url, "instantiation" => $instantiation, "name" => $slice_name, "description" => $description ); - echo "added:
"; print_r( $fields ); echo "
\n"; + if ( $check ) { + $fields= array( "url" => $url, + "instantiation" => $instantiation, + "name" => $name, + "description" => $description ); // add it! - $slice_new_id= $api->AddSlice( $fields ); + $slice_id= $api->AddSlice( $fields ); + + 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 ($api->SetSliceVref($slice_id,'omf') != 'omf') { + drupal_set_error("Could not set the 'vref' tag on newly created slice..."); + } else { + drupal_set_message("Successfully set the 'vref' tag on slice"); + } + } - if( $slice_new_id ) { - plc_redirect( "index.php?id=$slice_new_id" ); - exit(); + if ($person_ids) { + // Add people + $success=true; + $counter=0; + foreach ($person_ids as $person_id) { + $person_id=intval($person_id); + if ($api->AddPersonToSlice($person_id,$slice_id) != 1) { + drupal_set_error("Could not add person $person_id in slice :" . $api->error()); + $success=false; + } else { + $counter++; + } + } + if ($success) + drupal_set_message ("Added $counter person(s)"); + else + drupal_set_error ("Could not add all selected persons, only $counter were added"); + } + plc_redirect(l_slice($slice_id) ); } else { - $error['api']= $api->error(); + drupal_set_error("Could not create slice $name " . $api->error() ); + $check=false; } } + } -} +//////////////////// still here : either it's a blank form or something was wrong // Print header require_once 'plc_drupal.php'; -drupal_set_title('Slices'); include 'plc_header.php'; +$sites=$api->GetSites(array($site_id)); +$site=$sites[0]; +$sitename=$site['name']; +if ( ! $_POST['name']) + $base= $site['login_base'] ."_"; + +// propose to add all 'reachable' persons +$site_person_ids=$site['person_ids']; +$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 . '"'); -if( !$url ) - $url= "http://"; +// defaults +$url = $_POST['url']; +if( !$url ) $url= "http://"; // check for errors and set error styles if( $error['name'] ) @@ -92,75 +163,150 @@ if( $error['description'] ) $desc_error= " class='plc-warning'"; -// add javaScript code -echo "\n"; - - -// start form -echo "
\n"; - -if( $error['api'] ) - echo "". $error['api'] ."\n"; - -echo "

Create Slice

\n"; - -echo "

You must provide a short description of the new slice as well as a link to a project website before creating it. Do not provide bogus information; if a complaint is lodged against your slice and PlanetLab Operations is unable to determine what the normal behavior of your slice is, your slice may be deleted to resolve the complaint.\n"; -echo "

There are three possible \"instantiation\" states for a slice. PLC creates a slice with default settings. Delegated creates a ticket to use on each node. None allows you to reserve a slice name; you may instantiate the slice later.\n"; -echo "

NOTE: All PlanetLab users are strongly encouraged to join the PlanetLab Users mailing list. Most questions about running software on PlanetLab can be answered by posting to this list. Site administrators often use this list to post announcements about service outages. New software releases and available services are announced here as well.\n"; - -echo "

\n"; - -// 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 "\n"; - + $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 ""; + } + +print <<< EOF +
+

Important: Please provide a short description, as well as a +link to a project website, before creating your slice.

+

+PlanetLab's security model requires that anyone who is concerned about a slice's activity be able to immediately learn about that slice. The details that you provide are your public explanation about why the slice behaves as it does. Be sure to describe the kind of traffic that your slice generates, and how it handles material that is under copyright, if relevant. +

+The PlanetLab Operations Centres regularly respond to concerns raised by third parties about site behaviour. Most incidents are resolved rapidly based upon the publicly posted slice details. However, when these details are not sufficiently clear or accurate, and we cannot immediately reach the slice owner, we must delete the slice. +

+

NOTE: All PlanetLab users are strongly + encouraged to join the PlanetLab +Users +mailing list. Most questions about running software on PlanetLab can be answered by +posting to this list. +
Site administrators often use this list to post announcements about service outages. +New software releases and available services are announced here as well. +

+
+EOF; + +$toggle = new PlekitToggle ('create-slice-details','Slice Details', + array ('visible'=>get_arg('show_slice'))); +$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(); + +$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", + array('input_type'=>'textarea', + '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')); + +$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)); + +$instantiation_text = <<< EOF +
+

There are four possible "instantiation" states for a slice.

+
    +
  • PLC creates a slice with default settings.
  • +
  • Delegated creates a ticket to use on each node.
  • +
  • Controller creates a slice on all nodes to manipulate Delegated slices.
  • +
  • None allows you to reserve a slice name; you may instantiate the slice later.
  • +
+

PLC instantiated slices can be defined as OMF friendly, +in which case slivers come with the OMF Resource Controller pre-installed and pre-configured. +Such slivers can then be easily managed through a centralized tool, the OMF Experiment Controller. +Using these OMF tools, a user can describe, instrument, +and automatically execute their experiments across many slivers. +Please refer to the OMF User Guide +to learn more on how to use this feature. +

+
+EOF; + +$details->tr($instantiation_text); + +$details->end(); +$toggle->end(); + +if ($persons) { + $title = count($persons) . " people can be added in slice"; + $toggle=new PlekitToggle ('create-slice-persons',$title, + array('visible'=>get_arg('show_persons'))); + $toggle->start(); + + $headers = array(); + $headers['email']='string'; + $headers['first']='string'; + $headers['last']='string'; + $headers['+']='none'; + $table = new PlekitTable ('persons_in_slice',$headers,0); + $table->start(); + foreach ($persons as $person) { + $table->row_start(); + $table->cell($person['email']); + $table->cell($person['first_name']); + $table->cell($person['last_name']); + $table->cell ($form->checkbox_html('person_ids[]',$person['person_id'])); + $table->row_end(); + } + $table->end(); + $toggle->end(); + } -echo "Name: \n"; -echo "URL: \n"; -echo "Description: \n"; -echo "\n"; - -echo "
Site:
". $error['name'] ."
". $error['url'] ."
". $error['description'] ."
Instantiation:
\n"; - -echo "

\n"; - -echo "

\n"; - - +$add_button = $form->submit_html ("add-slice","Create Slice"); +print ("
$add_button
"); +$form->end(); // Print footer include 'plc_footer.php';