X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetlab%2Fnodes%2Findex.php;h=3a5cb1cff34f078377230b9346dd5adf783eccfc;hb=b7593d9531a46312c686b0e4e20a5d8d6e7e7647;hp=11b263620054aadb8061ff3e211c2fd85520e323;hpb=ff9f6693c80b77de767cd8940ad29ea3fc785091;p=plewww.git diff --git a/planetlab/nodes/index.php b/planetlab/nodes/index.php index 11b2636..3a5cb1c 100644 --- a/planetlab/nodes/index.php +++ b/planetlab/nodes/index.php @@ -5,502 +5,7 @@ // Require login require_once 'plc_login.php'; -// Get session and API handles -require_once 'plc_session.php'; -global $plc, $api, $adm; - -// Print header -require_once 'plc_drupal.php'; -drupal_set_title('Nodes'); -include 'plc_header.php'; - -// Common functions -require_once 'plc_functions.php'; -require_once 'plc_sorts.php'; - -// find person roles -$_person= $plc->person; -$_roles= $_person['role_ids']; - -//////////////////// -// The set of columns to fetch -// and the filter applied for fetching sites -$columns = array( "node_id", "hostname", "boot_state", "peer_id" ) ; -$filter = array("node_type"=>"regular"); -if ( in_array( '10', $_roles ) || in_array('20', $_roles) || in_array('40',$_roles)) { - // admins, PIs and techs can see interface details - $columns [] = "interface_ids"; - } - -////////////////// -// perform post-processing on objects as returned by GetNodes -// performs sanity check and summarize the result in a single column -// performs in-place replacement, so passes a reference -function layout_node ($node) { - - // we need the 'interface_ids' field to do this - // so regular users wont run this - if ( ! array_key_exists ('interface_ids', $node)) - return $node; - - $messages=array(); - - // do all this stuff on local nodes only - if ( ! $node['peer_id'] ) { - // check that the node has keys - if (count($node['interface_ids']) == 0) - $messages [] = "No interface"; - - } - // but always cleanup $node columns - unset ($node['interface_ids']); - $node['status'] = plc_make_table('plc-warning',$messages); - $node['comon'] = plc_comon_button("node_id",$node['node_id']); - return $node; -} - -// if nodepattern is set then set id to that node's id. -// we use GET rather than POST so paginate can display the right contents on subsequent pages -// can be useful for writing bookmarkable URL's as well -if( $_GET['nodepattern'] || $_GET['peerscope']) { - - // nodepattern - $nodepattern= $_GET['nodepattern']; - // need to use a hash filter for patterns to be properly handled - if (empty($nodepattern)) { - $nodepattern="*"; - } - $filter = array_merge (array( "hostname"=>$nodepattern ), $filter); - - // peerscope - list ( $peer_filter, $peer_label) = plc_peer_info($api,$_GET['peerscope']); - $filter=array_merge($filter,$peer_filter); - - $nodes= $api->GetNodes($filter, $columns); - $nodes_count = count ($nodes); - if ( $nodes_count == 1) { - header( "location: index.php?id=". $nodes[0]['node_id'] ); - exit(); - } else if ( $nodes_count == 0) { - echo " No node matching $nodepattern "; - } else { - drupal_set_title ("Nodes matching $nodepattern on". $peer_label); - $nodes = array_map(layout_node,$nodes); - sort_nodes ($nodes); - echo paginate( $nodes, "node_id", "Nodes", 25, "hostname"); - } -} -// if a site_id is given, display the site nodes only -else if( $_GET['site_id'] ) { - - $site_id= $_GET['site_id']; - - // Get site info - $site_info= $api->GetSites( array( intval( $site_id ) ), array( "name", "node_ids" ) ); - drupal_set_title("Nodes on site " . $site_info[0]['name']); - - // Get site nodes - $nodes= $api->GetNodes( array_merge(array('node_id'=>$site_info[0]['node_ids']),$filter), $columns); - - if ( empty ($nodes) ) { - echo "No node to display"; - } else { - - $nodes = array_map(layout_node,$nodes); - sort_nodes( $nodes ); - - echo paginate( $nodes, "node_id", "Nodes", 25, "hostname"); - } - -} -// if a slice_id is given, display only the nodes related to this slice -else if( $_GET['slice_id'] ) { - - $slice_id= $_GET['slice_id']; - - // Get slice infos - $slice_info= $api->GetSlices( array( intval( $slice_id ) ), array( "name", "node_ids" ) ); - drupal_set_title("nodes where " . $slice_info[0]['name'] . " is running"); - - // Get slice nodes - $nodes= $api->GetNodes( array_merge(array('node_id'=>$slice_info[0]['node_ids']),$filter), $columns); - - if ( empty ($nodes) ) { - echo "No node to display"; - } else { - - $nodes = array_map(layout_node,$nodes); - sort_nodes( $nodes ); - - echo paginate( $nodes, "node_id", "Nodes", 25, "hostname"); - echo "

