Exemple #1
0
int main(int argc, char** argv) {
    int success, failed;
    success = failed = 0;
    if(argc < 2) {
        fprintf(stderr, "Requires 1 argument: config file absolute path\n");
        exit(1);
    }

    //get log params
    int current_level, roll_out;
    long bytes_out;
    log_params_get(&current_level, &roll_out, &bytes_out);
    log_params_set(log_level_int("TRACE"), roll_out, bytes_out);

    if(test_sensor_registration() != EUCA_OK) {
        LOGERROR("Failed sensor registration test\n");
        failed++;
    } else {
        LOGINFO("Sensor registration check passed\n");
        success++;
    }

    char *config_path = argv[1];
    if(test_stats_run(config_path) != EUCA_OK) {
        LOGERROR("Failed init stats test\n");
        failed++;
    } else {
        LOGINFO("Init stats test passed\n");
        success++;
    }

    LOGINFO("Results: %d passed, %d failed\n", success, failed);
        
    return failed;
}
Exemple #2
0
int main (int argc, char **argv)
{
    log_params_set (EUCAWARN, 0, 0); // set log level
    log_prefix_set ("L "); // only print log level
    log_file_set (NULL); // log output goes to STANDARD_FILESTREAM

    char * component = NULL;
    int opt;
    while ((opt = getopt (argc, argv, "c:")) != -1) {
        switch (opt) {
        case 'c':
            component = optarg;
            break;
        case 'h':
        default:
            usage (argv[0]);
            return 1;
        }
    }

    if (argv[optind]==NULL) {
        logprintfl (EUCAERROR, "no fault ID is specified (try -h for usage)\n");
        return 1;
    }
    int ndigits = 0;
    for (char * c = argv[optind]; * c != '\0'; c++, ndigits++) {
        if ( ! isdigit (* c)) {
            logprintfl (EUCAERROR, "invalid fault ID (must be a number)\n");
            return 1;
        }
    }
    if (ndigits < 4) {
        logprintfl (EUCAERROR, "invalid fault ID (must be a 4-digit number)\n");
        return 1;
    }
    int nfaults = init_eucafaults (component);
    if (nfaults < 1) {
        logprintfl (EUCAERROR, "failed to locate fault information (is $EUCALYPTUS set?)\n");
        return 1;
    }

    // place variable-and-value pairs from command line into the map
    char_map ** m = NULL;
    for (int opt = optind + 1; opt < argc; opt++) {
        logprintfl (EUCADEBUG, "argv[opt]: %s\n", argv[opt]);
        if ((opt - optind + 1) % 2) {
            logprintfl (EUCADEBUG, "...now have two, calling c_varmap_alloc()\n");
            m = c_varmap_alloc (m, argv[opt - 1], argv[opt]);
        }
    }

    int ret = 0;
    if (log_eucafault_map (argv[optind], (const char_map **)m) == FALSE) {
        ret = 1;
    }
    if (m)
        c_varmap_free (m);
    
    return ret;
}
//!
//! Main entry point of the application
//!
//! @param[in] argc the number of parameter passed on the command line
//! @param[in] argv the list of arguments
//!
//! @return Always return 0 or exit(1) on failure
//!
int main(int argc, char **argv)
{
    char *sc_hostport = NULL;
    char *command = NULL;
    char *ip = NULL;
    char *instance_id = NULL;
    char *iqn = NULL;
    int ch = 0;

    log_file_set(NULL, NULL);
    log_params_set(EUCA_LOG_ALL, 0, 1);

    while ((ch = getopt(argc, argv, "hn:h:s:i:")) != -1) {
        switch (ch) {
        case 's':
            sc_hostport = optarg;
            break;
        case 'i':
            instance_id = optarg;
            break;
        case 'h':
            usage();                   // will exit
            break;
        case '?':
        default:
            fprintf(stderr, "ERROR: unknown parameter (try -h)\n");
            exit(1);
        }
    }
    argc -= optind;
    argv += optind;

    if (argc > 0) {
        command = argv[0];
        if (argc > 1) {
            fprintf(stderr, "WARNING: too many parameters (%d), using first one as command\n", argc);
            for (int i = 0; i <= argc; i++) {
                if (argv[i])
                    fprintf(stderr, "%d = %s\n", i, argv[i]);
            }
        }
    } else {
        fprintf(stderr, "ERROR: command not specified (try -h)\n");
        exit(1);
    }

    char configFile[BUFSIZE], policyFile[BUFSIZE];
    char *euca_home;
    char sc_url[BUFSIZE];

    euca_home = getenv("EUCALYPTUS");
    if (!euca_home) {
        euca_home = "";
    }

    snprintf(configFile, BUFSIZE, EUCALYPTUS_CONF_LOCATION, euca_home);
    snprintf(policyFile, BUFSIZE, EUCALYPTUS_POLICIES_DIR "/sc-client-policy.xml", euca_home);
    snprintf(sc_url, BUFSIZE, "http://%s/services/Storage", sc_hostport);

    char *instances_path;
    int rc;

    rc = get_conf_var(configFile, INSTANCE_PATH, &instances_path);

    char *instance_path = find_instance_path(instances_path, instance_id);
    eucaVolume volumes[EUCA_MAX_VOLUMES];
    char instance_xml[BUFSIZE];
    snprintf(instance_xml, BUFSIZE, "%s/instance.xml", instance_path);

    loop_through_volumes(instance_xml, volumes);

    ip = find_ip_addr();
    iqn = find_local_iqn();

    printf("Found local iqn=%s and local ip=%s\n", iqn, ip);

    for(int i = 0; i < EUCA_MAX_VOLUMES; i++){
        if(strlen(volumes[i].state) == 0 || strcmp(volumes[i].state, VOL_STATE_ATTACHED)) continue;

        printf("Performing operation on volume %d\nid=%s\ntoken=%s\ndevice=%s\nconnectionstring=%s\nbus=%s\nserial=%s\n", 
               i, volumes[i].id, volumes[i].attachment_token, volumes[i].device, volumes[i].connection_string, volumes[i].bus, volumes[i].serial);
        /***********************************************************/
        if (!strcmp(command, "ConnectVolumes")) {
            CHECK_PARAM(ip, "ip");
            CHECK_PARAM(iqn, "iqn");
            CHECK_PARAM(sc_hostport, "sc host and port");

            setup_iscsi(euca_home, configFile);
            euca_init_cert();

            char *libvirt_xml = NULL;
            ebs_volume_data *vol_data = NULL;

            if (connect_ebs_volume(volumes[i].id, volumes[i].serial, volumes[i].bus, sc_url, volumes[i].attachment_token, 1, policyFile, ip, iqn, &libvirt_xml, &vol_data) != EUCA_OK) {
                fprintf(stderr, "Error connecting ebs volume %s\n", volumes[i].id);
                exit(1);
            }

            /***********************************************************/
        } else if (!strcmp(command, "DisconnectVolumes")) {
            CHECK_PARAM(ip, "ip");
            CHECK_PARAM(iqn, "iqn");
            CHECK_PARAM(sc_hostport, "sc host and port");

            setup_iscsi(euca_home, configFile);
            euca_init_cert();

            if (disconnect_ebs_volume(sc_url, 1, policyFile, volumes[i].attachment_token, volumes[i].connection_string, ip, iqn) != EUCA_OK) {
                fprintf(stderr, "Error disconnecting ebs volume %s.\n", volumes[i].id);
                exit(1);
            }

            /***********************************************************/
        } else {
            fprintf(stderr, "ERROR: command %s unknown (try -h)\n", command);
            exit(1);
        }
    }

    _exit(0);
}
Exemple #4
0
//!
//! Set the log file, log level and log roll number
//!
//! @param[in] file the log file name string
//! @param[in] log_level_in the log level to set
//! @param[in] log_roll_number_in the log rolling number to set
//!
//! @return the result of the log_file_set() call.
//!
//! @see log_file_set()
//! @see log_params_set()
//!
//! @pre The given values must be valid.
//!
//! @post The values are set and log_max_size_bytes will be set to MAXLOGFILESIZE
//!
//! @todo legacy function, to be removed when no longer in use
//!
int logfile(const char *file, int log_level_in, int log_roll_number_in)
{
    log_params_set(log_level_in, log_roll_number_in, MAXLOGFILESIZE);
    return log_file_set(file);
}
Exemple #5
0
int logfile(char *file, int log_level_in, int log_roll_number_in) // TODO: legacy function, to be removed when no longer in use
{
    log_params_set (log_level_in, log_roll_number_in, 0);
    return log_file_set (file);
}