Exemplo n.º 1
0
    def test_get_id(self):
        l = [
            {"id": 1, "unused": 2},
            {"id": 3, "unused": 4},
        ]

        self.assertEqual(itemgetters("id")(l), [1, 3])
Exemplo n.º 2
0
def GetJobs(r):
    """
    Gets all jobs for the cluster.

    @rtype: list of int
    @return: job ids for the cluster
    """

    jobs = r.request("get", "/2/jobs")
    return r.applier(itemgetters("id"), jobs)
Exemplo n.º 3
0
def GetInstances(r, bulk=False):
    """
    Gets information about instances on the cluster.

    @type bulk: bool
    @param bulk: whether to return all information about all instances

    @rtype: list of dict or list of str
    @return: if bulk is True, info about the instances, else a list of instances
    """

    if bulk:
        return r.request("get", "/2/instances", query={"bulk": 1})
    else:
        instances = r.request("get", "/2/instances")
        return r.applier(itemgetters("id"), instances)
Exemplo n.º 4
0
def GetNodes(r, bulk=False):
    """
    Gets all nodes in the cluster.

    @type bulk: bool
    @param bulk: whether to return all information about all instances

    @rtype: list of dict or str
    @return: if bulk is true, info about nodes in the cluster,
            else list of nodes in the cluster
    """

    if bulk:
        return r.request("get", "/2/nodes", query={"bulk": 1})
    else:
        nodes = r.request("get", "/2/nodes")
        return r.applier(itemgetters("id"), nodes)
Exemplo n.º 5
0
def GetGroups(r, bulk=False):
    """
    Gets all node groups in the cluster.

    @type bulk: bool
    @param bulk: whether to return all information about the groups

    @rtype: list of dict or str
    @return: if bulk is true, a list of dictionaries with info about all node
            groups in the cluster, else a list of names of those node groups
    """

    if bulk:
        return r.request("get", "/2/groups", query={"bulk": 1})
    else:
        groups = r.request("get", "/2/groups")
        return r.applier(itemgetters("name"), groups)