Go to slice page

"; - } - - } -// if no node id, display list of nodes to choose -elseif( !$_GET['id'] ) { - - // GetNodes API call - $nodes= $api->GetNodes( empty($filter) ? NULL : $filter, $columns ); - - if ( empty ($nodes) ) { - echo "No node to display"; - } else { - - $nodes = array_map(layout_node,$nodes); - sort_nodes( $nodes ); - - drupal_set_html_head(' - - '); - - echo "
\n -
\n"; - echo "\n -\n -\n -\n - -\n -\n -
\n -
\n"; - - echo paginate( $nodes, "node_id", "Nodes", 25, "hostname" ); - - echo "\n"; - } -} - -if ( $_GET['id'] ) { - // get the node id from the URL - $node_id= intval( $_GET['id'] ); - - // make the api call to pull that nodes DATA - $node_info= $api->GetNodes( array( $node_id ) ); - - if (empty ($node_info)) { - echo "No such node."; - } else { - - // node info - $hostname= $node_info[0]['hostname']; - $boot_state= $node_info[0]['boot_state']; - $site_id= $node_info[0]['site_id']; - $model= $node_info[0]['model']; - $version= $node_info[0]['version']; - - // arrays of ids of node info - $slice_ids= $node_info[0]['slice_ids']; - $conf_file_ids= $node_info[0]['conf_file_ids']; - $interface_ids= $node_info[0]['interface_ids']; - $nodegroup_ids= $node_info[0]['nodegroup_ids']; - $pcu_ids= $node_info[0]['pcu_ids']; - $ports= $node_info[0]['ports']; - - // get peer - $peer_id= $node_info[0]['peer_id']; - - // gets site info - $site_info= $api->GetSites( array( $site_id ) ); - $site_name= $site_info[0]['name']; - $site_nodes= $site_info[0]['node_ids']; - - if( !empty( $site_nodes ) ) { - // get site node info basics - $site_node_list= $api->GetNodes( $site_nodes ); - - foreach( $site_node_list as $s_node ) { - $site_node[$s_node['node_id']]= $s_node['hostname']; - } - } - - // gets slice info for each slice - if( !empty( $slice_ids ) ) - $slice_info= $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 ); - - // gets nodegroup info - if( !empty( $nodegroup_ids ) ) - $node_groups= $api->GetNodeGroups( $nodegroup_ids ); - - // xxx Thierry : disabling call to GetEvents, that gets the session deleted in the DB - // gets events - // $filter= array( "object_type"=>"Node", "object_id"=>$node_id ); - // $fields= array( "event_id", "person_id", "fault_code", "call_name", "call", "message", "time" ); - // - // $event_info= $api->GetEvents( $filter, $fields ); - - // gets pcu and port info key to both is $pcu_id - if( !empty( $pcu_ids ) ) - $PCUs= $api->GetPCUs( $pcu_ids ); - - - // display node info - if ( $peer_id) { - echo "
"; - } - - drupal_set_title("Node " . $hostname . " details"); - - $is_admin = in_array( 10, $_roles ); - $is_pi = in_array( 20, $_roles ); - $is_tech = in_array( 40, $_roles ); - $in_site = in_array( $site_id, $_person['site_ids'] ); - - // available actions - if ( ! $peer_id && ( $is_admin || ( ($is_pi||$is_tech) && $in_site ) ) ) { - - // the javascript callback we set on the form; this - // (*) checks whether we clicked on 'delete' - // (*) in this case performs a javascript 'confirm' - // (*) then, notice that if we select delete, then cancel, we can select back 'Choose action' - // so submit only when value is not empty - $change='if (document.basic.action.value=="delete") if (! confirm("Are you sure you want to delete ' . $hostname . ' ? ") ) return false; if (document.basic.action.value!="") submit();'; - - echo "
"; - if ($is_admin) { - echo plc_event_button("Node","node",$node_id); - echo ""; - } - echo plc_comon_button("node_id",$node_id); - echo ""; - echo "
\n"; - echo "\n"; - echo "
\n"; - - echo "
"; - } - - echo "
"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - - if ( ! $peer_id && ( $is_admin || ( ($is_pi||$is_tech) && $in_site ) ) ) { - // handle legacy API - if ( ! method_exists ($api,"GetBootMedium")) { - $new_api_only=" disabled='disabled' "; - } - - echo "\n"; - - } - - // site info and all site nodes - echo "\n"; - echo "\n"; - echo "\n"; - - echo "
Hostname: $hostname
Model: $model
Version: $version
Boot State: "; - if ($peer_id) { - echo $boot_state; - } else { - echo "
\n"; - echo "\n"; - echo "\n"; - echo "
"; - } - echo "
Download "; - echo "
\n"; - echo "\n"; - echo "
"; - echo "
 
