From 5f2f81a03fbecad477f4e515a725553c8f578d41 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 4 Jun 2009 08:18:43 +0000 Subject: [PATCH] node page display/update PCU - draft --- planetlab/common/actions.php | 32 +++++++++- planetlab/icons/add.png | Bin 0 -> 4180 bytes planetlab/includes/plc_functions.php | 5 ++ planetlab/nodes/node.php | 86 +++++++++++++++++++++++---- 4 files changed, 110 insertions(+), 13 deletions(-) create mode 100644 planetlab/icons/add.png diff --git a/planetlab/common/actions.php b/planetlab/common/actions.php index c05d0b0..294dec0 100644 --- a/planetlab/common/actions.php +++ b/planetlab/common/actions.php @@ -49,6 +49,8 @@ $known_actions []= "delete-node"; // expects: node_id $known_actions []= "update-node"; // expects: node_id, hostname, model +$known_actions []= "attach-pcu"; +// expects: node_id, pcu_id, port_id (pcu_id <0 means detach) //////////////////////////////////////// interfaces $known_actions []= "delete-interfaces"; @@ -314,11 +316,12 @@ switch ($action) { } case 'update-node': { + $node_id=intval($_POST['node_id']); $hostname= $_POST['hostname']; $model= $_POST['model']; $fields= array( "hostname"=>$hostname, "model"=>$model ); - $api->UpdateNode( intval( $node_id ), $fields ); + $api->UpdateNode( $node_id, $fields ); $error= $api->error(); if( empty( $error ) ) { @@ -330,6 +333,33 @@ switch ($action) { break; } + // this code will ensure that at most one PCU gets attached to the node + case 'attach-pcu': { + $node_id=$_POST['node_id']; + $pcu_id=$_POST['node_id']; + $port=$_POST['port']; + // always start with deleting former PCUs + $former_pcu_ids = $api->GetNodes(array($node_id),array('pcu_ids')); + if ($former_pcu_ids) foreach ($former_pcu_ids as $former_pcu_id) { + if ($api->DeleteNodeFromPCU($node_id,$former_pcu_id) != 1) { + drupal_set_error ('Could not detach from PCU ' . $pcu_id); + } + } + // re-attach only if provided pcu_id >=0 + if ($pcu_id >= 0) { + if ($api->AddNodeToPCU($node_id,$pcu_id,$port) == 1) + drupal_set_message ('Attached node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port); + else + drupal_set_error ('Failed to attach node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port); + } else { + drupal_set_message ('Detached node from all PCUs'); + } + + plc_redirect(l_node($node_id)); + break; + } + + //////////////////////////////////////////////////////////// interfaces case 'delete-interfaces' : { $interface_ids=$_POST['interface_ids']; diff --git a/planetlab/icons/add.png b/planetlab/icons/add.png new file mode 100644 index 0000000000000000000000000000000000000000..3b4570b4d0f1c9831575625e968c34357a002f86 GIT binary patch literal 4180 zcmV-a5UcNrP)EX>4Tx0C?K1S9eg;ThrcO5<-#Q1;o&MZvsjSAV>?ni$FpRNeoR9E(%H!MVcZ- zr3f}e5F03p*Z>6)kuC~0qzOuIdH=wB@AtiTzWL^zdH0Vq&)L~$_t~8@vvUA=aQ-wJ z83h0llqkB>ZZn*Rrx%X7AFzM|Uf>5&|G-F^DS==M|EDeV00IE;R>hx2Bg21YoOBOQ zF91Xt0QiG9u?Yb12W(;&0N{^}qD289AppQ17~)R^K;i*FneO6*2S6?Z0B7(fz6SuD z0h_o5061d;gQEbDJ^(B)g&0Z!V4eiP8WBm6fdHJ!06-*021WpIW&xngA|j|n0Pb!8 zkPoEMqX4+q06^Nq(+jsLnW79}AOL_e{oCi?1W?BWz=QtVCp!+n2LO*g{_Xqa1PA~i zg0CZkv@`(#0AV)+U>asHe#rtb=K!o{GZ?F7490pn0D1_Zi5wVBkNG_>1ZfBO|L&VT z|28xNfC2y-VvItg+R-;LwM;Ltvn+b7r`a~x6F4zkk9pGh2m&I4pM@`q>=i?A%iNCO zJS2)GKS`^|&}D1oCKR?SIw-{`7pXL=j;LcbR5ZP`;)t;Z zi9`uR%f{%$njIh<^oa{S6dj+GaPp7B#EXY-9J!a&oZNP_>sWuvhtw}=Q|SvC$O*2K z5}A6Z2wCLp<2hGzU*=7oVab;~Yf#`^7*>>6oOkZ>`GyOxO5T@Fl`WUATwJV}tNeLs z=JNEFsjJi1rmJSI&sNXfSgcvSiK=70#d(|Wj=){Pd;IlW4XpQ(`wI^y8i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rv%tL{KjLnD1r+B z2m-)LWQ?-~0B{2!+(Dt1*1s{1=x=TV0Ac`$dRz$J9st+@5ZfTSrPC%C@d)$ZLjV9y z0E9xKxH@m-UB73e^M zNU(&@K!@PJqTJv!&>{5SSSk<%{y>KqAVDOA!&jg~gkNY99dQ4aJrJl64P+oeG|<(r zsee~r`zr`-LXaBW?!8oTVN#a0|i6Vl**2 z7&FW+j1fj3a2P?12&iDRF*`7(7-NhfMhBzcF?o0LuR5Fa3HYl|n?E%J2`K-VS>XRr z1DpSM001mEKyd*8z_TOw{_)nLNC%<-0Ps}WL3(I#NEFVLMkAAyan_VTRb`x}y1G96 z3ps#xAiDm1R{#J224YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007 zbV*G`2iXP$2n{p+s>@RV0059lL_t(I%jJ_X3IrhxMgNyMqUq*%mR?OkTQQkpVPSE0 zw6Iw=m4xtk`9!wX3>(T}Q~fhYL?9wl&@mh6y)PL}L1t^$!Mi*1-owmbW>D2v2F`&b zNFv5K8r52drm7Ag0B=w!<IkzWllDF?+F6X@E(;lnp eQ_z#{Z-Xvqt2<9AD7{Yr0000"; } +function plc_add_icon($width=15) { + return ""; +} + function plc_bubble($text,$bubble) { return "$text"; } diff --git a/planetlab/nodes/node.php b/planetlab/nodes/node.php index ebade5e..341e525 100644 --- a/planetlab/nodes/node.php +++ b/planetlab/nodes/node.php @@ -52,7 +52,6 @@ $slice_ids= $node['slice_ids']; $conf_file_ids= $node['conf_file_ids']; $interface_ids= $node['interface_ids']; $nodegroup_ids= $node['nodegroup_ids']; -$pcu_ids= $node['pcu_ids']; // get peers $peer_id = $node['peer_id']; @@ -87,17 +86,13 @@ if( !empty( $interface_ids ) ) if( !empty( $nodegroup_ids ) ) $nodegroups= $api->GetNodeGroups( $nodegroup_ids, array("groupname","tag_type_id","value")); -// xxx Thierry : remaining stuff -// (*) events: should display the latest events relating to that node. -// disabling call to GetEvents, that gets the session deleted in the DB -// (*) conf_files: is fetched but not displayed -if( !empty( $conf_file_ids ) ) - $conf_files= $api->GetConfFiles( $conf_file_ids ); -// (*) idem for PCUs -// gets pcu and port info key to both is $pcu_id -// turning this off: GetPCUs is not allowed to users, and we don't show PCUs yet anyway -//if( !empty( $pcu_ids ) ) -// $PCUs= $api->GetPCUs( $pcu_ids ); +// Thierry : remaining stuff +// (*) events: xxx todo xxx for admins xxx +// should display the latest events relating to that node. +// historically we had to turn this off at some point as GetEvents was getting the session deleted in the DB +// (*) conf_files: xxx todo xxx for admins xxx +//if( !empty( $conf_file_ids ) ) +// $conf_files= $api->GetConfFiles( $conf_file_ids ); //////////////////// display node info @@ -157,6 +152,72 @@ $details->tr_submit("submit","Update Node"); $details->form_end(); if ($privileges) $details->space(); +// PCU stuff - not too sure why, but GetPCUs is not exposed to the 'user' role +$display_pcus = (plc_is_admin() || plc_is_pi() || plc_is_tech()); +if ($display_pcus) { + $pcu_ids= $node['pcu_ids']; + $ports= $node['ports']; + // avoid 2 API calls : get all site PCUs and then search from there + function search_pcu ($site_pcus,$pcu_id) { + if ($site_pcus) foreach ($site_pcus as $site_pcu) if ($site_pcu['pcu_id']==$pcu_id) return $site_pcu; + return FALSE; + } + $site_pcus = $api->GetPCUs(array('site_id'=>$site_id)); + // not sure what the exact semantics is, but I expect pcu_ids and ports should have same cardinality + if (count ($pcu_ids) != count ($ports)) + $pcu_string = "Unexpected condition: " . count($pcu_ids) . " pcu_ids and " . count($ports) . " ports"; + else if (count($pcu_ids) == 0) + $pcu_string = plc_warning_html("No PCU !"); + else if (count($pcu_ids) == 1) { + $pcu_id=$pcu_ids[0]; + $port=$ports[0]; + $pcu_columns = array('hostname'); + $pcu=search_pcu($site_pcus,$pcu_id); + if ( ! $pcu ) + $pcu_string = "Cannot find PCU " . $pcu_id; + else + $pcu_string = $pcu['hostname'] . " on port " . $port; + } else + $pcu_string = plc_warning_html("More than one PCU attached ? "); + + + $details->form_start(l_actions(),array("action"=>"attach-pcu","node_id"=>$node_id)); + // prepare selectors + if (! $site_pcus) { + $pcu_update_area = "This site has no PCU - " . href ( l_pcu_add(), "add one here"); + } else { + $pcu_add_link = href (l_pcu_add(),plc_add_icon()); + + $pcu_selectors = array(array('display'=>'None','value'=>-1)); + foreach ($site_pcus as $site_pcu) { + $selector=array('display'=>$site_pcu['hostname'],'value'=>$site_pcu['pcu_id']); + if ($pcu_id == $site_pcu['pcu_id']) $selector['selected']=true; + $pcu_selectors []= $selector; + } + $pcu_chooser = $details->form()->select_html('pcu_id',$pcu_selectors); + + function port_selector ($i,$port) { + $selector = array ('display'=>'port ' . $i, 'value'=>$i); + if ($i == $port) $selector['selected'] = true; + return $selector; + } + $port_selectors = array () ; + $available_ports =range(1,8); + foreach ($available_ports as $available_port) + $port_selectors []= port_selector ($available_port,$port); + $port_chooser = $details->form()->select_html('port',$port_selectors); + + $pcu_attach_button = + $details->form()->submit_html('attach_pcu',"Attach PCU"); + + $pcu_update_area = $pcu_add_link . " " . $pcu_chooser . " " . $port_chooser . " " . $pcu_attach_button; + } + + $details->th_td("PCU",plc_vertical_table(array($pcu_string,$pcu_update_area))); + $details->form_end(); + $details->space(); + } + $details->th_td("Type",$node_type); $details->th_td("Version",$version); // let's use plc_objects @@ -208,6 +269,7 @@ if ( $local_peer && $privileges) { array('label'=>"Download mode",'autosubmit'=>true)); $download_value .= $download_form->end_html(); $details->th_td ("Download",$download_value); + } // site info and all site nodes -- 2.43.0