mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-21 05:43:12 +00:00
Expose /virtualbox/vms /vmwares/vms and /images via controller
Ref #1192, #537
This commit is contained in:
parent
fecd81655e
commit
917c1c7f84
@ -322,3 +322,11 @@ class Compute:
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def delete(self, path, **kwargs):
|
def delete(self, path, **kwargs):
|
||||||
return (yield from self.http_query("DELETE", path, **kwargs))
|
return (yield from self.http_query("DELETE", path, **kwargs))
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def forward(self, type, path):
|
||||||
|
"""
|
||||||
|
Forward a call to the emulator on compute
|
||||||
|
"""
|
||||||
|
res = yield from self.get("/{}/{}".format(type, path))
|
||||||
|
return res
|
||||||
|
@ -77,6 +77,38 @@ class ComputeHandler:
|
|||||||
response.set_status(200)
|
response.set_status(200)
|
||||||
response.json(compute)
|
response.json(compute)
|
||||||
|
|
||||||
|
@Route.get(
|
||||||
|
r"/computes/{compute_id:.+}/{emulator}/images",
|
||||||
|
parameters={
|
||||||
|
"compute_id": "Compute UUID"
|
||||||
|
},
|
||||||
|
status_codes={
|
||||||
|
200: "OK",
|
||||||
|
404: "Instance doesn't exist"
|
||||||
|
},
|
||||||
|
description="Get the list of images available on remote compute")
|
||||||
|
def list_images(request, response):
|
||||||
|
controller = Controller.instance()
|
||||||
|
compute = controller.get_compute(request.match_info["compute_id"])
|
||||||
|
images = yield from compute.forward(request.match_info["emulator"], "images")
|
||||||
|
response.json(images)
|
||||||
|
|
||||||
|
@Route.get(
|
||||||
|
r"/computes/{compute_id:.+}/{emulator}/vms",
|
||||||
|
parameters={
|
||||||
|
"compute_id": "Compute UUID"
|
||||||
|
},
|
||||||
|
status_codes={
|
||||||
|
200: "OK",
|
||||||
|
404: "Instance doesn't exist"
|
||||||
|
},
|
||||||
|
description="Get the list of vms available on remote compute for VMware an Virtualbox")
|
||||||
|
def list_vms(request, response):
|
||||||
|
controller = Controller.instance()
|
||||||
|
compute = controller.get_compute(request.match_info["compute_id"])
|
||||||
|
images = yield from compute.forward(request.match_info["emulator"], "vms")
|
||||||
|
response.json(images)
|
||||||
|
|
||||||
@Route.get(
|
@Route.get(
|
||||||
r"/computes/{compute_id:.+}",
|
r"/computes/{compute_id:.+}",
|
||||||
description="Get a compute server information",
|
description="Get a compute server information",
|
||||||
@ -93,7 +125,6 @@ class ComputeHandler:
|
|||||||
@Route.delete(
|
@Route.delete(
|
||||||
r"/computes/{compute_id:.+}",
|
r"/computes/{compute_id:.+}",
|
||||||
parameters={
|
parameters={
|
||||||
"project_id": "Project UUID",
|
|
||||||
"compute_id": "Compute UUID"
|
"compute_id": "Compute UUID"
|
||||||
},
|
},
|
||||||
status_codes={
|
status_codes={
|
||||||
|
@ -221,3 +221,11 @@ def test_update(compute, controller, async_run):
|
|||||||
assert compute.host == "example.org"
|
assert compute.host == "example.org"
|
||||||
controller.notification.emit.assert_called_with("compute.updated", compute.__json__())
|
controller.notification.emit.assert_called_with("compute.updated", compute.__json__())
|
||||||
assert compute.connected is False
|
assert compute.connected is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_forward(compute, async_run):
|
||||||
|
response = MagicMock()
|
||||||
|
response.status = 200
|
||||||
|
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||||
|
async_run(compute.forward("qemu", "images"))
|
||||||
|
mock.assert_called_with("GET", "https://example.com:84/v2/compute/qemu/images", auth=None, data=None, headers={'content-type': 'application/json'})
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from tests.utils import asyncio_patch
|
||||||
|
|
||||||
|
|
||||||
def test_compute_create_without_id(http_controller, controller):
|
def test_compute_create_without_id(http_controller, controller):
|
||||||
|
|
||||||
@ -56,7 +58,6 @@ def test_compute_create_with_id(http_controller, controller):
|
|||||||
assert controller.computes["my_compute_id"].host == "example.com"
|
assert controller.computes["my_compute_id"].host == "example.com"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_compute_get(http_controller, controller):
|
def test_compute_get(http_controller, controller):
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
@ -152,3 +153,41 @@ def test_compute_delete(http_controller, controller):
|
|||||||
|
|
||||||
response = http_controller.get("/computes")
|
response = http_controller.get("/computes")
|
||||||
assert len(response.json) == 0
|
assert len(response.json) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_compute_list_images(http_controller, controller):
|
||||||
|
|
||||||
|
params = {
|
||||||
|
"compute_id": "my_compute",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": "example.com",
|
||||||
|
"port": 84,
|
||||||
|
"user": "julien",
|
||||||
|
"password": "secure"
|
||||||
|
}
|
||||||
|
response = http_controller.post("/computes", params)
|
||||||
|
assert response.status == 201
|
||||||
|
|
||||||
|
with asyncio_patch("gns3server.controller.compute.Compute.forward", return_value=[]) as mock:
|
||||||
|
response = http_controller.get("/computes/my_compute/qemu/images")
|
||||||
|
assert response.json == []
|
||||||
|
mock.assert_called_with("qemu", "images")
|
||||||
|
|
||||||
|
|
||||||
|
def test_compute_list_vms(http_controller, controller):
|
||||||
|
|
||||||
|
params = {
|
||||||
|
"compute_id": "my_compute",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": "example.com",
|
||||||
|
"port": 84,
|
||||||
|
"user": "julien",
|
||||||
|
"password": "secure"
|
||||||
|
}
|
||||||
|
response = http_controller.post("/computes", params)
|
||||||
|
assert response.status == 201
|
||||||
|
|
||||||
|
with asyncio_patch("gns3server.controller.compute.Compute.forward", return_value=[]) as mock:
|
||||||
|
response = http_controller.get("/computes/my_compute/virtualbox/vms")
|
||||||
|
assert response.json == []
|
||||||
|
mock.assert_called_with("virtualbox", "vms")
|
||||||
|
Loading…
Reference in New Issue
Block a user