X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetlab%2Fnodes%2Fnode.php;h=f45712120636b1a05be6b156b7bc68a90d269ffe;hb=15c340da9dcec704b94592a1a7cb27feb2787279;hp=096428d69c42b2273b03863fa02c6a838a50fb30;hpb=7772d4ba04b97c8a32f3b9baf680ce4a76da1e25;p=plewww.git diff --git a/planetlab/nodes/node.php b/planetlab/nodes/node.php index 096428d..f457121 100644 --- a/planetlab/nodes/node.php +++ b/planetlab/nodes/node.php @@ -1,7 +1,5 @@ GetNodes( array($node_id)); +// Need to mention columns explicitly as we want hrn which is a tag +$columns=array ('hostname','boot_state','run_level','site_id','model','node_type','version', + 'slice_ids','conf_file_ids','interface_ids','nodegroup_ids','peer_id', + 'pcu_ids','ports','hrn'); +$nodes= $api->GetNodes( array($node_id),$columns); 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']; - - // 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 ); + return; + } + +$node=$nodes[0]; +// node info +$hostname= $node['hostname']; +$hrn=$node['hrn']; +$boot_state= $node['boot_state']; +$run_level = $node['run_level']; +$site_id= $node['site_id']; +$model= $node['model']; +$node_type= $node['node_type']; +$version= $node['version']; + +// 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" ) ); - - // 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")); - - // 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 - if( !empty( $pcu_ids ) ) - $PCUs= $api->GetPCUs( $pcu_ids ); - - //////////////////// display node info - - // fetches peers and initialize hash peer_id->peer - $peer_hash = plc_peer_global_hash ($api); - // show gray background on foreign objects : start a
This node is not associated to any slice.
\n"; + plc_warning ("This node is not associated to any slice"); } else { $headers=array(); $headers['Peer']="string"; - $headers['Name']="string"; - $headers['Slivers']="string"; - $table_options = array('notes_area'=>false); - plc_table_start ("slivers",$headers,1,$table_options); + $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_slice_t ($slice['slice_id'],$slice['name'])); - plc_table_cell (l_sliver_t ($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("slivers"); + $table->end(); } + $toggle->end(); +} - //////////////////////////////////////////////////////////// interfaces - if ( ! $peer_id ) { +//////////////////////////////////////////////////////////// Tags +// tags section +if ( $local_peer ) { + + $tags=$api->GetNodeTags (array('node_id'=>$node_id)); + function get_tagname ($tag) { return $tag['tagname'];} + // xxx looks like tech-only see an error here, + // might be that GetNodeTags is not accessible or something + $tagnames = array_map ("get_tagname",$tags); + $nodegroups_hash=plc_nodegroup_global_hash($api,$tagnames); + + $toggle = new PlekitToggle ('tags',count_english($tags,'tag'), + array('bubble'=>'Inspect and set tags on that node', + 'visible'=>get_arg('show_tags'))); + $toggle->start(); + + $headers=array("Name"=>"string", + "Value"=>"string", + "Nodegroup"=>"string", + ); + if (plc_is_admin()) $headers[plc_delete_icon()]="none"; + + $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10); + $table=new PlekitTable("node_tags",$headers,0,$table_options); + $table->start(); + if ($tags) foreach ($tags as $tag) { + // does this match a nodegroup ? + $nodegroup_name="n/a"; + $nodegroup_key=$tag['tagname'] . "=" . $tag['value']; + $nodegroup=$nodegroups_hash[$nodegroup_key]; + if ($nodegroup) $nodegroup_name=l_nodegroup_t($nodegroup['nodegroup_id'],$nodegroup['groupname']); + $table->row_start(); + $table->cell(l_tag_obj($tag)); + $table->cell($tag['value']); + $table->cell($nodegroup_name); + // the remove checkbox + if (plc_is_admin()) $table->cell ($form->checkbox_html('node_tag_ids[]',$tag['node_tag_id'])); + $table->row_end(); + } + + if ($privileges) { + $table->tfoot_start(); + + // remove tag + $table->row_start(); + $table->cell($form->submit_html("delete-node-tags","Remove Tags"), + // use the whole columns and right adjust + array('hfill'=>true,'align'=>'right')); + $table->row_end(); + + // set tag area + $table->row_start(); + // get list of tag names in the node/* category + $all_tags= $api->GetTagTypes( array ("category"=>"node*","-SORT"=>"tagname"), array("tagname","tag_type_id")); + // xxx cannot use onchange=submit() - would need to somehow pass action name + function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); } + $selector=array_map("tag_selector",$all_tags); + $table->cell($form->select_html("tag_type_id",$selector,array('label'=>"Choose"))); + $table->cell($form->text_html("value","",array('width'=>8))); + $table->cell($form->submit_html("set-tag-on-node","Set Tag"),array('columns'=>2,'align'=>'left')); + $table->row_end(); + } + + $table->end(); + $toggle->end(); +} - // display interfaces - if( ! $interfaces ) { - echo "No interface. Please add an interface to make this a usable PLC node
.\n"; - } else { - $headers=array(); - if ( $privileges ) { - // a single symbol, marking 'p' for primary and a delete button for non-primary - $headers[' ']='string'; - } - - $headers["IP"]="IPAddress"; - $headers["Method"]="string"; - $headers["Type"]="string"; - $headers["MAC"]="string"; - $headers["bw limit"]="FileSize"; - - 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(); - foreach ( $interfaces as $interface ) { - $interface_id= $interface['interface_id']; - $interface_ip= $interface['ip']; - $interface_broad= $interface['broadcast']; - $interface_primary= $interface['is_primary']; - $interface_network= $interface['network']; - $interface_dns1= $interface['dns1']; - $interface_dns2= $interface['dns2']; - $interface_hostname= $interface['hostname']; - $interface_netmaks= $interface['netmask']; - $interface_gatewary= $interface['gateway']; - $interface_mac= $interface['mac']; - $interface_bwlimit= $interface['bwlimit']; - $interface_type= $interface['type']; - $interface_method= $interface['method']; - - plc_table_row_start($interface['ip']); - if ( $privileges ) { - if (!$interface_primary) { - // xxx - plc_table_cell (plc_delete_link_button ('interfaces.php?id=' . $interface_id . '&delete=1&submitted=1', - '\\nInterface ' . $interface_ip)); - } else { - plc_table_cell('p'); - } + 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)); } - plc_table_cell(l_interface_t($interface_id,$interface_ip)); - plc_table_cell($interface_method); - plc_table_cell($interface_type); - plc_table_cell($interface_mac); - plc_table_cell($interface_bwlimit); - plc_table_row_end(); } - plc_table_end("interfaces"); + $table->row_end(); } - - } - - //////////////////////////////////////////////////////////// nodegroups - // display node group info - if ( ! $nodegroups ) { - echo "This node is not in any nodegroup.
\n"; - } else { - $headers=array(); - $headers['Name']="string"; - $headers['Tag']="string"; - $headers['Value']="string"; - - print "