mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 09:18:08 +00:00
Add endpoint to list the compute nodes
This commit is contained in:
parent
f5e5cf5059
commit
c8c61f2ae8
@ -48,14 +48,14 @@ class Controller:
|
||||
Save the controller configuration on disk
|
||||
"""
|
||||
data = {
|
||||
"computes": [ {
|
||||
"computes": [{
|
||||
"host": c.host,
|
||||
"port": c.port,
|
||||
"protocol": c.protocol,
|
||||
"user": c.user,
|
||||
"password": c.password,
|
||||
"compute_id": c.id
|
||||
} for c in self._computes.values() ],
|
||||
} for c in self._computes.values()],
|
||||
"version": __version__
|
||||
}
|
||||
os.makedirs(os.path.dirname(self._config_file), exist_ok=True)
|
||||
|
@ -48,6 +48,18 @@ class ComputeHandler:
|
||||
response.set_status(201)
|
||||
response.json(compute)
|
||||
|
||||
@classmethod
|
||||
@Route.get(
|
||||
r"/computes",
|
||||
description="List compute nodes",
|
||||
status_codes={
|
||||
200: "Compute list"
|
||||
})
|
||||
def list(request, response):
|
||||
|
||||
controller = Controller.instance()
|
||||
response.json([ c for c in controller.computes.values() ])
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/computes/shutdown",
|
||||
|
@ -82,6 +82,7 @@ def test_addCompute(controller, controller_config_path, async_run):
|
||||
async_run(controller.addCompute("test2"))
|
||||
assert len(controller.computes) == 2
|
||||
|
||||
|
||||
def test_addComputeConfigFile(controller, controller_config_path, async_run):
|
||||
async_run(controller.addCompute("test1"))
|
||||
assert len(controller.computes) == 1
|
||||
|
@ -34,3 +34,33 @@ def test_compute_create(http_controller, controller):
|
||||
|
||||
assert len(controller.computes) == 1
|
||||
assert controller.computes["my_compute_id"].host == "example.com"
|
||||
|
||||
|
||||
def test_compute_list(http_controller, controller):
|
||||
|
||||
params = {
|
||||
"compute_id": "my_compute_id",
|
||||
"protocol": "http",
|
||||
"host": "example.com",
|
||||
"port": 84,
|
||||
"user": "julien",
|
||||
"password": "secure"
|
||||
}
|
||||
response = http_controller.post("/computes", params)
|
||||
assert response.status == 201
|
||||
assert response.route == "/computes"
|
||||
assert response.json["user"] == "julien"
|
||||
assert "password" not in response.json
|
||||
|
||||
response = http_controller.get("/computes", example=True)
|
||||
assert response.json == [
|
||||
{
|
||||
'compute_id': 'my_compute_id',
|
||||
'connected': False,
|
||||
'host': 'example.com',
|
||||
'port': 84,
|
||||
'protocol': 'http',
|
||||
'user': 'julien'
|
||||
}
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user