+if ($profiling) plc_debug_prof('12: nodes to add',count($potential_nodes));
+
+//////////////////////////////////////// retrieve all slice tags
+$tags=$api->GetSliceTags (array('slice_id'=>$slice_id));
+//////////////////////////////////////////////////////////// tab:initscripts
+// xxx fixme
+// * add a message on how to use this:
+// * explain the 2 mechanisms (initscript_code, initscript)
+// * explain the interface : initscript start|stop|restart slicename
+// xxx fixme
+
+$initscript_info="
+There are two ways to attach an initscript to a slice:<ul>
+
+<li> <span class='bold'> Shared initscripts </span> are global to the
+MyPLC, and managed by the Operations Team. For that reason, regular
+users cannot change these scripts, but can reference one of the
+available names in the drop down below. </li>
+
+<li> You also have the option to provide <span class='bold'> your own
+code </span>, with the following conventions: <ul>
+
+<li> Like regular initscripts, your script must except to receive as a
+first argument <span class='bold'> start </span>, <span class='bold'>
+stop </span> or <span class='bold'> restart </span>. It is important
+to honor this argument, as your slice may be stopped and restarted at
+any time; also this is used whenever the installed code gets changed.
+</li>
+
+<li> As a second argument, you will receive the slicename; in most
+cases this can be safely ignored. </li>
+
+</ul>
+</li>
+ </ul>
+The slice-specific setting has precedence on a shared initscript.
+";
+
+$shared_initscripts=$api->GetInitScripts(array('-SORT'=>'name'),array('name'));
+//$shared_initscripts=$api->GetInitScripts();
+if ($profiling) plc_debug_prof('13: initscripts',count($initscripts));
+// xxx expose this even on foreign slices for now
+if ($local_peer) {
+ $initscript='';
+ $initscript_code='';
+ if ($tags) foreach ($tags as $tag) {
+ if ($tag['tagname']=='initscript') {
+ if ($initscript!='') drupal_set_error("multiple occurrences of 'initscript' tag");
+ $initscript=$tag['value'];
+ }
+ if ($tag['tagname']=='initscript_code') {
+ if ($initscript_code!='') drupal_set_error("multiple occurrences of 'initscript_code' tag");
+ $initscript_code=$tag['value'];
+ // plc_debug_txt('retrieved body',$initscript_code);
+ }
+ }
+ $label="No initscript";
+ $trimmed=trim($initscript_code);
+ if (!empty($trimmed)) $label="Initscript : slice-specific (" . substr($initscript_code,0,20) . " ...)";
+ else if (!empty($initscript)) $label="Initscript: shared " . $initscript;
+
+ $toggle = new PlekitToggle('slice-initscripts',$label,
+ array('bubble'=>'Manage initscript on that slice',
+ 'visible'=>get_arg('show_initscripts'),
+ 'info-text'=>$initscript_info
+ // not messing with persontags to guess whether this should be displayed or not
+ // hopefully some day toggle will know how to handle that using web storage
+ ));
+ $toggle->start();
+
+ $details=new PlekitDetails(TRUE);
+ // we expose the previous values so that actions.php can know if changes are really needed
+ // the code needs to be encoded as it may contain any character
+ // as far as the code, this does not work too well b/c what actions.php receives
+ // seems to have spurrious \r chars, and the comparison between old and new values
+ // is not reliable, which results in changes being made although the code hasn't changed
+ // hve spent too much time on this, good enough for now...
+ $details->form_start(l_actions(),array('action'=>'update-initscripts',
+ 'slice_id'=>$slice_id,
+ 'name'=>$name,
+ 'previous-initscript'=>$initscript,
+ 'previous-initscript-code'=>htmlentities($initscript_code)));
+ $details->start();
+ // comppute a pulldown with available names
+ $selectors=array();
+ $is_found=FALSE;
+ if ($shared_initscripts) foreach ($shared_initscripts as $is) {
+ $is_selector=array('display'=>$is['name'],'value'=>$is['name']);
+ if ($is['name']==$initscript) {
+ $is_selector['selected']=TRUE;
+ $is_found=TRUE;
+ }
+ $selectors[]=$is_selector;
+ }
+ // display a warning when initscript references an unknown script
+ $details->tr_submit('unused','Update initscripts');
+ ////////// by name
+ $details->th_td("shared initscript name",
+ $details->form()->select_html('initscript',$selectors,array('label'=>'none')),
+ 'initscript',
+ array('input_type'=>'select'));
+ if ($initscript && ! $is_found)
+ // xxx better rendering ?
+ $details->th_td('WARNING',plc_warning_html("Current name '" . $initscript . "' is not a known shared initscript name"));
+ ////////// by contents
+ $script_height=8;
+ $script_width=60;
+ if ($initscript_code) {
+ $text=explode("\n",$initscript_code);
+ $script_height=count($text);
+ $script_width=10;
+ foreach ($text as $line) $script_width=max($script_width,strlen($line));
+ }
+ $details->th_td('slice initscript',$initscript_code,'initscript-code',
+ array('input_type'=>'textarea', 'width'=>$script_width,'height'=>$script_height));
+ $details->tr_submit('unused','Update initscripts');
+ $details->form_end();
+ $details->end();
+ $toggle->end();
+}
+
+//////////////////////////////////////////////////////////// tab:tags