示例#1
0
static int status(char *nodes, opal_list_t *images)
{
    char *query, *line, *ptr;
    FILE *fp;
    orcm_pvsn_provision_t *pvn, *pvnptr;
    opal_value_t *attr;
    int i, rc=ORTE_SUCCESS;
    int j;
    char **nodelist, **ranges;

    OPAL_OUTPUT_VERBOSE((5, orcm_pvsn_base_framework.framework_output,
                         "%s pvsn:wwulf:status",
                         ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));

    /* if nodes is NULL, then get the info for all nodes. Note
     * that this could be a *lot* of info for a large cluster */
    if (NULL == nodes) {
        (void)asprintf(&query, "%s provision print", cmd);
    } else {
        /* could be a comma-separated regex, so parse it */
        ranges = opal_argv_split(nodes, ',');
        nodelist = NULL;
        for (i=0; NULL != ranges[i]; i++) {
            if (ORTE_SUCCESS != (rc = orte_regex_extract_node_names(ranges[i], &nodelist))) {
                ORTE_ERROR_LOG(rc);
                opal_argv_free(ranges);
                return rc;
            }
        }
        opal_argv_free(ranges);
        ptr = opal_argv_join(nodelist, ' ');
        opal_argv_free(nodelist);
        (void)asprintf(&query, "%s provision print %s", cmd, ptr);
        free(ptr);
    }

    if (NULL == (fp = popen(query, "r"))) {
        OPAL_OUTPUT_VERBOSE((5, orcm_pvsn_base_framework.framework_output,
                             "%s pvsn:wwulf:avail query for provisioning status failed",
                             ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));
        free(query);
        return ORCM_ERROR;
    }
    free(query);
    while (NULL != (line = orcm_getline(fp))) {
        OPAL_OUTPUT_VERBOSE((5, orcm_pvsn_base_framework.framework_output,
                             "%s pvsn:wwulf:status got input %s",
                             ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), line));
        /* if the line starts with #, it can be ignored */
        if ('#' == line[0]) {
            free(line);
            continue;
        }
        /* we want the following sections of the output line:
         * 0  => node name
         * 1  => attribute
         * 3  => value
         */
        ptr = line;
        j=0;
        while (NULL != (query = parse_next(ptr, &ptr))) {
            switch(j) {
            case 0:
                /* see if we already have this node */
                pvn = NULL;
                OPAL_LIST_FOREACH(pvnptr, images, orcm_pvsn_provision_t) {
                    if (0 == strcmp(pvnptr->nodes, query)) {
                        pvn = pvnptr;
                        break;
                    }
                }
                if (NULL == pvn) {
                    pvn = OBJ_NEW(orcm_pvsn_provision_t);
                    opal_list_append(images, &pvn->super);
                    pvn->nodes = strdup(query);
                    /* need to come up with a naming scheme for images */
                    pvn->image.name = strdup(query);
                }
                break;
            case 1:
                attr = OBJ_NEW(opal_value_t);
                attr->key = strdup(query);
                opal_list_append(&pvn->image.attributes, &attr->super);
                break;
            case 3:
                attr->type = OPAL_STRING;
                attr->data.string = strdup(query);
                break;
            default:
                /* just ignore it */
                break;
            }
            j++;
        }
        free(line);
    }
    pclose(fp);

    return ORCM_SUCCESS;
}
示例#2
0
static int avail(char *resources, opal_list_t *available)
{
    char *query, *line, *ptr;
    FILE *fp;
    orcm_pvsn_resource_t *res;
    opal_value_t *attr;
    char **types = NULL;
    int i, rc=ORTE_SUCCESS;
    int j;

    OPAL_OUTPUT_VERBOSE((5, orcm_pvsn_base_framework.framework_output,
                         "%s pvsn:wwulf:avail",
                         ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));

    /* A NULL for resources indicates the caller wants a list
     * of all known resource types. WW only has two of interest:
     * vnfs images and files */
    if (NULL == resources) {
        opal_argv_append_nosize(&types, "images");
        opal_argv_append_nosize(&types, "files");
    } else {
        /* the resource request can contain a comma-separated list
         * of desired resource types, so split it here */
        types = opal_argv_split(resources, ',');
    }

    for (i=0; NULL != types[i]; i++) {
        OPAL_OUTPUT_VERBOSE((5, orcm_pvsn_base_framework.framework_output,
                             "%s pvsn:wwulf:avail looking for resource type %s",
                             ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), types[i]));
        if (0 == strcasecmp(types[i], "images")) {
            OPAL_OUTPUT_VERBOSE((5, orcm_pvsn_base_framework.framework_output,
                                 "%s pvsn:wwulf:avail getting vnfs list",
                                 ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));
            /* get the vnfs image list */
            (void)asprintf(&query, "%s vnfs list", cmd);
            if (NULL == (fp = popen(query, "r"))) {
                OPAL_OUTPUT_VERBOSE((5, orcm_pvsn_base_framework.framework_output,
                                     "%s pvsn:wwulf:avail query for resource type %s failed",
                                     ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), types[i]));
                free(query);
                rc = ORTE_ERROR;
                break;
            }
            free(query);
            while (NULL != (line = orcm_getline(fp))) {
                OPAL_OUTPUT_VERBOSE((5, orcm_pvsn_base_framework.framework_output,
                                     "%s pvsn:wwulf:avail got input %s",
                                     ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), line));
                /* we need to discard the header, so check for it */
                if (0 == strncmp(line, "VNFS NAME", strlen("VNFS NAME"))) {
                    /* this is the header - ignore it */
                    OPAL_OUTPUT_VERBOSE((5, orcm_pvsn_base_framework.framework_output,
                                         "%s pvsn:wwulf:avail ignoring header",
                                         ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));
                    free(line);
                    continue;
                }
                /* break into three sections - the first contains the
                 * image name, the second the size, and the third the
                 * chroot location */
                ptr = line;
                if (NULL == (query = parse_next(line, &ptr))) {
                    /* not even an image name was given */
                    free(line);
                    continue;
                }
                res = OBJ_NEW(orcm_pvsn_resource_t);
                res->type = strdup("image");
                opal_list_append(available, &res->super);
                attr = OBJ_NEW(opal_value_t);
                attr->key = strdup("name");
                attr->type = OPAL_STRING;
                attr->data.string = strdup(query);
                opal_list_append(&res->attributes, &attr->super);
                if (NULL == (query = parse_next(ptr, &ptr))) {
                    /* should have been the size, but no other info
                     * was given - for now, don't worry about it */
                    free(line);
                    continue;
                }
                attr = OBJ_NEW(opal_value_t);
                attr->key = strdup("size");
                attr->type = OPAL_FLOAT;
                attr->data.fval = strtof(query, NULL);
                opal_list_append(&res->attributes, &attr->super);
                if (NULL == (query = parse_next(ptr, &ptr))) {
                    /* should have been the location, but no other info
                     * was given - for now, don't worry about it */
                    free(line);
                    continue;
                }
                attr = OBJ_NEW(opal_value_t);
                attr->key = strdup("location");
                attr->type = OPAL_STRING;
                attr->data.string = strdup(query);
                opal_list_append(&res->attributes, &attr->super);
                free(line);
            }
            pclose(fp);
        } else if (0 == strcasecmp(types[i], "files")) {
            OPAL_OUTPUT_VERBOSE((5, orcm_pvsn_base_framework.framework_output,
                                 "%s pvsn:wwulf:avail getting files list",
                                 ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));
            /* get the files list */
            (void)asprintf(&query, "%s file list", cmd);
            if (NULL == (fp = popen(query, "r"))) {
                OPAL_OUTPUT_VERBOSE((5, orcm_pvsn_base_framework.framework_output,
                                     "%s pvsn:wwulf:avail query for resource type %s failed",
                                     ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), types[i]));
                free(query);
                rc = ORTE_ERROR;
                break;
            }
            free(query);
            while (NULL != (line = orcm_getline(fp))) {
                OPAL_OUTPUT_VERBOSE((5, orcm_pvsn_base_framework.framework_output,
                                     "%s pvsn:wwulf:avail got input %s",
                                     ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), line));
                /* we want the following sections of the output line:
                 * 0  => ww file name
                 * 2  => permissions
                 * 4  => owner
                 * 5  => group
                 * 6  => size
                 * 7  => path
                 */
                ptr = line;
                j=0;
                while (NULL != (query = parse_next(ptr, &ptr))) {
                    switch(j) {
                    case 0:
                        attr = OBJ_NEW(opal_value_t);
                        attr->key = strdup("name");
                        attr->type = OPAL_STRING;
                        attr->data.string = strdup(query);
                        opal_list_append(&res->attributes, &attr->super);
                        break;
                    case 2:
                        attr = OBJ_NEW(opal_value_t);
                        attr->key = strdup("permissions");
                        attr->type = OPAL_STRING;
                        attr->data.string = strdup(query);
                        opal_list_append(&res->attributes, &attr->super);
                        break;
                    case 4:
                        attr = OBJ_NEW(opal_value_t);
                        attr->key = strdup("owner");
                        attr->type = OPAL_STRING;
                        attr->data.string = strdup(query);
                        opal_list_append(&res->attributes, &attr->super);
                        break;
                    case 5:
                        attr = OBJ_NEW(opal_value_t);
                        attr->key = strdup("group");
                        attr->type = OPAL_STRING;
                        attr->data.string = strdup(query);
                        opal_list_append(&res->attributes, &attr->super);
                        break;
                    case 6:
                        attr = OBJ_NEW(opal_value_t);
                        attr->key = strdup("size");
                        attr->type = OPAL_SIZE;
                        attr->data.size = (size_t)strtoul(query, NULL, 10);
                        opal_list_append(&res->attributes, &attr->super);
                        break;
                    case 7:
                        attr = OBJ_NEW(opal_value_t);
                        attr->key = strdup("path");
                        attr->type = OPAL_STRING;
                        attr->data.string = strdup(query);
                        opal_list_append(&res->attributes, &attr->super);
                        break;
                    default:
                        /* just ignore it */
                        break;
                    }
                    j++;
                }
                free(line);
            }
            pclose(fp);
        } else {
            orte_show_help("help-pvsn-ww.txt", "unknown-type", true, types[i]);
            rc = ORTE_ERR_BAD_PARAM;
            break;
        }
    }

    if (NULL != types) {
        opal_argv_free(types);
    }

    return rc;
}
示例#3
0
static void sample(orcm_sensor_sampler_t *sampler)
{
    float prob, division, check;
    char *vector, **elements, **parts, **pieces;
    orcm_ras_event_t *rev;
    int i, j;

    OPAL_OUTPUT_VERBOSE((1, orcm_sensor_base_framework.framework_output,
                         "%s sample:evinj considering injecting something",
                         ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));

     /* roll the dice */
    prob = (double)opal_rand(&mca_sensor_evinj_component.rng_buff) / (double)UINT32_MAX;
    if (prob < mca_sensor_evinj_component.prob) {
        rev = OBJ_NEW(orcm_ras_event_t);
        /* if we were given a vector file, read
         * the next vector from the file */
        if (NULL != fp) {
            vector = orcm_getline();
            if (NULL == vector) {
                /* reopen the file to start over */
                fclose(fp);
                fp = fopen(mca_sensor_evinj_component.vector_file, "r");
                if (NULL == fp) {
                    /* nothing we can do */
                    return;
                }
                vector = orcm_getline();
                if (NULL == vector) {
                    /* give up */
                    return;
                }
            }
            elements = opal_argv_split(vector, ';');
            free(vector);
            i=0;
            /* first field must contain a comma-delimited set of descriptors
             * of the location reporting this event, each descriptor given
             * as a colon-separated key:value pair (only string values are
             * supported when read from a file) */
            parts = opal_argv_split(elements[i], ',');
            for (j=0; NULL != parts[j]; j++) {
                pieces = opal_argv_split(parts[j], ':');
                if (2 != opal_argv_count(pieces)) {
                    ORTE_ERROR_LOG(ORCM_ERR_BAD_PARAM);
                    opal_argv_free(elements);
                    opal_argv_free(parts);
                    opal_argv_free(pieces);
                    OBJ_RELEASE(rev);
                    return;
                }
                ORCM_RAS_REPORTER(rev, pieces[0], pieces[1], OPAL_STRING);
                opal_argv_free(pieces);
            }
            opal_argv_free(parts);
            /* next field must be the event type */
            ++i;
            if (0 == strcmp("EXCEPTION", elements[i])) {
                rev->type = ORCM_RAS_EVENT_EXCEPTION;
            } else if (0 == strcmp("TRANSITION", elements[i])) {
                rev->type = ORCM_RAS_EVENT_STATE_TRANSITION;
            } else if (0 == strcmp("SENSOR", elements[i])) {
                rev->type = ORCM_RAS_EVENT_SENSOR;
            } else if (0 == strcmp("COUNTER", elements[i])) {
                rev->type = ORCM_RAS_EVENT_COUNTER;
            } else {
                ORTE_ERROR_LOG(ORCM_ERR_BAD_PARAM);
                opal_argv_free(elements);
                OBJ_RELEASE(rev);
                return;
            }
            /* next field must be the severity */
            ++i;
            if (0 == strcmp("EMERGENCY", elements[i])) {
                rev->severity = ORCM_RAS_EMERG;
            } else if (0 == strcmp("FATAL", elements[i])) {
                rev->severity = ORCM_RAS_FATAL;
            } else if (0 == strcmp("ALERT", elements[i])) {
                rev->severity = ORCM_RAS_ALERT;
            } else if (0 == strcmp("CRITICAL", elements[i])) {
                rev->severity = ORCM_RAS_CRIT;
            } else if (0 == strcmp("ERROR", elements[i])) {
                rev->severity = ORCM_RAS_ERROR;
            } else if (0 == strcmp("WARNING", elements[i])) {
                rev->severity = ORCM_RAS_WARNING;
            } else if (0 == strcmp("NOTICE", elements[i])) {
                rev->severity = ORCM_RAS_NOTICE;
            } else if (0 == strcmp("INFO", elements[i])) {
                rev->severity = ORCM_RAS_INFO;
            } else if (0 == strcmp("TRACE", elements[i])) {
                rev->severity = ORCM_RAS_TRACE;
            } else if (0 == strcmp("DEBUG", elements[i])) {
                rev->severity = ORCM_RAS_DEBUG;
            } else {
                ORTE_ERROR_LOG(ORCM_ERR_BAD_PARAM);
                opal_argv_free(elements);
                OBJ_RELEASE(rev);
                return;
            }
            /* next field is optional - if provided, it will consist
             * of a comma-delimited set of descriptors for this
             * event, each given as a colon-separated key:value pair
             * (only string values are supported when read from a file) */
            ++i;
            if (NULL == elements[i]) {
                /* we are done */
                opal_argv_free(elements);
                goto execute;
            }
            parts = opal_argv_split(elements[i], ',');
            for (j=0; NULL != parts[j]; j++) {
                pieces = opal_argv_split(parts[j], ':');
                if (2 != opal_argv_count(pieces)) {
                    ORTE_ERROR_LOG(ORCM_ERR_BAD_PARAM);
                    opal_argv_free(elements);
                    opal_argv_free(parts);
                    opal_argv_free(pieces);
                    OBJ_RELEASE(rev);
                    return;
                }
                ORCM_RAS_DESCRIPTION(rev, pieces[0], pieces[1], OPAL_STRING);
                opal_argv_free(pieces);
            }
            opal_argv_free(parts);
             /* the final field is also optional - if provided it
             * will consist of a comma-delimited set of data elements for this
             * event, each given as a colon-separated key:value pair
             * (only string values are supported when read from a file)*/
            ++i;
            if (NULL == elements[i]) {
                /* we are done */
                opal_argv_free(elements);
                goto execute;
            }
            parts = opal_argv_split(elements[i], ',');
            for (j=0; NULL != parts[j]; j++) {
                pieces = opal_argv_split(parts[j], ':');
                if (3 != opal_argv_count(pieces)) {
                    ORTE_ERROR_LOG(ORCM_ERR_BAD_PARAM);
                    opal_argv_free(elements);
                    opal_argv_free(parts);
                    opal_argv_free(pieces);
                    OBJ_RELEASE(rev);
                    return;
                }
                ORCM_RAS_DATA(rev, pieces[0], pieces[1], OPAL_STRING);
                opal_argv_free(pieces);
            }
            opal_argv_free(parts);
            opal_argv_free(elements);
        } else {
            /* just use some bogus location for test purposes */
            ORCM_RAS_REPORTER(rev, ORCM_LOC_CLUSTER, "GRAND-SLAM", OPAL_STRING);
            ORCM_RAS_REPORTER(rev, ORCM_LOC_ROW, "a", OPAL_STRING);
            i = 3;
            ORCM_RAS_REPORTER(rev, ORCM_LOC_RACK, &i, OPAL_INT);
            ORCM_RAS_REPORTER(rev, ORCM_LOC_NODE, "a305", OPAL_STRING);
            ORCM_RAS_REPORTER(rev, ORCM_COMPONENT_OVLYNET, ORCM_SUBCOMPONENT_PROC, OPAL_STRING);
            /* randomly generate the event type */
            prob = (double)opal_rand(&mca_sensor_evinj_component.rng_buff) / (double)UINT32_MAX;
            division = 1.0 / (float)(ORCM_RAS_EVENT_UNKNOWN_TYPE+1);
            rev->type = 0;
            for (check=division; check < prob; check += division) {
                ++rev->type;
            }
            /* randomly generate the severity */
            prob = (double)opal_rand(&mca_sensor_evinj_component.rng_buff) / (double)UINT32_MAX;
            division = 1.0 / (float)(ORCM_RAS_UNKNOWN+1);
            rev->severity = 0;
            for (check=division; check < prob; check += division) {
                ++rev->severity;
            }
            /* provide some description */
            check = 198.75;
            ORCM_RAS_DESCRIPTION(rev, ORCM_DESC_TEMP_HI, &check, OPAL_FLOAT);
            i = 13789;
            ORCM_RAS_DESCRIPTION(rev, ORCM_DESC_SESSION_ID, &i, OPAL_INT);
            /* provide some data */
            check = 134.8;
            ORCM_RAS_DATA(rev, "outlet avg temp", &check, OPAL_FLOAT);
        }

      execute:
        opal_output_verbose(1, orcm_sensor_base_framework.framework_output,
                             "%s sample:evinj injecting RAS event",
                             ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));

        /* inject it into the event generator thread */
        ORCM_RAS_EVENT(rev);
    }
}