From: Thierry Parmentelat Date: Fri, 30 Jan 2009 15:24:01 +0000 (+0000) Subject: sites almost there X-Git-Tag: PLEWWW-4.3-1~67 X-Git-Url: http://git.onelab.eu/?p=plewww.git;a=commitdiff_plain;h=7350273c7234b154c15b422e7dda2822cd9deb66 sites almost there --- diff --git a/modules/planetlab.module b/modules/planetlab.module index 5b91c09..5bb1355 100644 --- a/modules/planetlab.module +++ b/modules/planetlab.module @@ -117,7 +117,7 @@ function planetlab_block($op = 'list', $delta = 0, $edit = array()) { $site_item .= ul_start(); $site_item .= leaf( href(l_site(plc_my_site_id()),"My site")); if ( $is_admin ) - $site_item .= leaf( href(l_site_pending(),"Pending Requests")); + $site_item .= leaf( href(l_sites_pending(),"Pending Requests")); $site_item .= ul_end(); $items[] = expanded($site_item); diff --git a/planetlab/actions.php b/planetlab/actions.php index 7e18dfd..b69af23 100644 --- a/planetlab/actions.php +++ b/planetlab/actions.php @@ -42,6 +42,8 @@ $known_actions []= "update-tag-type"; // expects: tag_type_id & name & description & category & min_role_id $known_actions []= "add-tag-type"; // expects: tag_type_id & name & description & category & min_role_id +$known_actions []= "expire-all-slices-in-site"; +// expects: slice_ids ////////////////////////////// // sometimes we don't set 'action', but use the submit button name instead @@ -225,6 +227,25 @@ switch ($action) { exit(); } + case 'expire-all-slices-in-site': { + drupal_set_message("action $action not implemented in actions.php -- need tweaks and test"); + return; + + //// old code from sites/expire.php + $sites = $api->GetSites( array( intval( $site_id ))); + $site=$sites[0]; + // xxx why not 'now?' + $expiration= strtotime( $_POST['expires'] ); + // loop through all slices for site + foreach ($site['slice_ids'] as $slice_id) { + $api->UpdateSlice( $slice_id, array( "expires" => $expiration ) ); + } + // update site to not allow slice creation or renewal + $api->UpdateSite( $site_id, array( "max_slices" => 0 )) ; + header ("location: " l_site($site_id)); + exit(0); + } + case 'debug': { plc_debug('GET',$_GET); plc_debug('POST',$_POST); diff --git a/planetlab/adminsearch.php b/planetlab/adminsearch.php index 3f182a9..1e7d347 100644 --- a/planetlab/adminsearch.php +++ b/planetlab/adminsearch.php @@ -19,18 +19,19 @@ require_once 'plc_objects.php'; require_once 'plc_sorts.php'; function is_possible_domainname($token) { - if( strpos ( $token, "@" ) === False && substr_count($token, ".") >= 2 ) { + if ( strpos ( $token, "@" ) === False && substr_count($token, ".") >= 2 ) { return true; } else { return false; } } + function get_and_print_site($site_array) { global $api; $sites = $api->GetSites( $site_array, array( "name", "site_id", "url", "enabled", "node_ids", "person_ids", "date_created", "slice_ids", "max_slivers", "max_slices", "login_base" ) ); - if( count($sites) > 0 ) { + if ( count($sites) > 0 ) { foreach( $sites as $site) { $name = $site['name']; $site_id = $site['site_id']; @@ -64,8 +65,8 @@ function get_and_print_site($site_array) { echo "\n"; } } - } + function get_and_print_hostname($host_array) { global $api; $nodes = $api->GetNodes( $host_array, array( "hostname", "node_id", @@ -95,7 +96,7 @@ function get_and_print_hostname($host_array) { return $nodes; } -function get_and_print_user($user_array) { +function get_and_print_user ($user_array) { global $api; $persons= $api->GetPersons( $user_array, array( "person_id", "first_name", "last_name", "email", "roles", "enabled", "date_created", @@ -277,7 +278,7 @@ if (false) { sort_persons( $persons ); - echo paginate( $persons, "person_id", "Persons", 25, "email" ); + echo paginate_trash ( $persons, "person_id", "Persons", 25, "email" ); } // if no person id, display list of persons to choose diff --git a/planetlab/events/index.php b/planetlab/events/index.php index e1b9ad2..625ae3c 100644 --- a/planetlab/events/index.php +++ b/planetlab/events/index.php @@ -23,7 +23,7 @@ ini_set("memory_limit","256M"); //set default title drupal_set_title('Events'); -// paginate unit +// page size $page_size=30; $messages = array (); diff --git a/planetlab/includes/plc_functions.php b/planetlab/includes/plc_functions.php index 10172a2..2bcf31f 100644 --- a/planetlab/includes/plc_functions.php +++ b/planetlab/includes/plc_functions.php @@ -57,13 +57,18 @@ function l_interface_t ($interface_id,$text) { function l_interface_add($node_id) { return "/db/nodes/interfaces.php?node_id=$node_id"; } function l_sites () { return "/db/sites/index.php"; } +function l_sites_local () { return "/db/sites/index.php?peerscope=local"; } function l_site ($site_id) { return "/db/sites/index.php?id=$site_id"; } function l_site_t ($site_id,$text) { return href (l_site($site_id),$text); } +function l_site_update($site_id) { return "/xxx-undefined"; } function l_slices () { return "/db/slices/index.php"; } function l_slice ($slice_id) { return "/db/slices/index.php?id=$slice_id"; } function l_slice_t ($slice_id,$text) { return href (l_slice($slice_id),$text); } function l_slice_add () { return "/db/slices/add_slice.php"; } +function l_slices_site($site_id) { return "/db/slices/index.php?site_id=$site_id"; } +// from an object +function l_slice_text ($slice) { return l_slice_t ($slice['slice_id'],$slice['name']); } function l_sliver ($node_id,$slice_id) { return "/db/nodes/slivers.php?node_id=$node_id&slice_id=$slice_id"; } function l_sliver_t ($node_id,$slice_id,$text) { @@ -102,7 +107,7 @@ function l_sulogout() { return "/planetlab/sulogout.php"; } function l_reset_password() { return "/db/persons/reset_password.php"; } function l_person_register() { return "/db/persons/register.php"; } function l_site_register() { return "/db/sites/register.php"; } -function l_site_pending() { return "/db/sites/join_request.php"; } +function l_sites_pending() { return "/db/sites/join_request.php"; } // returns array ['url' => path, 'values' => hash (key=>value)* ] function split_url ($full_url) { @@ -230,6 +235,15 @@ function plc_peer_shortname ($peer_hash,$peer_id) { } } +function plc_peer_label ($peer) { + if (! $peer) { + return "Local object on " . PLC_NAME . " (" . PLC_SHORTNAME . ")"; + } + $result= $peer['peername'] . " (" . $peer['shortname'] . ")"; + $result= href(l_peer($peer['peer_id']),$result); + return plc_foreign_text($result); +} + // to set the background to grey on foreign objects // return true if the peer is local function plc_peer_block_start ($peer_hash,$peer_id) { @@ -381,12 +395,9 @@ function plc_errors ($list) { print( "\n" ); } -function plc_warning_div ($text) { - return "
" . $text . "
"; -} -function plc_warning ($text) { - print plc_warning_div("Warning " . $text); -} +function plc_warning_text ($text) { return "
" . $text . "
";} +function plc_warning ($text) { print plc_warning_text("Warning " . $text); } +function plc_foreign_text($text) { return "
$text
"; } // shows a php variable verbatim with a heading message function plc_debug ($message,$object) { @@ -395,4 +406,5 @@ function plc_debug ($message,$object) { print ""; } + ?> diff --git a/planetlab/includes/plc_functions_trash.php b/planetlab/includes/plc_functions_trash.php index b4c18dd..d277c5c 100644 --- a/planetlab/includes/plc_functions_trash.php +++ b/planetlab/includes/plc_functions_trash.php @@ -3,7 +3,7 @@ // this will be trashed eventually // pagination function -function paginate( $fn_array, $table_id, $caption, $limit, $main_field, $other_func= NULL, $fid= NULL ) { +function paginate_trash ( $fn_array, $table_id, $caption, $limit, $main_field, $other_func= NULL, $fid= NULL ) { // get vars from call adjust them $dir= strtolower( $caption ); $echo= ""; diff --git a/planetlab/nodes/node.php b/planetlab/nodes/node.php index 8e4117b..842b8b7 100644 --- a/planetlab/nodes/node.php +++ b/planetlab/nodes/node.php @@ -2,7 +2,7 @@ // $Id$ - // Require login +// Require login require_once 'plc_login.php'; // Get session and API handles @@ -51,7 +51,11 @@ $nodegroup_ids= $node['nodegroup_ids']; $pcu_ids= $node['pcu_ids']; // get peer -$peer_id= $node['peer_id']; +$peer_id = $node['peer_id']; +if ($peer_id) { + $peers=$api->GetPeers(array($peer_id)); + $peer=$peers[0]; + } // gets site info $sites= $api->GetSites( array( $site_id ) ); @@ -131,6 +135,7 @@ $tabs["All nodes"]=l_nodes(); plc_tabs($tabs); plc_details_start (); +plc_details_line("Peer",plc_peer_label($peer)); plc_details_line("Hostname",$hostname); plc_details_line("Type",$node_type); plc_details_line("Model",$model); diff --git a/planetlab/nodes/nodes.php b/planetlab/nodes/nodes.php index 0db6054..13e61c2 100644 --- a/planetlab/nodes/nodes.php +++ b/planetlab/nodes/nodes.php @@ -33,7 +33,6 @@ $tabs['My nodes'] = array('url'=>l_nodes(), 'values'=>array('site_id'=>plc_my_site_id()), 'bubble'=>'Lists nodes on site ' . $mysite_id); // -------------------- -$peer_filter=array(); $node_filter=array(); ////////////////// @@ -54,7 +53,7 @@ function node_status ($node) { // fetch nodes -$node_columns=array('hostname','node_type','site_id','node_id','boot_state','interface_ids','peer_id'); +$node_columns=array('hostname','node_type','site_id','node_id','boot_state','interface_ids','peer_id', "arch"); // server-side filtering - set pattern in $_GET for filtering on hostname if ($pattern) { $node_filter['hostname']=$pattern; @@ -129,16 +128,15 @@ $headers = array ("Peer"=>"string", "Hostname"=>"string", "IP"=>"IPAddress", "Type"=>"string", + "Arch"=>"string", "?"=>"string", - "Int"=>"int", - "Float"=>"float"); + ); # initial sort on hostnames plc_table_start("nodes",$headers,4); $peer_hash = plc_peer_global_hash ($api); // write rows -$fake1=1; $fake2=3.14; $fake_i=0; foreach ($nodes as $node) { $hostname=$node['hostname']; $node_id=$node['node_id']; @@ -159,14 +157,10 @@ foreach ($nodes as $node) { plc_table_cell (l_node_t($node_id,$hostname)); plc_table_cell (l_interface_t($interface_id,$ip)); plc_table_cell ($node_type); + plc_table_cell ($node['arch']); plc_table_cell (node_status($node)); - plc_table_cell ($fake1); - plc_table_cell ($fake2); plc_table_row_end(); - if ($fake_i % 5 == 0) $fake1 += 3; - if ($fake_i % 3 == 0) $fake2 +=5; else $fake2 -= $fake_i; - $fake_i += 1; } plc_table_end("nodes"); diff --git a/planetlab/persons/person.php b/planetlab/persons/person.php index 965e1d8..87b6827 100644 --- a/planetlab/persons/person.php +++ b/planetlab/persons/person.php @@ -130,7 +130,7 @@ if ($local_peer && $privileges && ! $enabled ) drupal_set_message ("$first_name $last_name is not enabled yet, you can enable her/him with the 'Enable' button below"); $enabled_text="Enabled"; -if ( ! $enabled ) $enabled_text = plc_warning_div("Disabled"); +if ( ! $enabled ) $enabled_text = plc_warning_text("Disabled"); plc_details_start(); plc_details_line("Enabled",$enabled_text); diff --git a/planetlab/persons/persons.php b/planetlab/persons/persons.php index 31408c4..f5ac603 100644 --- a/planetlab/persons/persons.php +++ b/planetlab/persons/persons.php @@ -35,7 +35,6 @@ $tabs['My accounts'] = array('url'=>l_persons(), 'values'=>array('site_id'=>plc_my_site_id()), 'bubble'=>'Lists accounts on site ' . plc_my_site_id()); // -------------------- -$peer_filter=array(); $person_filter=array(); //////////////////// diff --git a/planetlab/sites/expire.php b/planetlab/sites/expire.php deleted file mode 100644 index 6522909..0000000 --- a/planetlab/sites/expire.php +++ /dev/null @@ -1,74 +0,0 @@ -person; -$_roles= $_person['role_ids']; - - -// if no site id redirect -if( !$_GET['id'] ) { - header( "location: index.php" ); - exit(); - } - -// get site id -$site_id= $_GET['id']; - -// get site info -$site_info= $api->GetSites( array( intval( $site_id ), array( "name", "url", "longitude", "latitude", "login_base", "max_slices", "abbreviated_name", "slice_ids" ) ); - -// if submitted expire -if( $_POST['action'] ) { - $expiration= strtotime( $_POST['expires'] ); - - // loop through all slices for site - foreach( $site_info[0]['slice_ids'] as $slice_id ) { - $fields= array( "expires" => $expiration ); - // update all slice's expiration - $api->UpdateSlice( $slice_id, $fields ); - - } - - // update site to not allow slice creation or renewal - $site_fields= array( "max_slices" => 0 ); - $api->UpdateSite( $site_id, $site_fields ); - -} - - -// Print header -require_once 'plc_drupal.php'; -drupal_set_title('Sites'); -include 'plc_header.php'; - -// start form -echo "
\n"; -echo "

