Пример #1
0
function get_member_info($slice, $signer, $ma_url, $sa_url)
{
    $slice_id = $slice[SA_SLICE_TABLE_FIELDNAME::SLICE_ID];
    $slice_members = get_slice_members($sa_url, $signer, $slice_id);
    $member_ids = array();
    $admin_ids = array();
    foreach ($slice_members as $slice_member) {
        if ($slice_member[SA_SLICE_MEMBER_TABLE_FIELDNAME::ROLE] == CS_ATTRIBUTE_TYPE::LEAD) {
            $slice_lead_id = $slice_member[SA_SLICE_MEMBER_TABLE_FIELDNAME::MEMBER_ID];
        } else {
            if ($slice_member[SA_SLICE_MEMBER_TABLE_FIELDNAME::ROLE] == CS_ATTRIBUTE_TYPE::ADMIN) {
                $admin_ids[] = $slice_member[SA_SLICE_MEMBER_TABLE_FIELDNAME::MEMBER_ID];
            } else {
                $member_ids[] = $slice_member[SA_SLICE_MEMBER_TABLE_FIELDNAME::MEMBER_ID];
            }
        }
    }
    $slice_member_details = lookup_member_details($ma_url, $signer, $member_ids);
    $slice_admin_details = lookup_member_details($ma_url, $signer, $admin_ids);
    $member_info_str = "<b style='text-decoration: underline;'>Slice members</b><br>";
    if (count($slice_admin_details) > 0) {
        $member_info_str .= "<b>Admins</b><br>";
        foreach ($slice_admin_details as $slice_admin_id => $slice_admin_info) {
            $slice_admin_obj = new Member($slice_admin_id);
            $slice_admin_obj->init_from_record($slice_admin_info);
            $slice_admin_name = $slice_admin_obj->prettyName();
            $slice_admin_username = $slice_admin_info[MA_ATTRIBUTE_NAME::USERNAME];
            $member_info_str .= "{$slice_admin_name} ({$slice_admin_username})<br>";
        }
    } else {
        $member_info_str .= "<i>No admins on slice</i><br>";
    }
    if (count($slice_member_details) > 0) {
        $member_info_str .= "<b>Members</b><br>";
        foreach ($slice_member_details as $slice_member_id => $slice_member_info) {
            $slice_member_obj = new Member($slice_member_id);
            $slice_member_obj->init_from_record($slice_member_info);
            $slice_member_name = $slice_member_obj->prettyName();
            $slice_member_username = $slice_member_info[MA_ATTRIBUTE_NAME::USERNAME];
            $member_info_str .= "{$slice_member_name} ({$slice_member_username})<br>";
        }
    } else {
        if (count($slice_admin_details) == 0) {
            $member_info_str .= "<i>No members on slice</i><br>";
        }
    }
    return $member_info_str;
}
Пример #2
0
//      change_slice_member_role($sa_url, $user, $slice_id, $member_id, $selection_id);
//    }
//  } else {
//    if ($selection_id > 0) {
//      // Add this member to this slice
//      add_slice_member($sa_url, $user, $slice_id, $member_id, $selection_id);
//    }
//  }
//}
if (!array_key_exists('slice_id', $_REQUEST)) {
    error_log("do-edit-slice-member called without a slice_id");
    relative_redirect('home.php');
}
$slice_id = $_REQUEST['slice_id'];
unset($_REQUEST['slice_id']);
$slice_members = get_slice_members($sa_url, $user, $slice_id);
$slice_members_by_role = array();
foreach ($slice_members as $slice_member) {
    $slice_member_id = $slice_member['member_id'];
    $slice_member_role = $slice_member['role'];
    $slice_members_by_role[$slice_member_id] = $slice_member_role;
}
$selections = $_REQUEST;
/* Remove project_id from selections so that it isn't confused
   with a member id. */
