Exemplo n.º 1
1
function print_rspec($obj, $pretty, $filterToAM)
{
    $args = array_keys($obj);
    // How many AMs reported actual results
    $amc = 0;
    foreach ($args as $arg) {
        if (is_array($obj[$arg]) and array_key_exists('value', $obj[$arg]) and array_key_exists('code', $obj[$arg]) and is_array($obj[$arg]['code']) and array_key_exists('geni_code', $obj[$arg]['code']) and $obj[$arg]['code']['geni_code'] == 0) {
            $amc = $amc + 1;
        }
    }
    foreach ($args as $arg) {
        $arg_url = $arg;
        $am_id = am_id($arg_url);
        $arg_name = am_name($arg_url);
        $arg_urn = am_urn($arg_url);
        if (is_array($obj[$arg]) and array_key_exists('value', $obj[$arg])) {
            $xml = $obj[$arg]['value'];
        } else {
            $xml = "";
        }
        $code = -1;
        if (is_array($obj[$arg]) and array_key_exists('code', $obj[$arg]) and is_array($obj[$arg]['code']) and array_key_exists('geni_code', $obj[$arg]['code'])) {
            $code = $obj[$arg]['code']['geni_code'];
        }
        if (is_array($obj[$arg]) and array_key_exists('output', $obj[$arg])) {
            $output = $obj[$arg]['output'];
        } else {
            if (!is_array($obj[$arg]) or !array_key_exists('code', $obj[$arg])) {
                $output = (string) $obj[$arg];
            } else {
                $output = "";
            }
        }
        /* If pretty, keep output clean by only printing RSpec for
              aggregates which have a slice (ie code!=12 or code !==2).
              Also don't print if no code was returned (ie code!=-1) because
              something catastrophic happened.
              -- unless there are no aggregates with resources, in which case
              we print the error.
           */
        // error_log("Aggregate listresources code is " . $code);
        if (!(($code == -1 or $code == 12 or $code == 2) and $pretty)) {
            if ($pretty) {
                print "<div class='aggregate' id='aggT_" . $am_id . "'>Aggregate <b>" . $arg_name . "'s</b> Resources:</div>";
            } else {
                print "<div class='aggregate' id='aggT_" . $am_id . "'>Aggregate <b>" . $arg_name . "'s</b> Raw Resources:</div>";
            }
            print "<div class='resources' id='agg_" . $am_id . "'>";
            if ($code == 0) {
                if ($pretty) {
                    /* Parsed into a table */
                    print_rspec_pretty($xml, False, $filterToAM, $arg_urn, $am_id);
                } else {
                    //	  /* As plain XML but with newlines after each block */
                    //	  $xml = str_replace(">", ">\n", $xml);
                    print_xml($xml);
                }
            } else {
                if ($output == "") {
                    $output = "[None. Return code: " . $code . "]";
                }
                echo "<p>Returned: <i>{$output}</i></p>";
            }
            print "</div>\n";
        }
    }
}
Exemplo n.º 2
0
function getInfoFromSliverStatusPG($obj, $status_array)
{
    $loginInfo = array();
    $pgKeyList = array();
    foreach ($obj as $am_url => $am_item) {
        $status_item = array();
        // AM url
        $status_item['url'] = $am_url;
        // AM name
        $status_item['am_name'] = am_name($am_url);
        if (!$am_item) {
            // "ERROR: empty sliver status!"
            continue;
        }
        if (!array_key_exists("users", $am_item)) {
            //    "ERROR: No 'users' key in sliver status!"
            continue;
        }
        if (!array_key_exists('geni_resources', $am_item)) {
            // "ERROR: Sliver Status lists no resources"
            continue;
        }
        $status_array[am_id($am_url)]['login_info'] = array();
        foreach ($am_item['users'] as $userDict) {
            if (!array_key_exists('login', $userDict)) {
                // "User entry had no 'login' key"
                continue;
            }
            //    } elseif (preg_match("/^Failed to get SliverStatus on urn*$/",$line,$fail)) {
            $pgKeyList[$userDict['login']] = array();
            if (!array_key_exists('keys', $userDict)) {
                continue;
            }
        }
        foreach ($userDict['keys'] as $k) {
            #XXX nriga Keep track of keys, in the future we can verify what key goes with
            # which private key
            $pgKeyList[$userDict['login']][] = $k['key'];
        }
    }
    return $status_array;
}