Site: $site_name
All site nodes: "; - if (empty($site_node)) { - echo "Site has no node"; - } else { - foreach( $site_node as $key => $val ) { - echo "$val
"; - } - } - echo "

\n"; - - if ( ! $peer_id ) { - - echo "
\n"; - - // display interfaces - if( $interfaces ) { - echo "

\n"; - echo "\n"; - echo ""; - // placeholder for the delete buttons - if ( $is_admin || ($is_pi && $in_site)) { - echo ""; - } - echo "\n"; - - foreach( $interfaces as $interface ) { - $nn_id= $interface['interface_id']; - $nn_ip= $interface['ip']; - $nn_broad= $interface['broadcast']; - $nn_primary= $interface['is_primary']; - $nn_network= $interface['network']; - $nn_dns1= $interface['dns1']; - $nn_dns2= $interface['dns2']; - $nn_hostname= $interface['hostname']; - $nn_netmaks= $interface['netmask']; - $nn_gatewary= $interface['gateway']; - $nn_mac= $interface['mac']; - $nn_bwlimit= $interface['bwlimit']; - $nn_type= $interface['type']; - $nn_method= $interface['method']; - - echo ""; - if ( $is_admin || ($is_pi && $in_site)) { - echo ""; - } - echo ""; - } - echo "\n"; - } - - echo "
Interfaces
IP AddressMethodTypeMACBandwidth Limit
"; - if (!$nn_primary) { - echo plc_delete_link_button('interfaces.php?id=' . $nn_id . '&delete=1&submitted=1', '\\nInterface ' . $nn_ip); - } else { - echo ' P '; - } - echo ""; - if( $is_admin || $is_pi || $is_tech ) { - echo "$nn_ip"; - } else { - echo "$nn_ip$nn_method$nn_type$nn_mac$nn_bwlimit
\n"; - - } else { - echo "

No interface. Please add an interface to make this a usable PLC node

.\n"; - } - - echo "
Add an interface.\n"; - echo "

\n"; - } - - // display node group info - if( !empty( $node_groups ) ) { - - echo "

\n\n"; - if( in_array( 10, $_roles ) ) echo ""; - echo "\n"; - - foreach( $node_groups as $node_group ) { - echo ""; - - if( in_array( '10', $_roles ) || ( in_array( 20, $_roles ) && in_array( $site_id, $_person['site_ids'] ) ) || ( in_array( 40, $_roles ) && in_array( $site_id, $_person['site_ids'] ) ) ) - echo ""; - - echo "\n"; - - } - echo "
Node Groups
NameDescription
". $node_group['name'] ."". $node_group['description'] ."Updateremove

\n"; - - } else { - echo "

This node is not in any nodegroup.

\n"; - } - - // select list for adding to node group - // get nodegroup info - $full_ng_info= $api->GetNodeGroups( NULL ); - if( empty( $node_groups ) ) { - $person_ng= $full_ng_info; - } else { - $person_ng= arr_diff( $full_ng_info, $node_groups ); - } - - sort_nodegroups( $person_ng ); - - if( !empty( $person_ng ) ) { - echo "

Select nodegroup to add this node to.
\n"; - echo "\n"; - } - - - // display slices - echo "


\n"; - if( !empty( $slice_info ) ) { - sort_slices( $slice_info ); - echo paginate( $slice_info, "slice_id", "Slices", 15, "name", "slivers", $node_id ); - } else { - echo "

This node is not associated to any slice.

\n"; - } - - - // display events - disabled, see GetEvents above - if( !empty( $event_info ) ) { - echo "

\n"; - echo "

\n\n\n"; - - // display event on rows of table - foreach( $event_info as $event ) { - echo "\n"; - } - echo "
Node Events
Call NameCallMessageTime
". $event['call'] ."". $event['message'] ."". $event['time'] ."
\n"; - } - - if ( $peer_id ) { - echo "

"; - } - } - if( $peer_id ) - echo "
"; - - echo "

Back to nodes list"; - - } - -// Print footer -include 'plc_footer.php'; +if ($_GET['id']) require ('node.php') ; +else require ('nodes.php'); ?>