예제 #1
0
async def agents_with_attrs(request: web.Request):
    user = await User.from_alchemy_obj(request["user"])
    account = await Account.from_alchemy_obj(request["user"].current_account)

    filters = request.query.copy()
    filters.pop("account_id", None)

    agents = await agents_service.get_agents(user, account, backend=mesos)
    filtered_agents = apply_attr_filter(filters, agents)

    stats = calculate_stats(filtered_agents)
    return web.json_response(
        AgentsResource(agents=filtered_agents, stats=stats).dict())
예제 #2
0
 def test_it_raises_a_validation_error_if_type_is_invalid(self):
     agents = [
         dict(
             type="XABLAU",
             id="id",
             hostname="hostname",
             active="active",
             version="version",
             port=8080,
             used_resources={"bla": "used_resources"},
             attributes={"data": "attributes"},
             resources={"data": "resources"},
         )
     ]
     with self.assertRaises(ValidationError):
         AgentsResource(agents=agents)
예제 #3
0
    def test_it_instantiates_a_agentsresource_using_agents_instances(self):
        agents = [
            MesosAgent(**dict(
                id="id",
                hostname="hostname",
                active="active",
                version="version",
                port=8080,
                used_resources={"bla": "used_resources"},
                attributes={"data": "attributes"},
                resources={"data": "resources"},
            ))
        ]
        resource = AgentsResource(agents=agents)

        self.assertIsInstance(resource, AgentsResource)
        for agent in resource.agents:
            self.assertIsInstance(agent, MesosAgent)
예제 #4
0
    def test_it_instantiates_a_agentsresource_if_type_is_valid(self):
        agents = [
            dict(
                type="MESOS",
                id="id",
                hostname="hostname",
                active="active",
                version="version",
                port=8080,
                used_resources={"bla": "used_resources"},
                attributes={"data": "attributes"},
                resources={"data": "resources"},
            )
        ]
        resource = AgentsResource(agents=agents)

        self.assertIsInstance(resource, AgentsResource)
        for agent in resource.agents:
            self.assertIsInstance(agent, MesosAgent)
예제 #5
0
async def agents_handler(request: web.Request):
    user = await User.from_alchemy_obj(request["user"])
    account = await Account.from_alchemy_obj(request["user"].current_account)
    agents = await agents_service.get_agents(user, account, mesos)
    stats = calculate_stats(agents)
    return web.json_response(AgentsResource(agents=agents, stats=stats).dict())