Beispiel #1
0
int node_config(int argc, char *argv[], NodeConfig *c, NodeSysConfig *s)
{
    int ret;

    if (c == NULL)
        return NODE_CONFIG_RET_ERR_UNKNOWN; /* internal error */

    /* initialize NodeConfig with undefined values */
    bzero(c, sizeof(NodeConfig));
    c->auto_connect = UNKNOWN;
    c->verbose = UNDEFINED_CFG_INT;
    c->daemon = UNDEFINED_CFG_INT;
    c->debug = UNDEFINED_CFG_INT;
    c->driver = HYPERVISOR_IS_KVM;

    /* parse command line options */
    ret = __parse_opt(argc, argv, c);
    if (ret)
        return ret; /* to exit program */

    /* check conf_path before reading it */
    if (c->conf_path == NULL) {
        c->conf_path = strdup(DEFAULT_LYNODE_CONF_PATH);
        if (c->conf_path == NULL)
            return NODE_CONFIG_RET_ERR_NOMEM;
    }
    
    /* parse config file */
    if (access(c->conf_path, R_OK) == 0) {
        ret = __parse_config(c);
        if (ret && ret != NODE_CONFIG_RET_ERR_NOCONF)
            return ret; /* to exit programe */
    }

    /* set default values for auto_connect */
    if (c->auto_connect == UNKNOWN)
        c->auto_connect = ALWAYS;

    /* read sysconf settings */
    bzero(s, sizeof(NodeSysConfig));
    s->node_tag = -1;
    if (c->sysconf_path == NULL) {
        c->sysconf_path = strdup(DEFAULT_LYNODE_SYSCONF_PATH);
        if (c->conf_path == NULL)
            return NODE_CONFIG_RET_ERR_NOMEM;
    }
    if (access(c->sysconf_path, W_OK) != 0) {
        if (lyutil_create_file(c->sysconf_path, 0) < 0) {
            logsimple(_("not able to write to %s\n"), c->sysconf_path);
            return NODE_CONFIG_RET_ERR_CMD;
        }
    }
    else {
        ret = __parse_sysconf(c->sysconf_path, s);
        if (ret)
           return ret; /* to exit program */
    }

    /* read xml template */
    if (c->vm_template_path) {
        c->vm_xml = file2str(c->vm_template_path, LIBVIRT_XML_MAX);
        if (c->vm_xml == NULL) {
            logsimple(_("error while reading %s\n"), c->vm_template_path);
            return NODE_CONFIG_RET_ERR_CMD;
        }
    }
    if (c->vm_template_net_nat_path) {
        c->vm_xml_net_nat = file2str(c->vm_template_net_nat_path, LIBVIRT_XML_MAX);
        if (c->vm_xml_net_nat == NULL) {
            logsimple(_("error while reading %s\n"), c->vm_template_net_nat_path);
            return NODE_CONFIG_RET_ERR_CMD;
        }
    }
    if (c->vm_template_net_br_path) {
        c->vm_xml_net_br = file2str(c->vm_template_net_br_path, LIBVIRT_XML_MAX);
        if (c->vm_xml_net_br == NULL) {
            logsimple(_("error while reading %s\n"), c->vm_template_net_br_path);
            return NODE_CONFIG_RET_ERR_CMD;
        }
    }
    if (c->vm_template_disk_path) {
        c->vm_xml_disk = file2str(c->vm_template_disk_path, LIBVIRT_XML_MAX);
        if (c->vm_xml_disk == NULL) {
            logsimple(_("error while reading %s\n"), c->vm_template_disk_path);
            return NODE_CONFIG_RET_ERR_CMD;
        }
    }


    /* set default values for unconfigured settings */
    if (c->verbose == UNDEFINED_CFG_INT)
        c->verbose = 0;
    if (c->daemon == UNDEFINED_CFG_INT)
        c->daemon = 1;
    if (c->debug == UNDEFINED_CFG_INT)
        c->debug = 0;
    if (c->clc_port == 0)
        c->clc_port = DEFAULT_LYCLC_PORT;
    if (c->clc_mcast_ip == NULL)
        c->clc_mcast_ip = strdup(DEFAULT_LYCLC_MCAST_IP);
    if (c->clc_mcast_port == 0)
        c->clc_mcast_port = DEFAULT_LYCLC_MCAST_PORT;
    if (c->log_path == NULL) {
        c->log_path = strdup(DEFAULT_LYNODE_LOG_PATH);
        if (c->log_path == NULL)
            return NODE_CONFIG_RET_ERR_NOMEM;
    }
    if (c->pid_path == NULL) {
        c->pid_path = strdup(DEFAULT_LYNODE_PID_PATH);
        if (c->pid_path == NULL)
            return NODE_CONFIG_RET_ERR_NOMEM;
    }
    if (c->osm_conf_path == NULL) {
        c->osm_conf_path = strdup(DEFAULT_LYOSM_CONF_PATH);
        if (c->osm_conf_path == NULL)
            return NODE_CONFIG_RET_ERR_NOMEM;
    }
    if (c->osm_key_path == NULL) {
        c->osm_key_path = strdup(DEFAULT_LYOSM_KEY_PATH);
        if (c->osm_key_path == NULL)
            return NODE_CONFIG_RET_ERR_NOMEM;
    }
    if (c->node_data_dir == NULL) {
        c->node_data_dir = strdup(DEFAULT_LYNODE_DATA_DIR);
        if (c->node_data_dir == NULL)
            return NODE_CONFIG_RET_ERR_NOMEM;
    }
    if (c->net_primary == NULL) {
        c->net_primary = strdup(LUOYUN_INSTANCE_NET_DEFAULT);
        if (c->net_primary == NULL)
            return NODE_CONFIG_RET_ERR_NOMEM;
    }

    /* create necessary sub-directories for normal operation */
    int len = strlen(c->node_data_dir); 
    c->app_data_dir = malloc(len + 15);
    c->ins_data_dir = malloc(len + 15);
    c->trash_data_dir = malloc(len + 15);
    if (c->app_data_dir == NULL || c->ins_data_dir == NULL)
        return NODE_CONFIG_RET_ERR_NOMEM;
    sprintf(c->app_data_dir, "%s/appliances", c->node_data_dir);
    if (lyutil_create_dir(c->app_data_dir) != 0) {
        logsimple(_("failed creating directory of %s\n"), c->app_data_dir);
        return NODE_CONFIG_RET_ERR_CMD;
    }
    if (__clean_lockfile(c->app_data_dir) != 0) {
        logsimple(_("failed cleaning directory of %s\n"), c->app_data_dir);
        return NODE_CONFIG_RET_ERR_CMD;
    }
    sprintf(c->ins_data_dir, "%s/instances", c->node_data_dir);
    if (lyutil_create_dir(c->ins_data_dir) != 0) {
        logsimple(_("failed creating directory of %s\n"), c->ins_data_dir);
        return NODE_CONFIG_RET_ERR_CMD;
    }
    if (__clean_lockfile(c->ins_data_dir) != 0) {
        logsimple(_("failed cleaning directory of %s\n"), c->ins_data_dir);
        return NODE_CONFIG_RET_ERR_CMD;
    }
    sprintf(c->trash_data_dir, "%s/trash", c->node_data_dir);
    if (lyutil_create_dir(c->trash_data_dir) != 0) {
        logsimple(_("failed creating directory of %s\n"), c->trash_data_dir);
        return NODE_CONFIG_RET_ERR_CMD;
    }

    /* simple configuration validity checking */
    if (__is_IP_valid(c->clc_mcast_ip, 1) == 0) {
        logsimple(_("cloud controller mcast ip is invalid\n"));
        return NODE_CONFIG_RET_ERR_CONF;
    }
    if (__is_port_valid(c->clc_mcast_port) == 0 ) {
        logsimple(_("cloud controller port is invalid\n"));
        return NODE_CONFIG_RET_ERR_CONF;
    }
    if (__is_port_valid(c->clc_port) == 0 ) {
        logsimple(_("cloud controller port is invalid\n"));
        return NODE_CONFIG_RET_ERR_CONF;
    }
    if ((c->auto_connect == DISABLE || c->clc_ip)
        && __is_IP_valid(c->clc_ip, 0) == 0) {
        logsimple(_("cloud controller ip is invalid<%s>\n"), c->clc_ip);
        return NODE_CONFIG_RET_ERR_CONF;
    }
    if (c->log_path) {
        if (access(c->log_path, F_OK) && lyutil_create_file(c->log_path, 0) < 0) {
            logsimple(_("not able to create %s\n"), c->log_path);
            return NODE_CONFIG_RET_ERR_CMD;
        }
        if (access(c->log_path, W_OK)) {
            logsimple(_("not able to write to %s\n"), c->log_path);
            return NODE_CONFIG_RET_ERR_CMD;
        }
    }
    return ret;
}
Beispiel #2
0
int clc_config(int argc, char *argv[], CLCConfig * c)
{
    int ret;

    if (c == NULL)
        return CLC_CONFIG_RET_ERR_UNKNOWN;      /* internal error */

    /* initialize CLCConfig with undefined values */
    bzero(c, sizeof(CLCConfig));
    c->verbose = UNDEFINED_CFG_INT;
    c->daemon = UNDEFINED_CFG_INT;
    c->debug = UNDEFINED_CFG_INT;
    c->conf_path = NULL;
    c->web_conf_path = NULL;
    c->log_path = NULL;
    c->pid_path = NULL;
    c->db_name = NULL;
    c->db_user = NULL;
    c->db_pass = NULL;

    /* parse command line options */
    ret = __parse_opt(argc, argv, c);
    if (ret)
        return ret;             /* to exit program */

    /* check conf_path before reading it */
    if (c->conf_path == NULL) {
        c->conf_path = strdup(DEFAULT_LYCLC_CONF_PATH);
        if (c->conf_path == NULL)
            return CLC_CONFIG_RET_ERR_NOMEM;
    }
    //else if (file_not_exist(c->conf_path))
    //    return CLC_CONFIG_RET_ERR_ERRCONF;

    /* read web config file first */
    if (c->web_conf_path && access(c->web_conf_path, R_OK) == 0) {
        ret = __parse_web_config(c);
        if (ret && ret != CLC_CONFIG_RET_ERR_NOCONF)
            return ret; /* to exit programe */
        if (strcmp(c->clc_ip, "127.0.0.1") == 0) {
            free(c->clc_ip);
            c->clc_ip = NULL;
        }
    }

    /* parse config file */
    if (access(c->conf_path, R_OK) == 0) {
        ret = __parse_config(c);
        if (ret && ret != CLC_CONFIG_RET_ERR_NOCONF)
            return ret; /* to exit programe */
    }

    /* set default values for unconfigured settings */
    if (c->verbose == UNDEFINED_CFG_INT)
        c->verbose = 0;
    if (c->daemon == UNDEFINED_CFG_INT)
        c->daemon = 1;
    if (c->debug == UNDEFINED_CFG_INT)
        c->debug = 0;
    if (c->clc_port == 0)
        c->clc_port = DEFAULT_LYCLC_PORT;
    if (c->clc_mcast_ip == NULL) {
        c->clc_mcast_ip = strdup(DEFAULT_LYCLC_MCAST_IP);
        if (c->clc_mcast_ip == NULL)
            return CLC_CONFIG_RET_ERR_NOMEM;
    }
    if (c->clc_mcast_port == 0)
        c->clc_mcast_port = DEFAULT_LYCLC_MCAST_PORT;
    if (c->clc_data_dir == NULL) {
        c->clc_data_dir = strdup(DEFAULT_LYCLC_DATA_DIR);
        if (c->clc_data_dir == NULL)
            return CLC_CONFIG_RET_ERR_NOMEM;
    }
    if (c->log_path == NULL) {
        c->log_path = strdup(DEFAULT_LYCLC_LOG_PATH);
        if (c->log_path == NULL)
            return CLC_CONFIG_RET_ERR_NOMEM;
    }
    if (c->pid_path == NULL) {
        c->pid_path = strdup(DEFAULT_LYCLC_PID_PATH);
        if (c->pid_path == NULL)
            return CLC_CONFIG_RET_ERR_NOMEM;
    }
    if (c->db_name == NULL) {
        c->db_name = strdup(DEFAULT_LYCLC_DB_NAME);
        if (c->db_name == NULL)
            return CLC_CONFIG_RET_ERR_NOMEM;
    }
    if (c->db_user == NULL) {
        c->db_user = strdup(DEFAULT_LYCLC_DB_USER);
        if (c->db_user == NULL)
            return CLC_CONFIG_RET_ERR_NOMEM;
    }
    if (c->db_pass == NULL) {
        c->db_pass = strdup(DEFAULT_LYCLC_DB_PASS);
        if (c->db_pass == NULL)
            return CLC_CONFIG_RET_ERR_NOMEM;
    }
    if (c->node_storage_low == 0)
        c->node_storage_low = DEFAULT_NODE_STORAGE_LOW;
    if (c->node_select < NODE_SELECT_ANY || 
        c->node_select > NODE_SELECT_LAST_ONLY)
        c->node_select = NODE_SELECT_LAST_ONLY;
    if (c->job_timeout_instance  == 0)
        c->job_timeout_instance = DEFAULT_JOB_TIMOUT_INSTANCE;
    if (c->job_timeout_node == 0)
        c->job_timeout_node = DEFAULT_JOB_TIMOUT_NODE;
    if (c->job_timeout_other == 0)
        c->job_timeout_other = DEFAULT_JOB_TIMOUT_OTHER;
 
    /* simple configuration validity checking */
    if (c->vm_name_prefix && strlen(c->vm_name_prefix) > 10) {
        logsimple(_("VM name prefix is too long, must not be > 10\n"));
        return CLC_CONFIG_RET_ERR_CONF;
    }
        
    if (__is_IP_valid(c->clc_mcast_ip, 1) == 0) {
        logsimple(_("cloud controller mcast ip is invalid\n"));
        return CLC_CONFIG_RET_ERR_CONF;
    }
    if (__is_port_valid(c->clc_mcast_port) == 0) {
        logsimple(_("cloud controller port is invalid\n"));
        return CLC_CONFIG_RET_ERR_CONF;
    }
    if (__is_port_valid(c->clc_port) == 0) {
        logsimple(_("cloud controller port is invalid\n"));
        return CLC_CONFIG_RET_ERR_CONF;
    }
    if (c->clc_ip && __is_IP_valid(c->clc_ip, 0) == 0) {
        logsimple(_("cloud controller ip is invalid\n"));
        return CLC_CONFIG_RET_ERR_CONF;
    }
    if (c->log_path) {
        if (access(c->log_path, F_OK) && lyutil_create_file(c->log_path, 0) < 0) {
            logsimple(_("not able to create %s\n"), c->log_path);
            return CLC_CONFIG_RET_ERR_CMD;
        }
        if (access(c->log_path, W_OK)) {
            logsimple(_("not able to write to %s\n"), c->log_path);
            return CLC_CONFIG_RET_ERR_CMD;
        }
    }

    return ret;
}
Beispiel #3
0
int clc_config(int argc, char *argv[], CLCConfig * c)
{
    int ret;

    if (c == NULL)
        return CLC_CONFIG_RET_ERR_UNKNOWN;      /* internal error */

    /* initialize CLCConfig with undefined values */
    bzero(c, sizeof(CLCConfig));
    c->verbose = UNDEFINED_CFG_INT;
    c->daemon = UNDEFINED_CFG_INT;
    c->debug = UNDEFINED_CFG_INT;
    c->conf_path = NULL;
    c->log_path = NULL;
    c->pid_path = NULL;
    c->db_name = NULL;
    c->db_user = NULL;
    c->db_pass = NULL;

    /* parse command line options */
    ret = __parse_opt(argc, argv, c);
    if (ret)
        return ret;             /* to exit program */

    /* check conf_path before reading it */
    if (c->conf_path == NULL) {
        c->conf_path = strdup(DEFAULT_LYCLC_CONF_PATH);
        if (c->conf_path == NULL)
            return CLC_CONFIG_RET_ERR_NOMEM;
    }
    //else if (file_not_exist(c->conf_path))
    //    return CLC_CONFIG_RET_ERR_ERRCONF;

    /* parse config file */
    if (access(c->conf_path, R_OK) == 0) {
        ret = __parse_config(c);
        if (ret && ret != CLC_CONFIG_RET_ERR_NOCONF)
            return ret; /* to exit programe */
    }

    /* set default values for unconfigured settings */
    if (c->verbose == UNDEFINED_CFG_INT)
        c->verbose = 0;
    if (c->daemon == UNDEFINED_CFG_INT)
        c->daemon = 1;
    if (c->debug == UNDEFINED_CFG_INT)
        c->debug = 0;
    if (c->clc_port == 0)
        c->clc_port = DEFAULT_LYCLC_PORT;
    if (c->clc_mcast_ip == NULL) {
        c->clc_mcast_ip = strdup(DEFAULT_LYCLC_MCAST_IP);
        if (c->clc_mcast_ip == NULL)
            return CLC_CONFIG_RET_ERR_NOMEM;
    }
    if (c->clc_mcast_port == 0)
        c->clc_mcast_port = DEFAULT_LYCLC_MCAST_PORT;
    if (c->clc_data_dir == NULL) {
        c->clc_data_dir = strdup(DEFAULT_LYCLC_DATA_DIR);
        if (c->clc_data_dir == NULL)
            return CLC_CONFIG_RET_ERR_NOMEM;
    }
    if (c->log_path == NULL) {
        c->log_path = strdup(DEFAULT_LYCLC_LOG_PATH);
        if (c->log_path == NULL)
            return CLC_CONFIG_RET_ERR_NOMEM;
    }
    if (c->pid_path == NULL) {
        c->pid_path = strdup(DEFAULT_LYCLC_PID_PATH);
        if (c->pid_path == NULL)
            return CLC_CONFIG_RET_ERR_NOMEM;
    }
    if (c->db_name == NULL) {
        c->db_name = strdup(DEFAULT_LYCLC_DB_NAME);
        if (c->db_name == NULL)
            return CLC_CONFIG_RET_ERR_NOMEM;
    }
    if (c->db_user == NULL) {
        c->db_user = strdup(DEFAULT_LYCLC_DB_USER);
        if (c->db_user == NULL)
            return CLC_CONFIG_RET_ERR_NOMEM;
    }
    if (c->db_pass == NULL) {
        c->db_pass = strdup(DEFAULT_LYCLC_DB_PASS);
        if (c->db_pass == NULL)
            return CLC_CONFIG_RET_ERR_NOMEM;
    }

    /* simple configuration validity checking */
    if (__is_IP_valid(c->clc_mcast_ip, 1) == 0) {
        logsimple(_("cloud controller mcast ip is invalid\n"));
        return CLC_CONFIG_RET_ERR_CONF;
    }
    if (__is_port_valid(c->clc_mcast_port) == 0) {
        logsimple(_("cloud controller port is invalid\n"));
        return CLC_CONFIG_RET_ERR_CONF;
    }
    if (__is_port_valid(c->clc_port) == 0) {
        logsimple(_("cloud controller port is invalid\n"));
        return CLC_CONFIG_RET_ERR_CONF;
    }
    if (c->clc_ip && __is_IP_valid(c->clc_ip, 0) == 0) {
        logsimple(_("cloud controller ip is invalid\n"));
        return CLC_CONFIG_RET_ERR_CONF;
    }
    if (c->log_path) {
        if (access(c->log_path, F_OK) && lyutil_create_file(c->log_path, 0) < 0) {
            logsimple(_("not able to create %s\n"), c->log_path);
            return CLC_CONFIG_RET_ERR_CMD;
        }
        if (access(c->log_path, W_OK)) {
            logsimple(_("not able to write to %s\n"), c->log_path);
            return CLC_CONFIG_RET_ERR_CMD;
        }
    }

    return ret;
}