+//////////////////// the options for an nodetype - suitable for plekit/form
+global $builtin_node_types;
+$builtin_node_types = array ( "regular" => "Regular/Shared",
+ "reservable" => "Reservable (requires to get leases)");
+function node_type_display ($api, $node_type) {
+ global $builtin_node_types;
+ $val=$builtin_node_types[$node_type];
+ if ( ! $val) $val="??undefined??";
+ return $val;
+}
+
+function node_type_selectors ($api,$node_type) {
+ global $builtin_node_types;
+ foreach ($builtin_node_types as $value=>$display) {
+ $selector=array('display'=>$display, 'value'=>$value);
+ if ($value == $node_type) $selector['selected']=true;
+ $selectors []= $selector;
+ }
+ return $selectors;
+}
+
+//////////////////// the options for an interface - suitable for plekit/form
+//>>> GetNetworkMethods()
+//[u'static', u'dhcp', u'proxy', u'tap', u'ipmi', u'unknown']
+function interface_method_selectors ($api, $method, $primary) {
+ if ($primary) {
+ $builtin_methods=array("static"=>"Static",
+ "dhcp"=>"DHCP");
+ } else {
+ $builtin_methods=array("static"=>"Static",
+ "dhcp"=>"DHCP",
+ "proxy"=>"Proxy",
+ "tap"=>"TUN/TAP",
+ "ipmi"=>"IPMI");
+ }
+ $selectors=array();
+ foreach ($builtin_methods as $value=>$display) {
+ $selector=array('display'=>$display, 'value'=>$value);
+ if ($value == $method) $selector['selected']=true;
+ $selectors []= $selector;
+ }
+ return $selectors;
+}
+
+// displays bandwidth with kbps Mbps Gbps as needed
+function pretty_bandwidth ($bw) {
+ if ($bw < 1000) return $bw;
+ if ($bw < 1000000) return strval($bw/1000) . " kbps";
+ if ($bw < 1000000000) return strval($bw/1000000) . " Mbps";
+ else return strval($bw/1000000000) . " Gbps";
+}
+
+////////////////////
+function instantiation_label ($slice) {
+ $instantiation_labels = array ('not-instantiated'=>'NOT',
+ 'plc-instantiated'=>'PLC',
+ 'delegated' => 'DEL',
+ 'nm-controller' => 'NM');
+ $result=$instantiation_labels[$slice['instantiation']];
+ if (!$result) $result = $slice['instantiation'];
+ if (!$result) $result = '??';
+ return $result;
+}
+
+//////////////////// toggle areas
+// get_arg ('show_persons',false) returns $_GET['show_persons'] if set and false otherwise
+function get_arg ($name,$default,$method='get') {
+ if ($method == 'get') $var=$_GET; else $var=$_POST;
+ if (isset ($var[$name])) return $var[$name];
+ else return $default;
+}
+
+//////////////////// number of ...
+function count_english ($objs,$name) {
+ $count=count($objs);
+ if ($count == 0) return 'No ' . $name;
+ else if ($count == 1) return 'One ' . $name;
+ else return $count . ' ' . $name . 's';
+}
+function count_english_warning ($objs, $name) {
+ $x=count_english ($objs,$name);
+ if (count ($objs) == 0) $x=plc_warning_html($x . ' !!');
+ return $x;
+}
+
+//////////////////// outlining reservable nodes
+function reservable_mark () { return "-R-";}
+function reservable_legend () { return "reservable nodes are marked with " . reservable_mark (); }
+
+