示例#1
0
def deploy(runlist, uuid, profile, user):
    import itertools
    s = storage

    is_undeploy = (request.endpoint == 'undeploy')

    #read manifest
    manifest = s.read_manifest(uuid)
    if manifest is None:
        return 'Manifest for app %s doesn\'t exists' % uuid, 400

    # read runlists
    runlist_dict = s.read_runlist(runlist, {})

    hosts = s.read_hosts()
    if not hosts:
        return 'No hosts are available', 400

    post_body = request.stream.read()
    if post_body and not is_undeploy:
        s.write_profile(profile, json.loads(post_body))
    else:
        if s.read_profile(profile) is None:
            return 'Profile name is not valid', 400

    # update runlists
    if is_undeploy:
        if uuid not in runlist_dict:
            return '%s app is not deployed' % uuid, 400
        del runlist_dict[uuid]
    else:
        runlist_dict[uuid] = profile

    #manifest update
    if is_undeploy:
        manifest.pop('runlist', None)
    else:
        manifest['runlist'] = runlist

    print hosts
    if is_undeploy:
        res = send_json_rpc(1, [[uuid]], itertools.chain(*hosts.values()))
    else:
        res = send_json_rpc(0, [{uuid: profile}], itertools.chain(*hosts.values()))

    logger.debug("JSON RPC Response: %s" % res)
    for host, host_res in res.items():
        if not host_res:
            return 'Cocaine RPC on %s didn\'t process call' % host, 500
        for app_uuid, res in host_res.items():
            if 'error' in res:
                return "%s - %s" % (app_uuid, res['error']), 500
            logger.debug("Deploy: %s. %s", app_uuid, res)

    s.write_runlist(runlist, runlist_dict)
    s.write_manifest(uuid, manifest)

    return 'ok'
示例#2
0
def host_stats(alias, host, user):
    result_info =  send_json_rpc(2, [], set([host,]))
    res = result_info.get(host)
    if res is not None:
        return jsonify(res)
    else:
        return 'None'
示例#3
0
def stats(user):
    import itertools
    hosts = storage.read_hosts()
    if not hosts:
        return render_template('stats.html', user=user, hosts={})
    hosts = send_json_rpc(2, [], set(itertools.chain(*hosts.values())))
    return render_template('stats.html', user=user, hosts=hosts)
示例#4
0
def stop_app(uuid):
    res = send_json_rpc(1, [[uuid]], storage.read_hosts())
    return process_json_rpc_response(res, uuid)
示例#5
0
def start_app(uuid, profile):
    res = send_json_rpc(0, [{uuid: profile}], storage.read_hosts())
    return process_json_rpc_response(res, uuid)