示例#1
0
文件: ask_util.py 项目: mnms/share
def prefix_of_fdbp(save, default=None):
    logger.debug('ask flash db path')
    deploy_history = config.get_deploy_history()
    if not default:
        default = deploy_history['prefix_of_fdbp']
    q = 'Type prefix of {}'
    result = ask(q.format('flash_db_path'), default=default)
    if save:
        deploy_history['prefix_of_fdbp'] = result
        config.save_deploy_history(deploy_history)
    logger.info('OK, {}'.format(result))
    return result
示例#2
0
文件: ask_util.py 项目: mnms/share
def prefix_of_rd(save, default=None):
    logger.debug('ask redis data path')
    deploy_history = config.get_deploy_history()
    if not default:
        default = deploy_history['prefix_of_rd']
    q = 'Type prefix of {}'
    result = ask(q.format('redis_data'), default=default)
    if save:
        deploy_history['prefix_of_rd'] = result
        config.save_deploy_history(deploy_history)
    logger.info('OK, {}'.format(result))
    return result
示例#3
0
文件: ask_util.py 项目: mnms/share
def hosts(save, default=None):
    logger.debug('ask host')
    deploy_history = config.get_deploy_history()
    if not default:
        default = deploy_history['hosts']
    q = 'Please type host list separated by comma(,)'
    result = ask(q, default=', '.join(default))
    result = map(lambda x: x.strip(), result.split(','))
    if save:
        deploy_history['hosts'] = result
        config.save_deploy_history(deploy_history)
    logger.info('OK, {}'.format(result))
    return result
示例#4
0
文件: ask_util.py 项目: mnms/share
def ssd_count(save, default=None):
    logger.debug('ask ssd count')
    deploy_history = config.get_deploy_history()
    if not default:
        default = deploy_history['ssd_count']
    q = 'How many sdd would you like to use?'
    result = int(askInt(q, default=str(default)))
    if result <= 0:
        logger.warn("The number of ssd must be greater than 0. try again.")
        return ssd_count(save=save, default=default)
    if save:
        deploy_history['ssd_count'] = result
        config.save_deploy_history(deploy_history)
    logger.info('OK, {}'.format(result))
    return result
示例#5
0
文件: ask_util.py 项目: mnms/share
def replicas(save, default=None):
    logger.debug('ask replicas')
    deploy_history = config.get_deploy_history()
    if not default:
        default = deploy_history['replicas']
    q = 'How many replicas would you like to create on each master?'
    result = int(askInt(q, default=str(default)))
    if result < 0:
        msg = [
            'The number of master must be greater than or equal to 0.',
            'try again.',
        ]
        logger.error(' '.join(msg))
        return replicas(save, default=default)
    if save:
        deploy_history['replicas'] = result
        config.save_deploy_history(deploy_history)
    logger.info('OK, {}'.format(result))
    return result
示例#6
0
文件: ask_util.py 项目: mnms/share
def master_ports(save, cluster_id, default_count=None):
    logger.debug('ask master ports')
    deploy_history = config.get_deploy_history()
    if not default_count:
        default_count = deploy_history['master_count']
    q = 'How many masters would you like to create on each host?'
    m_count = int(askInt(q, default=str(default_count)))
    if m_count <= 0:
        logger.warn("The number of master must be greater than 0. try again.")
        return master_ports(cluster_id, default_count)
    logger.info('OK, {}'.format(m_count))
    if save:
        deploy_history['master_count'] = m_count
        config.save_deploy_history(deploy_history)

    start_m_ports = START_PORT + cluster_id * MASTER_OFFSET
    end_m_ports = start_m_ports + m_count - 1
    if start_m_ports == end_m_ports:
        default_m_ports = str(start_m_ports)
    else:
        default_m_ports = '{}-{}'.format(start_m_ports, end_m_ports)

    q = [
        'Please type ports separate with comma(,) ',
        'and use hyphen(-) for range.',
    ]
    while True:
        result = ask(''.join(q), default=default_m_ports)
        result = map(lambda x: x.strip(), result.split(','))
        valid = True
        m_ports = set()
        pattern = re.compile('[0-9]+-[0-9]+')
        for item in result:
            # range number
            matched = pattern.match(item)
            if matched:
                s, e = map(int, item.split('-'))
                if s > e:
                    logger.error('Invalid range: {}'.format(item))
                    valid = False
                    break
                m_ports.update(range(s, e + 1))
                continue
            # single number
            elif item.decode('utf-8').isdecimal():
                m_ports.add(int(item))
                continue
            else:
                logger.error('Invalid input: {}'.format(item))
                valid = False
                break
        if not valid:
            continue
        out_of_range = []
        for port in m_ports:
            if not port_range_safe(port):
                out_of_range.append(port)
        if out_of_range:
            msg = 'Use port between {} and {}: {}'.format(
                PORT_MININUM,
                PORT_MAXIMUM,
                out_of_range,
            )
            logger.error(msg)
            continue
        if valid and len(m_ports) != m_count:
            q2 = [
                "You type count '{}' at first, ".format(m_count),
                "but now count is '{}'. ".format(len(m_ports)), 'try again.'
            ]
            logger.error(''.join(q2))
            continue
        if valid:
            break
    m_ports = sorted(list(m_ports))
    logger.info('OK, {}'.format(result))
    return m_ports