X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetlab%2Fnodes%2Fnode.php;h=4d8ccb5988da5e7709cc8794d66627d6f3b25e69;hb=f20e546535306a5fe875d2b8c5585cec0e22db46;hp=2ed71dc5a437deaa93b7bcb65d99be5684434d12;hpb=799fd3ac9ad3f9b61cc5b3bb7f5341e0c649beb7;p=plewww.git diff --git a/planetlab/nodes/node.php b/planetlab/nodes/node.php index 2ed71dc..4d8ccb5 100644 --- a/planetlab/nodes/node.php +++ b/planetlab/nodes/node.php @@ -1,7 +1,5 @@ person; -$_roles= $_person['role_ids']; +require_once 'plc_peers.php'; +require_once 'linetabs.php'; +require_once 'table.php'; +require_once 'details.php'; +require_once 'form.php'; +require_once 'toggle.php'; +require_once 'plc_objects.php'; // -------------------- // recognized URL arguments @@ -35,278 +32,507 @@ $nodes= $api->GetNodes( array($node_id)); if (empty($nodes)) { drupal_set_message ("Node " . $node_id . " not found"); - } else { - $node=$nodes[0]; - // node info - $hostname= $node['hostname']; - $boot_state= $node['boot_state']; - $site_id= $node['site_id']; - $model= $node['model']; - $version= $node['version']; - $node_type = $node['node_type']; - - // arrays of ids of node info - $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 peer - $peer_id= $node['peer_id']; - - // gets site info - $sites= $api->GetSites( array( $site_id ) ); - $site=$sites[0]; - $site_name= $site['name']; - $site_node_ids= $site['node_ids']; - - $site_node_hash=array(); - if( !empty( $site_node_ids ) ) { - // get site node info basics - $site_nodes= $api->GetNodes( $site_node_ids ); + return; + } + +$node=$nodes[0]; +// node info +$hostname= $node['hostname']; +$boot_state= $node['boot_state']; +$run_level = $node['run_level']; +$site_id= $node['site_id']; +$model= $node['model']; +$version= $node['version']; +$node_type = $node['node_type']; + +// arrays of ids of node info +$slice_ids= $node['slice_ids']; +$conf_file_ids= $node['conf_file_ids']; +$interface_ids= $node['interface_ids']; +$nodegroup_ids= $node['nodegroup_ids']; + +// get peers +$peer_id = $node['peer_id']; +$peers=new Peers ($api); + +// gets site info +$sites= $api->GetSites( array( $site_id ) ); +$site=$sites[0]; +$site_name= $site['name']; +$site_node_ids= $site['node_ids']; + +// hash node_id=>hostname for this site's nodes +$site_node_hash=array(); +if( !empty( $site_node_ids ) ) { + // get site node info basics + $site_nodes= $api->GetNodes( $site_node_ids ); - foreach( $site_nodes as $site_node ) { - $site_node_hash[$site_node['node_id']]= $site_node['hostname']; - } + foreach( $site_nodes as $site_node ) { + $site_node_hash[$site_node['node_id']]= $site_node['hostname']; } + } - // gets slice info for each slice - if( !empty( $slice_ids ) ) - $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" , "peer_id" ) ); +// gets slice info for each slice +if( !empty( $slice_ids ) ) + $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" , "peer_id" ) ); - // gets conf file info - if( !empty( $conf_file_ids ) ) - $conf_files= $api->GetConfFiles( $conf_file_ids ); +// get interface info +if( !empty( $interface_ids ) ) + $interfaces= $api->GetInterfaces( $interface_ids ); - // get interface info - if( !empty( $interface_ids ) ) - $interfaces= $api->GetInterfaces( $interface_ids ); +// gets nodegroup info +if( !empty( $nodegroup_ids ) ) + $nodegroups= $api->GetNodeGroups( $nodegroup_ids, array("groupname","tag_type_id","value")); - // gets nodegroup info - if( !empty( $nodegroup_ids ) ) - $nodegroups= $api->GetNodeGroups( $nodegroup_ids, array("groupname","tag_type_id","value")); +// 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 ); - // xxx Thierry : disabling call to GetEvents, that gets the session deleted in the DB - // needs being reworked +//////////////////// display node info - // gets pcu and port info key to both is $pcu_id - if( !empty( $pcu_ids ) ) - $PCUs= $api->GetPCUs( $pcu_ids ); +drupal_set_title("Details for node " . $hostname); +$local_peer= ! $peer_id; - - // display node info - plc_peer_block_start ($peer_hash,$peer_id); - - drupal_set_title("Details for node " . $hostname); - // extra privileges to admins, and (pi||tech) on this site - $extra_privileges = plc_is_admin () || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech())); +// extra privileges to admins, and (pi||tech) on this site +$privileges = (plc_is_admin () && $local_peer) || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech())); - $tabs=array(); - // available actions - if ( ! $peer_id && $extra_privileges ) { +$tabs=array(); +// available actions +$tabs [] = tab_nodes_site($site_id); +$tabs [] = tab_site($site_id); +//$tabs [] = tab_nodes(); + +if ( $local_peer && $privileges ) { - $tabs['Update'] = array ('url'=>"/db/nodes/node_actions.php", - 'method'=>'POST', - 'values'=>array('action'=>'prompt-update','node_id'=>$node_id)); - $tabs['Delete'] = array ('url'=>"/db/nodes/node_actions.php", - 'method'=>'POST', - 'values'=>array('action'=>'delete','node_id'=>$node_id), - 'confirm'=>'Are you sure to delete ' . $hostname. ' ?'); - // xxx subject to roles - $tabs["Add Interface"]=l_interface_add_u($node_id); - $tabs["Comon"]=l_comon("node_id",$node_id); - $tabs["Events"]=l_event("Node","node",$node_id); - - $tabs["All nodes"]=l_nodes(); - - plc_tabs($tabs); - - } + $tabs["Add Interface"]=array('url'=>l_interface_add($node_id), + 'bubble'=>"Define new network interface on $hostname"); + $tabs['Delete'] = array ('url'=>l_actions(), + 'method'=>'POST', + 'values'=>array('action'=>'delete-node','node_id'=>$node_id), + 'bubble'=>"Delete node $hostname", + 'confirm'=>'Are you sure to delete ' . $hostname); + $tabs["Events"]=array_merge(tablook_event(), + array('url'=>l_event("Node","node",$node_id), + 'bubble'=>"Events for node $hostname")); + $tabs["Comon"]=array_merge(tablook_comon(), + array('url'=>l_comon("node_id",$node_id), + 'bubble'=>"Comon page about node $hostname")); + } + +plekit_linetabs($tabs); + +// show gray background on foreign objects : start a
Hostname: | $hostname |
---|---|
Type: | $node_type |
Model: | $model |
Version: | $version |
Boot State: | "; - if ($peer_id) { - echo $boot_state; + $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 { - echo ""; - } - echo " |
Download | "; - echo ""; - echo " |
Site: | $site_name |
All site nodes: | ";
- if (empty($site_node_hash)) {
- echo "Site has no node";
- } else {
- foreach( $site_node_hash as $key => $val ) {
- echo "$val "; + 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 . " Or, select existing " . $pcu_chooser . " " . $port_chooser . " " . $pcu_attach_button; } - echo " |
No interface. Please add an interface to make this a usable PLC node
.\n"; + $details->th_td("PCU",$pcu_value_area); + $details->form_end(); + } + +//////////////////// Reboot Node +if ( $display_reboot_button ) +{ + if ( ! empty($_SESSION['messages']) ) { + $msg = $_SESSION['messages']['status'][0]; } else { - $columns=array(); - if ( $extra_privileges ) { - // a single symbol, marking 'p' for primary and a delete button for non-primary - $columns[' ']='string'; - } - - $columns["IP"]="IPAddress"; - $columns["Method"]="string"; - $columns["Type"]="string"; - $columns["MAC"]="string"; - $columns["bw limit"]="FileSize"; - - print "This node is not associated to any slice.
\n"; + plc_warning ("This node is not associated to any slice"); } else { - $columns=array(); - $columns['Peer']="string"; - $columns['Name']="string"; - $columns['Slivers']="string"; - plc_table_start ("slivers",$columns,1); + $headers=array(); + $headers['Peer']="string"; + $headers['Slice Name']="string"; + $headers['Sliver']="string"; + $reasonable_page=10; + $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page); + if (count ($slices) <= $reasonable_page) { + $table_options['search_area']=false; + $table_options['pagesize_area']=false; + } + $table=new PlekitTable("node_slices",$headers,1,$table_options); + $table->start(); foreach ($slices as $slice) { - plc_table_row_start($slice['name']); - plc_table_cell (plc_peer_shortname($peer_hash,$slice['peer_id'])); - plc_table_cell (l_slice2 ($slice['slice_id'],$slice['name'])); - plc_table_cell (l_sliver3 ($node_id,$slice['slice_id'],'view')); - plc_table_row_end(); + $table->row_start(); + $peers->cell ($table,$slice['peer_id']); + $table->cell (l_slice_t ($slice['slice_id'],$slice['name'])); + $table->cell (l_sliver_t ($node_id,$slice['slice_id'],'sliver tags')); + $table->row_end(); } - plc_table_end(); + $table->end(); } + $toggle->end(); +} - //////////////////////////////////////////////////////////// nodegroups - // display node group info - if ( ! $nodegroups ) { - echo "This node is not in any nodegroup.
\n"; - } else { - $columns=array(); - $columns['Name']="string"; - $columns['Tag']="string"; - $columns['Value']="string"; - - print "'; + plc_warning_html("This node has no interface"); + echo "Please add an interface to make this a usable PLC node.
\n"; + } // else { // show this unconditionnally as otherwise there's no mean to create one.. + + // display a hostname column iff at least one interface has a hostname + $need_hostname=false; + if ($interfaces) foreach ($interfaces as $interface) if ($interface['hostname']) $need_hostname=true; + + $headers=array(); + + $sort_column=0; + if (plc_is_admin()) { $headers['I']='int'; $sort_column +=1;} + $headers["IP"]="sortIPAddress"; + if ($need_hostname) $headers['hostname']='string'; + $headers["Method"]="string"; + $headers["Type"]="string"; + $headers["MAC"]="string"; + $headers["bw limit"]="sortBandwidth"; + $headers["tags"]=array('type'=>'int', + 'title'=>"number of tags set on interface"); + // a single symbol, marking 'p' for primary and a delete button for non-primary + if ( $privileges ) $headers[plc_delete_icon()]='string'; + + $table_options=array('search_area'=>false,"pagesize_area"=>false,'notes_area'=>false); + $table=new PlekitTable("node_interfaces",$headers,$sort_column,$table_options); + $table->start(); + + if ($interfaces) foreach ( $interfaces as $interface ) { + $interface_id= $interface['interface_id']; + $interface_ip= $interface['ip']; + + $table->row_start(); + if (plc_is_admin()) $table->cell(l_interface_t($interface_id,$interface_id)); + $table->cell(l_interface_t($interface_id,$interface_ip)); + if ($need_hostname) $table->cell($interface['hostname']); + $table->cell($interface['method']); + $table->cell($interface['type']); + $table->cell($interface['mac']); + $table->cell(pretty_bandwidth($interface['bwlimit'])); + $table->cell(href(l_interface_tags($interface_id), + count($interface['interface_tag_ids']))); + if ( $privileges ) { + if ($interface['is_primary']) { + $table->cell(plc_bubble("p","Cannot delete a primary interface")); + } else { + $table->cell ($form->checkbox_html('interface_ids[]',$interface_id)); + } + } + $table->row_end(); + } + if ($privileges) { + $table->tfoot_start(); + $table->row_start(); + // we should have 6 cols, use 3 for the left (new) and the rest for the right (remove) + //$add_button=new PlekitFormButton (l_interface_add($node_id),"add","Add Interface","GET"); + //$table->cell($add_button->html(),array('columns'=> 3,'align'=>'left')); + $table->cell($form->submit_html("new-interface","Add Interface"), + array('columns'=> 3,'align'=>'left')); + $table->cell($form->submit_html("delete-interfaces","Remove Interfaces"), + array('columns'=>$table->columns()-3,'align'=>'right')); + $table->row_end(); + } + $table->end(); + // } + $toggle->end(); + } + +$form->end(); + +//////////////////////////////////////////////////////////// +$peers->block_end($peer_id); + +//plekit_linetabs ($tabs,"bottom"); + // Print footer include 'plc_footer.php';