示例#1
0
def _get_stack_id(stack_name):
    url = str.format('http://{}/v2-beta/projects/{}/stacks', conf().RANCHER_ADDRESS, conf().PROJECT_ID)
    res = json_util.un_marshal(request_util.get(url))
    services = res.get('data')
    for service in services:
        if service.get('name') == stack_name:
            return service.get('id')
示例#2
0
def load_config(env):
    global config
    config_path = os.path.join(root.get_root(), str.format('config/config-{}.json', env))
    # 读取配置文件
    try:
        if not file_util.is_exist(config_path):
            logger.error('配置文件路径不存在')
            return
        config_str = file_util.read(config_path)
        # 将json字符串反序列化为dict类型
        con = json_util.un_marshal(config_str)
        set_config(con)
    except Exception as e:
        logger.error(e)
示例#3
0
def _set_docker_config(args_str, service_name, neighbors):
    args = json_util.un_marshal(args_str)
    peer_dir = os.path.join(conf().NODE_DIR, service_name)
    args['stackId'] = _get_stack_id(conf().STACK_NAME)
    args['name'] = service_name
    args['launchConfig']['hostname'] = service_name
    args['launchConfig']['dataVolumes'] = [str.format('/root/NFS500/test/{}/config:/tendermint/config', service_name)]
    args['launchConfig']['imageUuid'] = conf().IMAGE_ID
    p2p_str = ''
    if neighbors:
        p2p_str = '--p2p.persistent_peers=' + neighbors
    entry_point = ['sh', '-c', str.format('tendermint node {} --proxy_app=persistent_kvstore', p2p_str)]
    args['launchConfig']['entryPoint'] = entry_point
    print(args)
    return args
示例#4
0
def _get_genesis(path, target_ip, target_id):
    url = str.format('http://{}:{}/api/system/getGenesis', target_ip,
                     config.PORT)
    params = {'target_id': target_id}
    # logger.info(url)
    # 从远程服务获取genesis.json配置
    res = request_util.get(url=url, params=params)
    # logger.info('genesis data: ' + res)
    data = json_util.un_marshal(res)
    if data and data['flag']:
        # 写入文件中
        path = file_util.join(path, GENESIS_PATH)
        file_util.write_json(data['data'], path)
    else:
        raise Exception('获取genesis配置信息失败')
示例#5
0
def _update_genesis(old_name, new_name, genesis):
    # 节点目录为 数据根目录 加上 节点名称,  bak后缀为副本
    old_dir = os.path.join(conf().NODE_DIR, old_name + '-bak')
    new_dir = os.path.join(conf().NODE_DIR, new_name)

    genesis_path = os.path.join(old_dir, 'config/genesis.json')
    # 更新genesis.json文件
    if isinstance(genesis, str):
        genesis = json_util.un_marshal(genesis)
    file_util.write_json(genesis, genesis_path)

    # 移动本地目录到新目录
    file_util.move_dir(old_dir, new_dir)

    # 分发节点目录
    for ip in conf().MACHINE_IPS:
        _distribute_file(ip, new_dir, new_dir)
示例#6
0
def transfer_move_req(peer_id, chain_id):
    peer = config.get_peer_by_id(peer_id)
    if not peer:
        raise Exception('该节点不存在')
    if peer.chain_id == chain_id:
        raise Exception('该节点已属于该分片,无需调整')
    # 向该节点所在机器上的服务发送调整分片的请求
    data = {'peer_id': peer_id, 'chain_id': chain_id}
    url = str.format('http://{}:{}/api/system/doAdjust', peer.ip, config.PORT)
    try:
        # 转发请求
        res_str = request_util.post(url=url, data=data)
        res = json_util.un_marshal(res_str)
        if res['flag']:
            logger.info('调整分片操作执行成功')
        else:
            raise Exception('调整分片操作执行失败: ' + res.message)
    except Exception as e:
        raise e