示例#1
0
def get_servers(server_id, role_name, cluster_id):
    if server_id:
        servers = server.ServerModel.find_by_model_id(*server_id)
        if not isinstance(servers, list):
            servers = [servers]

        return servers

    if not cluster_id:
        items = server.ServerModel.list_models({
            "all": True,
            "filter": {},
            "sort_by": []
        })
        return items.response_all()["items"]

    clusters = cluster.ClusterModel.find_by_model_id(*cluster_id)
    server_ids = set()
    for clstr in clusters:
        if not role_name:
            server_ids |= clstr.configuration.all_server_ids
        else:
            server_ids |= {
                data["server_id"]
                for data in clstr.configuration.state
                if data["role"] in role_name
            }

    servers = []
    for itm in server.ServerModel.collection().find({"_id": list(server_ids)}):
        model = server.ServerModel()
        model.update_from_db_document(itm)
        server.append(servers)

    return servers
示例#2
0
def get_all(output_format):
    """List locked servers"""

    servers = []
    cursor = server.ServerModel.collection().find(
        {
            "lock": {
                "$ne": None
            },
            "is_latest": True
        },
        sort=[("model_id", generic.SORT_ASC)])
    for doc in cursor:
        model = server.ServerModel()
        model.update_from_db_document(doc)
        servers.append(model)

    servers = [{
        "id": srv.model_id,
        "lock_id": srv.lock,
        "cluster_id": srv.cluster_id
    } for srv in servers]

    if output_format == "json":
        click.echo(utils.json_dumps(servers))
    else:
        writer = csv.DictWriter(sys.stdout, ["id", "cluster_id", "lock_id"])
        writer.writeheader()
        writer.writerows(servers)
示例#3
0
def test_set_state_ok(state):
    model = server.ServerModel()

    model.state = state
    assert model.state == state
示例#4
0
def test_set_state_fail(state):
    model = server.ServerModel()

    with pytest.raises(ValueError):
        model.state = state