Expire ". $site_info[0]['name'] ."

\n"; -echo "Expiration: \n"; -echo "

Are you sure you want to set the expiration date for all slices that expire after the above date to the above date as well as disable slice creation and renewal at this site?

\n"; -echo "\n"; - -echo "

Back to Site\n"; - - -echo "

\n"; - - -// Print footer -include 'plc_footer.php'; - -?> diff --git a/planetlab/sites/index.php b/planetlab/sites/index.php index 4b7443f..a871948 100644 --- a/planetlab/sites/index.php +++ b/planetlab/sites/index.php @@ -1,445 +1,11 @@ person; -$_roles= $_person['role_ids']; - -//////////////////// -// The set of columns to fetch -// and the filter applied for fetching sites -if ( !in_array( '10', $_roles ) ) { - $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" ); - $filter = array ("enabled" => TRUE); - } else { - $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" , "enabled", "person_ids", "max_slices", "slice_ids", "node_ids"); - $filter = array (); - } - - -////////////////// -// perform post-processing on site objects as returned by GetSites -// performs sanity check and summarize the result in a single column -// performs in-place replacement, so passes a reference -function layout_site ($site) { - - // we need the 'enabled' field to do this - // so regular users wont run this - if ( ! array_key_exists ('enabled', $site)) - return $site; - - $messages=array(); - - if (empty ($site['node_ids'])) $messages [] = "Site has no node"; - $class='plc-foreign'; - - // do all this stuff on local sites only - if ( ! $site['peer_id'] ) { - - $class='plc-warning'; - - // check that site is enabled - if ( ! $site['enabled']) { - $messages [] = "Not enabled"; - } - - // check that site has at least a PI and a tech - global $api; - $persons=$api->GetPersons(array("person_id"=>$site['person_ids']),array("role_ids")); - $nb_pis=0; - $nb_tech=0; - - if ( ! empty ($persons)) { - foreach ($persons as $person) { - if (in_array( '20', $person['role_ids'])) $nb_pis += 1; - if (in_array( '40', $person['role_ids'])) $nb_techs += 1; - } - } - if ($nb_pis == 0) $messages [] = "Site has no PI"; - if ($nb_techs == 0) $messages [] = "Site has no Tech"; - - // check number of slices - if ( $site['max_slices'] == 0) { - $messages [] = "No slice allowed"; - } else if (count($site["slice_ids"]) >= $site['max_slices']) { - $messages [] = "Site has no slice left"; - } - - // pretty print the cell - } - // but always cleanup $site columns - unset ($site['enabled']); - unset ($site['person_ids']); - unset ($site['max_slices']); - unset ($site['slice_ids']); - unset ($site['node_ids']); - $site['sanity check'] = plc_vertical_table($messages,$class); - - return $site; -} - - -// if sitepattern or peerscope is set : search the sites -// 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['sitepattern'] || $_GET['peerscope']) { - $sitename= $_GET['sitepattern']; - if (empty($sitename)) { - $sitename="*"; - } - $filter = array_merge (array( "name"=>$sitename ), $filter); - switch ($_GET['peerscope']) { - case '': - $peer_label="all peers"; - break; - case 'local': - $filter=array_merge(array("peer_id"=>NULL),$filter); - $peer_label="local peer"; - break; - case 'foreign': - $filter=array_merge(array("~peer_id"=>NULL),$filter); - $peer_label="foreign peers"; - break; - default: - $peer_id=intval($_GET['peerscope']); - $filter=array_merge(array("peer_id"=>$peer_id),$filter); - $peer=$api->GetPeers(array("peer_id"=>$peer_id)); - $peer_label='peer "' . $peer[0]['peername'] . '"'; - break; - } - - $sites= $api->GetSites( $filter , $site_columns); - $sites = array_map(layout_site,$sites); - - $sites_count = count ($sites); - if ( $sites_count == 1) { - header( "location: index.php?id=". $sites[0]['site_id'] ); - exit(); - } else if ( $sites_count == 0) { - echo " No site matching $sitename on " . $peer_label . " "; - } else { - drupal_set_title ("Sites matching $sitename on " . $peer_label); - sort_sites ($sites); - echo paginate( $sites, "site_id", "Sites", 25, "name"); - } -} - - -// if no site id, display list of sites to choose -elseif( !$_GET['id'] ) { - - // GetSites API call - // careful, need to pass NULL and *not* array() if no filter is given - $sites= $api->GetSites( empty($filter) ? NULL : $filter, $site_columns ); - $sites = array_map(layout_site,$sites); - if ( empty ($sites)) { - echo "No site to display"; - } else { - sort_sites( $sites ); - - drupal_set_html_head(' - - '); - - echo "
\n -
\n"; - echo "\n -\n -\n -\n - -\n -\n -
\n -
\n"; - - echo paginate( $sites, "site_id", "Sites", 25, "name" ); - - echo "\n"; - } -} -else { - // stores get variable and casts it as int - $site_id= intval( $_GET['id'] ); - - // api call GetSites - $site_info= $adm->GetSites( array( $site_id ) ); - - // var names to api return - $sitename= $site_info[0]['name']; - $abbrev_name= $site_info[0]['abbreviated_name']; - $site_url= $site_info[0]['url']; - $login_base= $site_info[0]['login_base']; - $site_lat= $site_info[0]['latitude']; - $site_long= $site_info[0]['longitude']; - $max_slivers= $site_info[0]['max_slivers']; - $max_slices= $site_info[0]['max_slices']; - - $enabled = $site_info[0]['enabled']; - - // peer id - $peer_id= $site_info[0]['peer_id']; - - $site_addresses= $site_info[0]['address_ids']; - $site_pcus= $site_info[0]['pcu_ids']; - $site_nodes= $site_info[0]['node_ids']; - $site_persons= $site_info[0]['person_ids']; - $site_slices= $site_info[0]['slice_ids']; - - $adm->begin(); - // gets address info - $adm->GetAddresses( $site_addresses ); - - // gets pcu info - $adm->GetPCUs( $site_pcus ); - - // gets node info - $adm->GetNodes( $site_nodes, array( "node_id", "hostname", "boot_state" ) ); - - // gets person info - $adm->GetPersons( $site_persons, array( "role_ids", "person_id", "first_name", "last_name", "email", "enabled" ) ); - - $adm->GetSlices ( $site_slices, array ("slice_id", "name", "instantiation" ) ); - - list( $addresses, $pcus, $nodes, $persons, $slices )= $adm->commit(); - - $techs = array(); - $pis = array(); - foreach( $persons as $person ) { - $role_ids= $person['role_ids']; - if( in_array( '40', $role_ids )) - $techs[] = $person; - - if( in_array( '20', $role_ids )) - $pis[] = $person; - - } - - if( $peer_id ) { - echo "
\n"; - } - - // start form - drupal_set_title("Site $sitename details"); - // echo "

$sitename Site details

\n"; - - if( !$peer_id ) { - $actions= array( ''=>'Choose Action' ); - - if( in_array( 10, $_roles ) - || ( in_array( 20, $_roles ) && in_array( $site_id, $_person['site_ids'] ) ) ) { - $actions['update']= 'Update Site'; - } - - if( in_array( 10, $_roles ) ) { - $actions['delete']= 'Delete Site'; - $actions['expire']= 'Expire All Slices'; - } - - echo "
"; - if( in_array( 10, $_roles ) ) { - echo plc_event_button("Site","site",$site_id); - echo "\n"; - } - echo plc_comon_button("site_id",$site_id); - // comon link - echo ""; - - // list to take site action - echo "
\n"; - echo "\n"; - echo "\n"; - echo "
"; - - echo "
\n"; - } - - - if ( ! $enabled ) { - echo "

This site is not enabled - Please visit this page to review pending applications.

"; - } - - // basic site info - echo "

\n - \n - \n - \n - \n - \n - \n"; - - if( $peer_id ) { - // display peer name - echo "\n"; - $peer = $api->GetPeers(array('peer_id'=>$peer_id)); - echo ""; - // we wrap up everything here - // the local version closes the table in the middle of the page... - echo "
Full name: $sitename
Login base: $login_base
Abbreviated Name: $abbrev_name
URL: $site_url
Latitude: $site_lat
Longitude: $site_long
Managed at foreign peer:" . $peer[0]['peername'] . "
"; - echo "

"; - - } else { - - // Slices - echo "\n"; - $href="'/db/slices/index.php?site_id=" . $site_id . "'"; - $slice_text="" . count($site_slices) . "/" . $max_slices; - if (count($site_slices) >= $max_slices) { - $slice_text .= " Maximum number of slices reached !"; - } - printf("# Slices Used/Allocated: %s\n",$href,$href,$slice_text); - if ( ! empty ($site_slices)) { - foreach ($slices as $slice) { - $href="'/db/slices/index.php?id=" . $slice['slice_id'] . "'"; - printf (" %s %s \n", - $href,$slice['name'],$href,$slice['instantiation']); - } - } - - // Users - echo "\n"; - $href="'/db/persons/index.php?site_id=" . $site_id . "'"; - printf (" # UsersTotal %d users\n",$href,$href,count($site_persons)); - - echo "PI(s)"; - if ( ! $pis) { - echo "Site has no PI !!"; - } else { - echo ""; - foreach( $pis as $person ) { - echo "\n"; - } - echo "
"; - if ( ! $person['enabled'] ) { - printf(" %s (not enabled yet)
\n",$person['person_id'],$person['email']); - } else { - printf("%s
\n",$person['person_id'],$person['email']); - } - echo "
\n"; - } - echo "\n"; - - echo "Tech(s)"; - if ( ! $techs) { - echo "Site has no Technical contact !!"; - } else { - echo ""; - foreach( $techs as $person ) { - echo "\n"; - } - echo "
"; - if ( ! $person['enabled'] ) { - printf(" %s (not enabled yet)
\n",$person['person_id'],$person['email']); - } else { - printf("%s
\n",$person['person_id'],$person['email']); - } - echo "
\n"; - } - echo "\n"; - - // Nodes - echo "\n"; - $href="'/db/nodes/index.php?site_id=" . $site_id . "'"; - printf ("# Nodes",$href); - if (empty ($site_nodes)) { - $right_site = in_array($site_id,$_person['site_ids']); - $right_role = in_array(30,$_roles) || in_array(40,$_roles); - $can_add = $right_site && $right_role; - if ($can_add) { - $href_node_add = "'/db/nodes/node_add.php'"; - printf ("0 Site has no node, please add one",$href_node_add); - } else { - printf ("0 Site has no node",$href); - } - } else { - printf ("%d",$href,count($nodes)); - } - echo ""; - - if( !empty( $site_nodes ) ) { - foreach( $nodes as $node ) { - echo "". $node['hostname'] ."". $node['boot_state'] ."\n"; - } - - } - - echo "\n"; - - // Addresses - echo "
\n"; - - // if there is an address list it. - if( !empty( $addresses ) ) { - echo "

Addresses

\n"; - - foreach( $addresses as $address ) { - echo "

\n\n\n\n\n
"; - - $comma= count( $address['address_types'] ); - $count= 0; - foreach( $address['address_types'] as $add_type ) { - echo $add_type; - $count++; - if ( $comma > 0 && $count != $comma ) - echo ", "; - } - - echo "
". $address['line1'] ."
". $address['line2'] ."
". $address['line3'] ."
". $address['city'] .", ". $address['state'] ." ". $address['postalcode'] ."
". $address['country'] ."

\n"; - } - - } - else { - echo "Site has no addresses. \n"; - } - - // if eligable display add address - /*if( in_array( '10', $_roles ) || in_array( '20', $_roles ) ) - echo "

Add an address\n";*/ - - } - - echo "


Back to site list"; - -} - - -// Print footer -include 'plc_footer.php'; +if ($_GET['id']) require ('site.php') ; +else require ('sites.php'); ?> diff --git a/planetlab/sites/site.php b/planetlab/sites/site.php new file mode 100644 index 0000000..822ed4c --- /dev/null +++ b/planetlab/sites/site.php @@ -0,0 +1,195 @@ +GetSites( array($site_id)); + +if (empty($sites)) { + drupal_set_message ("Site " . $site_id . " not found"); + return; + } + +$site=$sites[0]; +// var names to api return +$sitename= $site['name']; +$abbrev_name= $site['abbreviated_name']; +$site_url= $site['url']; +$login_base= $site['login_base']; +$site_lat= $site['latitude']; +$site_long= $site['longitude']; +$max_slivers= $site['max_slivers']; +$max_slices= $site['max_slices']; + +$enabled = $site['enabled']; + +// get peer details +$peer_id= $site['peer_id']; +if ($peer_id) { + $peers=$api->GetPeers(array("peer_id"=>$peer_id)); + $peer=$peers[0]; + } + +$adress_ids= $site['address_ids']; +$pcu_ids= $site['pcu_ids']; +$node_ids= $site['node_ids']; +$person_ids= $site['person_ids']; +$slice_ids= $site['slice_ids']; + +$api->begin(); +// gets address info +$api->GetAddresses( $adress_ids ); + +// gets pcu info +$api->GetPCUs( $pcu_ids ); + +// gets node info +$api->GetNodes( $node_ids, array( "node_id", "hostname", "boot_state" ) ); + +// gets person info +$api->GetPersons( $person_ids, array( "role_ids", "person_id", "first_name", "last_name", "email", "enabled" ) ); + +$api->GetSlices ( $slice_ids, array ("slice_id", "name", "instantiation" ) ); + +list( $addresses, $pcus, $nodes, $persons, $slices )= $api->commit(); + +$techs = array(); +$pis = array(); +foreach( $persons as $person ) { + $role_ids= $person['role_ids']; + if( in_array( '40', $role_ids )) + $techs[] = $person; + + if( in_array( '20', $role_ids )) + $pis[] = $person; + +} + +// fetches peers and initialize hash peer_id->peer +$peer_hash = plc_peer_global_hash ($api); +// show gray background on foreign objects : start a

with proper class +plc_peer_block_start ($peer_hash,$peer_id); + +drupal_set_title("Details for site " . $sitename); + +// extra privileges to admins, and pi on this site +$privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi()); + +$tabs=array(); +// available actions +if ( ! $peer_id && $privileges ) { + + $tabs['Update']=array('url'=>l_site_update($site_id)); + // not avail to PI + $tabs['Expire slices'] = array('url'=>l_actions(), + 'values'=>array('site_id'=>$site_id, + 'action'=>'expire-all-slices-in-site'), + 'bubble'=>"Expire all slices and prevent creation of new slices", + 'confirm'=>"Suspend all slices in $login_base"); + if (plc_is_admin()) + $tabs['Delete']=array('url'=>l_actions(), + 'values'=>array('site_id'=>$site_id, + 'action'=>'delete-site'), + 'bubble'=>"Delete site $login_base", + 'confirm'=>"Are you sure you want to delete site $login_base"); + $tabs["Events"]=array('url'=>l_event("Site","site",$site_id), + 'bubble'=>"Events for site $hostname"); + $tabs["Comon"]=array('url'=>l_comon("site_id",$site_id), + 'buble'=>"Comon page for $hostname"); + + if (plc_is_admin()) + $tabs['Pending'] = array ('url'=>l_sites_pending(), + 'bubble'=>'Review pending join requests'); + } + +$tabs["All sites"]=l_sites(); + +plc_tabs($tabs); + +if ( ! $enabled ) + plc_warning ("This site is not enabled - Please visit " . + href (l_sites_pending(),"this page") . + " to review pending applications."); + +plc_details_start(); +plc_details_line("Peer",plc_peer_label($peer)); +plc_details_line("Full name",$sitename); +plc_details_line("Login base",$login_base); +plc_details_line("Abbreviated name",$abbrev_name); +plc_details_line("URL",$site_url); +plc_details_line("Latitude",$site_lat); +plc_details_line("Longitude",$site_long); + +if ( ! $peer_id ) { + + // Nodes + plc_details_space_line(); + $nb_boot = 0; + if ($nodes) foreach ($nodes as $node) if ($node['boot_state'] == 'boot') $nb_boot ++; + $node_text = $nb_boot . " boot / " . count($nodes) . " total"; + plc_details_line("# Nodes", href(l_nodes_site($site_id),$node_text)); + function n_link ($n) { return l_node_t($n['node_id'],$n['hostname'] . " (" . $n['boot_state'] . ")");} + $nodes_text= plc_vertical_table(array_map ("n_link",$nodes)); + plc_details_line ("hostnames",$nodes_text); + + // Users + plc_details_space_line(); + $user_text = count($person_ids) . " total / " . + count ($pis) . " PIs / " . + count ($techs) . " techs"; + if ( (count ($pis) == 0) || (count ($techs) == 0) || (count($person_ids) >=50)) + $user_text = plc_warning_text ($user_text); + plc_details_line ("# Users",href(l_persons_site($site_id),$user_text)); + function p_link ($p) { return l_person_t($p['person_id'],$p['email']); } + // PIs + $pi_text = plc_vertical_table (array_map ("p_link",$pis)); + plc_details_line("PI's",$pi_text); + // PIs + $tech_text = plc_vertical_table (array_map ("p_link",$techs)); + plc_details_line("techs's",$tech_text); + + // Slices + plc_details_space_line(); + // summary on # slices + $slice_text = count($slice_ids) . " running / " . $max_slices . " max"; + if (count($slice_ids) >= $max_slices) $slice_text = plc_warning_text ($slice_text); + plc_details_line("# Slices", href(l_slices_site($site_id),$slice_text)); + if ($slices) foreach ($slices as $slice) + plc_details_line($slice['instantiation'],l_slice_text($slice)); + + + } + +plc_details_end(); + +//////////////////////////////////////// +plc_peer_block_end(); + +// Print footer +include 'plc_footer.php'; + +?> diff --git a/planetlab/sites/sites.php b/planetlab/sites/sites.php new file mode 100644 index 0000000..3a72f81 --- /dev/null +++ b/planetlab/sites/sites.php @@ -0,0 +1,140 @@ +GetPersons(array("person_id"=>$site['person_ids']),array("role_ids")); + $nb_pis=0; + $nb_tech=0; + if ( $persons) foreach ($persons as $person) { + if (in_array( '20', $person['role_ids'])) $nb_pis += 1; + if (in_array( '40', $person['role_ids'])) $nb_techs += 1; + } + if ($nb_pis == 0) $messages [] = "No PI"; + if ($nb_techs == 0) $messages [] = "No Tech"; + + // check number of slices + if ( $site['max_slices'] == 0) { + $messages [] = "No slice allowed"; + } else if (count($site["slice_ids"]) >= $site['max_slices']) { + $messages [] = "No slice left"; + } + } + + return plc_vertical_table ($messages,$class); +} + +//////////////////// +// The set of columns to fetch +// and the filter applied for fetching sites +if ($pattern) { + $site_filter['login_base']=$pattern; + $title .= " with login_base matching " . $pattern; + } else { + $site_filter['login_base']="*"; + } + +// server-side selection on peerscope +list ( $peer_filter, $peer_label) = plc_peer_info($api,$_GET['peerscope']); +$site_filter=array_merge($site_filter,$peer_filter); + +if (! plc_is_admin()) { + $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" ); + $site_filter = array_merge ($site_filter, array ("enabled" => TRUE)); + } else { + $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" , + "enabled", "person_ids", "max_slices", "slice_ids", "node_ids"); + } + +$tabs['My site'] = array('url'=>l_site(plc_my_site_id())); +$tabs['Local sites'] = array('url'=>l_sites_local()); +if (plc_is_admin()) + $tabs['Pending'] = array ('url'=>l_sites_pending(), + 'bubble'=>'Review pending join requests'); + +drupal_set_title($title); +plc_tabs($tabs); + +// go +$sites= $api->GetSites( $site_filter , $site_columns); + +$peer_hash = plc_peer_global_hash ($api); + +$headers['Peer']="string"; +$headers['Name']="string"; +$headers['Login_base']="string"; +$headers['Abbreviated']="string"; +if (plc_is_admin()) { + $headers['N']="int"; + $headers['U']="int"; + $headers['S']="int"; + $headers['?']="string"; + } + +plc_table_start("sites",$headers,3); +if ($sites) foreach ($sites as $site) { + $shortname = plc_peer_shortname ($peer_hash,$site['peer_id']); + plc_table_row_start($site['login_base']); + plc_table_cell($shortname); + plc_table_cell (l_site_t($site['site_id'],$site['name'])); + plc_table_cell ($site['login_base']); + plc_table_cell ($site['abbreviated_name']); + if (plc_is_admin()) { + plc_table_cell(count($site['node_ids'])); + plc_table_cell(count($site['person_ids'])); + plc_table_cell(count($site['slice_ids'])); + plc_table_cell(site_status($site)); + } + plc_table_row_end(); +} +plc_table_end("sites"); + +// Print footer +include 'plc_footer.php'; + +?>