if (array_key_exists('project_id', $selections)) {
    unset($selections['project_id']);
}
$validation_result = validate_slice_member_requests($slice_members_by_role, $selections);
$success = $validation_result['success'];
if ($success) {
Пример #3
0
function get_all_members_of_slice_as_users($sa_url, $ma_url, $user, $slice_id)
{
    // Get other users on this project
    $members = get_slice_members($sa_url, $user, $slice_id);
    //error_log("Return from get_slice_members = " . print_r($members, TRUE));
    $member_uuids = array();
    foreach ($members as $member) {
        $member_id = $member[MA_ARGUMENT::MEMBER_ID];
        // In Future consider FILTER by ROLE?
        //	$role_id = $member[ 'role' ]; // FIND VARIABLE TO REPLACE
        $member_uuids[] = $member_id;
    }
    $slice_members = lookup_member_details($ma_url, $user, $member_uuids);
    //error_log("Slice members = " . print_r($slice_members, TRUE));
    $slice_users = array();
    foreach ($slice_members as $member_id => $slice_member) {
        // initialize members
        $member = new Member();
        $member->init_from_record($slice_member);
        //error_log("Member = " . print_r($member, TRUE));
        // now as users
        $slice_user = new GeniUser();
        $slice_user->init_from_member($member);
        //	error_log("Slice user = "******"Slice users = " . print_r($slice_users, TRUE));
    return $slice_users;
}
Пример #4
0
function update_user_keys_on_slivers($sa_url, $signer, $slice_id, $slice_urn, $members_to_add, $members_to_change, $members_to_remove)
{
    $username = $signer->username;
    $ma_url = sa_to_ma_url($sa_url);
    $am_urls = array();
    // Get list of aggregates for slice
    $aggs_for_slice = aggregates_in_slice($sa_url, $signer, $slice_urn);
    //  error_log("SLIVER_INFO.RES = " . print_r($aggs_for_slice, true));
    foreach ($aggs_for_slice as $agg_info) {
        if (!array_key_exists(SERVICE_ATTRIBUTE_TAG, $agg_info)) {
            continue;
        }
        $agg_attributes = $agg_info[SERVICE_ATTRIBUTE_TAG];
        $am_type = $agg_attributes[SERVICE_ATTRIBUTE_AM_TYPE];
        if ($am_type != SERVICE_ATTRIBUTE_INSTAGENI_AM) {
            continue;
        }
        // This call only works for IG/PG racks
        $am_url = $agg_info[SR_TABLE_FIELDNAME::SERVICE_URL];
        $am_urls[] = $am_url;
    }
    //  error_log("AM_URLS = " . print_r($am_urls, true));
    // If there are no AM URLs (e.g. no IG/PG AMs), then nothing to do here. Bail.
    if (count($am_urls) < 1) {
        return True;
    }
    // Generate slice_users list of dictionaries: [{"urn" : urn, "keys" : [key1, key2]}, ...]
    $slice_users_list = array();
    $slice_members = get_slice_members($sa_url, $signer, $slice_id);
    //  error_log("MEMBERS = " . print_r($slice_members, true));
    foreach ($slice_members as $member_info) {
        $member_id = $member_info[MA_MEMBER_TABLE_FIELDNAME::MEMBER_ID];
        $member_urn = get_member_urn($ma_url, $signer, $member_id);
        $keys_res = lookup_public_ssh_keys($ma_url, $signer, $member_id);
        //    error_log("MEMBER_ID = " . print_r($member_id, true));
        //    error_log("KEYS_RES = " . print_r($keys_res, true));
        $member_public_keys = array();
        foreach ($keys_res as $key_info) {
            $public_key = $key_info[MA_SSH_KEY_TABLE_FIELDNAME::PUBLIC_KEY];
            $member_public_keys[] = $public_key;
        }
        $member_entry = array('urn' => $member_urn, 'keys' => $member_public_keys);
        $slice_users_list[] = $member_entry;
    }
    // For each removed member, add an empty entry to list (to remove their SSH keys)
    foreach ($members_to_remove as $member_to_remove) {
        $member_entry = array('urn' => $member_to_remove, 'keys' => array());
        $slice_users_list[] = $member_entry;
    }
    $slice_users = array('geni_users' => $slice_users_list);
    //  error_log("GENI_USERS = " . print_r($slice_users, true));
    // invoke omni to call the geni_update_users POA
    $slice_users_json = json_encode($slice_users);
    $slice_users_filename = writeDataToTempFile($slice_users_json);
    $args = array("--optionsfile", $slice_users_filename, "poa", $slice_urn, 'geni_update_users');
    $res = invoke_omni_function($am_urls, $signer, $args, array(), 0, 0, false, NULL, 3);
    //   error_log("Update_user_keys_on_slivers.RES = " . print_r($res, true));
    // Clean up JSON file and invocation directory
    unlink($slice_users_filename);
    return $res;
}
Пример #5
0
function setup_jacks_slice_context()
{
    global $user;
    global $slice;
    global $slice_id;
    global $slice_name;
    global $ma_url;
    global $sa_url;
    global $all_ams;
    global $slice_ams;
    global $slice_urn;
    global $slice_expiration;
    // Set globals for variables used in slice jacks page later
    global $owner_email;
    global $slice_date_expiration;
    global $member_names;
    global $slice_creation;
    global $slice_desc;
    global $slice_owner_name;
    global $members;
    unset($slice);
    include "tool-lookupids.php";
    if (!isset($sa_url)) {
        $sa_url = get_first_service_of_type(SR_SERVICE_TYPE::SLICE_AUTHORITY);
    }
    if (!isset($ma_url)) {
        $ma_url = get_first_service_of_type(SR_SERVICE_TYPE::MEMBER_AUTHORITY);
    }
    if (isset($slice)) {
        $slice_name = $slice[SA_ARGUMENT::SLICE_NAME];
        //  error_log("SLICE  = " . print_r($slice, true));
        $slice_desc = $slice[SA_ARGUMENT::SLICE_DESCRIPTION];
        $slice_creation_db = $slice[SA_ARGUMENT::CREATION];
        $slice_creation = dateUIFormat($slice_creation_db);
        $slice_expiration_db = $slice[SA_ARGUMENT::EXPIRATION];
        $slice_expiration = dateUIFormat($slice_expiration_db);
        $slice_date_expiration = dateOnlyUIFormat($slice_expiration_db);
        $slice_urn = $slice[SA_ARGUMENT::SLICE_URN];
        $slice_owner_id = $slice[SA_ARGUMENT::OWNER_ID];
        $owner = $user->fetchMember($slice_owner_id);
        $slice_owner_name = $owner->prettyName();
        $owner_email = $owner->email();
        $project_name = $project[PA_PROJECT_TABLE_FIELDNAME::PROJECT_NAME];
        //error_log("slice project_name result: $project_name\n");
        // Fill in members of slice member table
        $members = get_slice_members($sa_url, $user, $slice_id);
        $member_names = lookup_member_names_for_rows($ma_url, $user, $members, SA_SLICE_MEMBER_TABLE_FIELDNAME::MEMBER_ID);
        //find only ams that slice has resources on
        $slivers = lookup_sliver_info_by_slice($sa_url, $user, $slice_urn);
        //find aggregates to be able to return just am_id
        $all_aggs = get_services_of_type(SR_SERVICE_TYPE::AGGREGATE_MANAGER);
        $aggs_with_resources = array();
        //do the comparison and find ams
        foreach ($slivers as $sliver) {
            foreach ($all_aggs as $agg) {
                if ($sliver[SA_SLIVER_INFO_TABLE_FIELDNAME::SLIVER_INFO_AGGREGATE_URN] == $agg[SR_TABLE_FIELDNAME::SERVICE_URN]) {
                    $aggs_with_resources[] = $agg[SR_TABLE_FIELDNAME::SERVICE_ID];
                    break;
                }
            }
        }
        //return unique ids
        $slice_ams = array_unique($aggs_with_resources, SORT_REGULAR);
        // Now restore the array to a numerically ordered array because
        // array_unique preserves keys, so it could turn into, in effect, a
        // dictionary.
        $slice_ams = array_values($slice_ams);
    } else {
        print "Unable to load slice<br/>\n";
        $_SESSION['lasterror'] = "Unable to load slice";
        relative_redirect("home.php");
        exit;
    }
    if (!isset($all_ams)) {
        $am_list = get_services_of_type(SR_SERVICE_TYPE::AGGREGATE_MANAGER);
        $all_ams = array();
        foreach ($am_list as $am) {
            $single_am = array();
            $service_id = $am[SR_TABLE_FIELDNAME::SERVICE_ID];
            $single_am['name'] = $am[SR_TABLE_FIELDNAME::SERVICE_NAME];
            $single_am['url'] = $am[SR_TABLE_FIELDNAME::SERVICE_URL];
            $single_am['urn'] = $am[SR_TABLE_FIELDNAME::SERVICE_URN];
            $all_ams[$service_id] = $single_am;
        }
    }
}