mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-11-16 16:54:51 +02:00
Return what is supported by a compute node
Ref https://github.com/GNS3/gns3-gui/issues/1448
This commit is contained in:
parent
ffe6448534
commit
bbc1505274
@ -58,6 +58,14 @@ class BaseManager:
|
|||||||
self._port_manager = None
|
self._port_manager = None
|
||||||
self._config = Config.instance()
|
self._config = Config.instance()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def node_types(cls):
|
||||||
|
"""
|
||||||
|
:returns: Array of supported node type on this computer
|
||||||
|
"""
|
||||||
|
# By default we transform DockerVM => docker but you can override this (see builtins)
|
||||||
|
return [cls._NODE_CLASS.__name__.rstrip('VM').lower()]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nodes(self):
|
def nodes(self):
|
||||||
"""
|
"""
|
||||||
|
@ -34,3 +34,10 @@ class Builtin(BaseManager):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def node_types(cls):
|
||||||
|
"""
|
||||||
|
:returns: List of node type supported by this class and computer
|
||||||
|
"""
|
||||||
|
return ['cloud', 'nat', 'ethernet_hub', 'ethernet_switch']
|
||||||
|
@ -116,6 +116,13 @@ class Dynamips(BaseManager):
|
|||||||
self._dynamips_path = None
|
self._dynamips_path = None
|
||||||
self._dynamips_ids = {}
|
self._dynamips_ids = {}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def node_types(cls):
|
||||||
|
"""
|
||||||
|
:returns: List of node type supported by this class and computer
|
||||||
|
"""
|
||||||
|
return ['dynamips', 'frame_relay_switch', 'atm_switch']
|
||||||
|
|
||||||
def get_dynamips_id(self, project_id):
|
def get_dynamips_id(self, project_id):
|
||||||
"""
|
"""
|
||||||
:param project_id: UUID of the project
|
:param project_id: UUID of the project
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
import socket
|
||||||
import asyncio
|
import asyncio
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
@ -64,13 +65,14 @@ class Controller:
|
|||||||
log.info("Start controller")
|
log.info("Start controller")
|
||||||
yield from self.load()
|
yield from self.load()
|
||||||
server_config = Config.instance().get_section_config("Server")
|
server_config = Config.instance().get_section_config("Server")
|
||||||
self._computes["local"] = Compute(compute_id="local",
|
yield from self.add_compute(compute_id="local",
|
||||||
controller=self,
|
name=socket.gethostname(),
|
||||||
protocol=server_config.get("protocol", "http"),
|
protocol=server_config.get("protocol", "http"),
|
||||||
host=server_config.get("host", "localhost"),
|
host=server_config.get("host", "localhost"),
|
||||||
port=server_config.getint("port", 3080),
|
port=server_config.getint("port", 3080),
|
||||||
user=server_config.get("user", ""),
|
user=server_config.get("user", ""),
|
||||||
password=server_config.get("password", ""))
|
password=server_config.get("password", ""),
|
||||||
|
force=True)
|
||||||
yield from self.gns3vm.auto_start_vm()
|
yield from self.gns3vm.auto_start_vm()
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -228,8 +230,8 @@ class Controller:
|
|||||||
compute = Compute(compute_id=compute_id, controller=self, name=name, **kwargs)
|
compute = Compute(compute_id=compute_id, controller=self, name=name, **kwargs)
|
||||||
self._computes[compute.id] = compute
|
self._computes[compute.id] = compute
|
||||||
self.save()
|
self.save()
|
||||||
|
yield from compute.connect()
|
||||||
self.notification.emit("compute.created", compute.__json__())
|
self.notification.emit("compute.created", compute.__json__())
|
||||||
|
|
||||||
return compute
|
return compute
|
||||||
else:
|
else:
|
||||||
self.notification.emit("compute.updated", self._computes[compute_id].__json__())
|
self.notification.emit("compute.updated", self._computes[compute_id].__json__())
|
||||||
|
@ -90,9 +90,12 @@ class Compute:
|
|||||||
self._connected = False
|
self._connected = False
|
||||||
self._controller = controller
|
self._controller = controller
|
||||||
self._set_auth(user, password)
|
self._set_auth(user, password)
|
||||||
self._version = None
|
|
||||||
self._cpu_usage_percent = None
|
self._cpu_usage_percent = None
|
||||||
self._memory_usage_percent = None
|
self._memory_usage_percent = None
|
||||||
|
self._capabilities = {
|
||||||
|
"version": None,
|
||||||
|
"node_types": []
|
||||||
|
}
|
||||||
self.name = name
|
self.name = name
|
||||||
# Websocket for notifications
|
# Websocket for notifications
|
||||||
self._ws = None
|
self._ws = None
|
||||||
@ -155,13 +158,6 @@ class Compute:
|
|||||||
yield from self._ws.close()
|
yield from self._ws.close()
|
||||||
self._ws = None
|
self._ws = None
|
||||||
|
|
||||||
@property
|
|
||||||
def version(self):
|
|
||||||
"""
|
|
||||||
:returns: Version of compute node (string or None if not connected)
|
|
||||||
"""
|
|
||||||
return self._version
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""
|
"""
|
||||||
@ -173,8 +169,6 @@ class Compute:
|
|||||||
def name(self, name):
|
def name(self, name):
|
||||||
if name is not None:
|
if name is not None:
|
||||||
self._name = name
|
self._name = name
|
||||||
elif self._id == "local":
|
|
||||||
self._name = socket.gethostname()
|
|
||||||
else:
|
else:
|
||||||
if self._user:
|
if self._user:
|
||||||
user = self._user
|
user = self._user
|
||||||
@ -284,7 +278,8 @@ class Compute:
|
|||||||
"user": self._user,
|
"user": self._user,
|
||||||
"connected": self._connected,
|
"connected": self._connected,
|
||||||
"cpu_usage_percent": self._cpu_usage_percent,
|
"cpu_usage_percent": self._cpu_usage_percent,
|
||||||
"memory_usage_percent": self._memory_usage_percent
|
"memory_usage_percent": self._memory_usage_percent,
|
||||||
|
"capabilities": self._capabilities
|
||||||
}
|
}
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -336,24 +331,27 @@ class Compute:
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def http_query(self, method, path, data=None, **kwargs):
|
def http_query(self, method, path, data=None, **kwargs):
|
||||||
if not self._connected:
|
if not self._connected:
|
||||||
yield from self._connect()
|
yield from self.connect()
|
||||||
if not self._connected:
|
if not self._connected:
|
||||||
raise aiohttp.web.HTTPConflict(text="The server {} is not a GNS3 server".format(self._id))
|
raise aiohttp.web.HTTPConflict(text="The server {} is not a GNS3 server".format(self._id))
|
||||||
response = yield from self._run_http_query(method, path, data=data, **kwargs)
|
response = yield from self._run_http_query(method, path, data=data, **kwargs)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def _connect(self):
|
def connect(self):
|
||||||
"""
|
"""
|
||||||
Check if remote server is accessible
|
Check if remote server is accessible
|
||||||
"""
|
"""
|
||||||
if not self._connected:
|
if not self._connected:
|
||||||
response = yield from self._run_http_query("GET", "/version")
|
try:
|
||||||
|
response = yield from self._run_http_query("GET", "/capabilities")
|
||||||
|
except aiohttp.errors.ClientOSError:
|
||||||
|
return
|
||||||
|
|
||||||
if "version" not in response.json:
|
if "version" not in response.json:
|
||||||
self._http_session.close()
|
self._http_session.close()
|
||||||
raise aiohttp.web.HTTPConflict(text="The server {} is not a GNS3 server".format(self._id))
|
raise aiohttp.web.HTTPConflict(text="The server {} is not a GNS3 server".format(self._id))
|
||||||
self._version = response.json["version"]
|
self._capabilities = response.json
|
||||||
if parse_version(__version__)[:2] != parse_version(response.json["version"])[:2]:
|
if parse_version(__version__)[:2] != parse_version(response.json["version"])[:2]:
|
||||||
self._http_session.close()
|
self._http_session.close()
|
||||||
raise aiohttp.web.HTTPConflict(text="The server {} versions are not compatible {} != {}".format(self._id, __version__, response.json["version"]))
|
raise aiohttp.web.HTTPConflict(text="The server {} versions are not compatible {} != {}".format(self._id, __version__, response.json["version"]))
|
||||||
|
@ -136,7 +136,7 @@ class VMwareGNS3VM(BaseGNS3VM):
|
|||||||
raise GNS3VMError("No VMX path configured, can't stop the VM")
|
raise GNS3VMError("No VMX path configured, can't stop the VM")
|
||||||
try:
|
try:
|
||||||
yield from self._execute("stop", [self._vmx_path, "soft"])
|
yield from self._execute("stop", [self._vmx_path, "soft"])
|
||||||
except VMwareError as e:
|
except GNS3VMError as e:
|
||||||
log.warning("Error when stopping the VM: {}".format(str(e)))
|
log.warning("Error when stopping the VM: {}".format(str(e)))
|
||||||
log.info("GNS3 VM has been stopped")
|
log.info("GNS3 VM has been stopped")
|
||||||
self.running = False
|
self.running = False
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from .capabilities_handler import CapabilitiesHandler
|
||||||
from .network_handler import NetworkHandler
|
from .network_handler import NetworkHandler
|
||||||
from .project_handler import ProjectHandler
|
from .project_handler import ProjectHandler
|
||||||
from .dynamips_vm_handler import DynamipsVMHandler
|
from .dynamips_vm_handler import DynamipsVMHandler
|
||||||
|
40
gns3server/handlers/api/compute/capabilities_handler.py
Normal file
40
gns3server/handlers/api/compute/capabilities_handler.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2015 GNS3 Technologies Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from gns3server.web.route import Route
|
||||||
|
from gns3server.config import Config
|
||||||
|
from gns3server.schemas.capabilities import CAPABILITIES_SCHEMA
|
||||||
|
from gns3server.version import __version__
|
||||||
|
from gns3server.compute import MODULES
|
||||||
|
from aiohttp.web import HTTPConflict
|
||||||
|
|
||||||
|
|
||||||
|
class CapabilitiesHandler:
|
||||||
|
@Route.get(
|
||||||
|
r"/capabilities",
|
||||||
|
description="Retrieve the capabilities of the server",
|
||||||
|
output=CAPABILITIES_SCHEMA)
|
||||||
|
def get(request, response):
|
||||||
|
|
||||||
|
node_types = []
|
||||||
|
for module in MODULES:
|
||||||
|
node_types.extend(module.node_types())
|
||||||
|
|
||||||
|
response.json({
|
||||||
|
"version": __version__,
|
||||||
|
"node_types": node_types
|
||||||
|
})
|
37
gns3server/schemas/capabilities.py
Normal file
37
gns3server/schemas/capabilities.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2015 GNS3 Technologies Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from .node import NODE_TYPE_SCHEMA
|
||||||
|
|
||||||
|
|
||||||
|
CAPABILITIES_SCHEMA = {
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"description": "Get what a server support",
|
||||||
|
"type": "object",
|
||||||
|
"required": ["version", "node_types"],
|
||||||
|
"properties": {
|
||||||
|
"version": {
|
||||||
|
"description": "Version number",
|
||||||
|
"type": ["string", "null"],
|
||||||
|
},
|
||||||
|
"node_types": {
|
||||||
|
"type": "array",
|
||||||
|
"items": NODE_TYPE_SCHEMA
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties": False
|
||||||
|
}
|
@ -15,6 +15,7 @@
|
|||||||
# 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 .capabilities import CAPABILITIES_SCHEMA
|
||||||
|
|
||||||
COMPUTE_CREATE_SCHEMA = {
|
COMPUTE_CREATE_SCHEMA = {
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
@ -102,10 +103,7 @@ COMPUTE_OBJECT_SCHEMA = {
|
|||||||
"maximum": 100,
|
"maximum": 100,
|
||||||
"minimum": 0
|
"minimum": 0
|
||||||
},
|
},
|
||||||
"version": {
|
"capabilities": CAPABILITIES_SCHEMA
|
||||||
"description": "Version of the GNS3 remote compute server",
|
|
||||||
"type": ["string", "null"]
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"required": ["compute_id", "protocol", "host", "port", "name"]
|
"required": ["compute_id", "protocol", "host", "port", "name"]
|
||||||
|
@ -17,6 +17,25 @@
|
|||||||
|
|
||||||
from .label import LABEL_OBJECT_SCHEMA
|
from .label import LABEL_OBJECT_SCHEMA
|
||||||
|
|
||||||
|
NODE_TYPE_SCHEMA = {
|
||||||
|
"description": "Type of node",
|
||||||
|
"enum": [
|
||||||
|
"cloud",
|
||||||
|
"nat",
|
||||||
|
"ethernet_hub",
|
||||||
|
"ethernet_switch",
|
||||||
|
"frame_relay_switch",
|
||||||
|
"atm_switch",
|
||||||
|
"docker",
|
||||||
|
"dynamips",
|
||||||
|
"vpcs",
|
||||||
|
"virtualbox",
|
||||||
|
"vmware",
|
||||||
|
"iou",
|
||||||
|
"qemu"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
NODE_LIST_IMAGES_SCHEMA = {
|
NODE_LIST_IMAGES_SCHEMA = {
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"description": "List of binary images",
|
"description": "List of binary images",
|
||||||
@ -87,22 +106,7 @@ NODE_OBJECT_SCHEMA = {
|
|||||||
"maxLength": 36,
|
"maxLength": 36,
|
||||||
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
|
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
|
||||||
},
|
},
|
||||||
"node_type": {
|
"node_type": NODE_TYPE_SCHEMA,
|
||||||
"description": "Type of node",
|
|
||||||
"enum": ["cloud",
|
|
||||||
"nat",
|
|
||||||
"ethernet_hub",
|
|
||||||
"ethernet_switch",
|
|
||||||
"frame_relay_switch",
|
|
||||||
"atm_switch",
|
|
||||||
"docker",
|
|
||||||
"dynamips",
|
|
||||||
"vpcs",
|
|
||||||
"virtualbox",
|
|
||||||
"vmware",
|
|
||||||
"iou",
|
|
||||||
"qemu"]
|
|
||||||
},
|
|
||||||
"node_directory": {
|
"node_directory": {
|
||||||
"description": "Working directory of the node. Read only",
|
"description": "Working directory of the node. Read only",
|
||||||
"type": ["null", "string"]
|
"type": ["null", "string"]
|
||||||
|
@ -48,9 +48,6 @@ def test_host_ip(controller):
|
|||||||
def test_name():
|
def test_name():
|
||||||
c = Compute("my_compute_id", protocol="https", host="example.com", port=84, controller=MagicMock(), name=None)
|
c = Compute("my_compute_id", protocol="https", host="example.com", port=84, controller=MagicMock(), name=None)
|
||||||
assert c.name == "https://example.com:84"
|
assert c.name == "https://example.com:84"
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
|
||||||
c = Compute("local", protocol="https", host="example.com", port=84, controller=MagicMock(), name=None)
|
|
||||||
assert c.name == socket.gethostname()
|
|
||||||
c = Compute("world", protocol="https", host="example.com", port=84, controller=MagicMock(), name="hello")
|
c = Compute("world", protocol="https", host="example.com", port=84, controller=MagicMock(), name="hello")
|
||||||
assert c.name == "hello"
|
assert c.name == "hello"
|
||||||
c = Compute("world", protocol="https", host="example.com", port=84, controller=MagicMock(), user="azertyuiopqsdfghjklkm")
|
c = Compute("world", protocol="https", host="example.com", port=84, controller=MagicMock(), user="azertyuiopqsdfghjklkm")
|
||||||
@ -88,10 +85,10 @@ def test_compute_httpQueryNotConnected(compute, controller, async_run):
|
|||||||
response.status = 200
|
response.status = 200
|
||||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||||
async_run(compute.post("/projects", {"a": "b"}))
|
async_run(compute.post("/projects", {"a": "b"}))
|
||||||
mock.assert_any_call("GET", "https://example.com:84/v2/compute/version", headers={'content-type': 'application/json'}, data=None, auth=None, chunked=False)
|
mock.assert_any_call("GET", "https://example.com:84/v2/compute/capabilities", headers={'content-type': 'application/json'}, data=None, auth=None, chunked=False)
|
||||||
mock.assert_any_call("POST", "https://example.com:84/v2/compute/projects", data='{"a": "b"}', headers={'content-type': 'application/json'}, auth=None, chunked=False)
|
mock.assert_any_call("POST", "https://example.com:84/v2/compute/projects", data='{"a": "b"}', headers={'content-type': 'application/json'}, auth=None, chunked=False)
|
||||||
assert compute._connected
|
assert compute._connected
|
||||||
assert compute.version == __version__
|
assert compute._capabilities["version"] == __version__
|
||||||
controller.notification.emit.assert_called_with("compute.updated", compute.__json__())
|
controller.notification.emit.assert_called_with("compute.updated", compute.__json__())
|
||||||
|
|
||||||
|
|
||||||
@ -103,7 +100,7 @@ def test_compute_httpQueryNotConnectedInvalidVersion(compute, async_run):
|
|||||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||||
with pytest.raises(aiohttp.web.HTTPConflict):
|
with pytest.raises(aiohttp.web.HTTPConflict):
|
||||||
async_run(compute.post("/projects", {"a": "b"}))
|
async_run(compute.post("/projects", {"a": "b"}))
|
||||||
mock.assert_any_call("GET", "https://example.com:84/v2/compute/version", headers={'content-type': 'application/json'}, data=None, auth=None, chunked=False)
|
mock.assert_any_call("GET", "https://example.com:84/v2/compute/capabilities", headers={'content-type': 'application/json'}, data=None, auth=None, chunked=False)
|
||||||
|
|
||||||
|
|
||||||
def test_compute_httpQueryNotConnectedNonGNS3Server(compute, async_run):
|
def test_compute_httpQueryNotConnectedNonGNS3Server(compute, async_run):
|
||||||
@ -114,7 +111,7 @@ def test_compute_httpQueryNotConnectedNonGNS3Server(compute, async_run):
|
|||||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||||
with pytest.raises(aiohttp.web.HTTPConflict):
|
with pytest.raises(aiohttp.web.HTTPConflict):
|
||||||
async_run(compute.post("/projects", {"a": "b"}))
|
async_run(compute.post("/projects", {"a": "b"}))
|
||||||
mock.assert_any_call("GET", "https://example.com:84/v2/compute/version", headers={'content-type': 'application/json'}, data=None, auth=None, chunked=False)
|
mock.assert_any_call("GET", "https://example.com:84/v2/compute/capabilities", headers={'content-type': 'application/json'}, data=None, auth=None, chunked=False)
|
||||||
|
|
||||||
|
|
||||||
def test_compute_httpQueryNotConnectedNonGNS3Server2(compute, async_run):
|
def test_compute_httpQueryNotConnectedNonGNS3Server2(compute, async_run):
|
||||||
@ -125,7 +122,7 @@ def test_compute_httpQueryNotConnectedNonGNS3Server2(compute, async_run):
|
|||||||
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
with asyncio_patch("aiohttp.ClientSession.request", return_value=response) as mock:
|
||||||
with pytest.raises(aiohttp.web.HTTPConflict):
|
with pytest.raises(aiohttp.web.HTTPConflict):
|
||||||
async_run(compute.post("/projects", {"a": "b"}))
|
async_run(compute.post("/projects", {"a": "b"}))
|
||||||
mock.assert_any_call("GET", "https://example.com:84/v2/compute/version", headers={'content-type': 'application/json'}, data=None, auth=None, chunked=False)
|
mock.assert_any_call("GET", "https://example.com:84/v2/compute/capabilities", headers={'content-type': 'application/json'}, data=None, auth=None, chunked=False)
|
||||||
|
|
||||||
|
|
||||||
def test_compute_httpQueryError(compute, async_run):
|
def test_compute_httpQueryError(compute, async_run):
|
||||||
@ -234,7 +231,11 @@ def test_json(compute):
|
|||||||
"user": "test",
|
"user": "test",
|
||||||
"cpu_usage_percent": None,
|
"cpu_usage_percent": None,
|
||||||
"memory_usage_percent": None,
|
"memory_usage_percent": None,
|
||||||
"connected": True
|
"connected": True,
|
||||||
|
"capabilities": {
|
||||||
|
"version": None,
|
||||||
|
"node_types": []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
assert compute.__json__(topology_dump=True) == {
|
assert compute.__json__(topology_dump=True) == {
|
||||||
"compute_id": "my_compute_id",
|
"compute_id": "my_compute_id",
|
||||||
|
@ -71,7 +71,11 @@ def test_load(controller, controller_config_path, async_run):
|
|||||||
"user": "admin",
|
"user": "admin",
|
||||||
"name": "http://admin@localhost:8000",
|
"name": "http://admin@localhost:8000",
|
||||||
"cpu_usage_percent": None,
|
"cpu_usage_percent": None,
|
||||||
"memory_usage_percent": None
|
"memory_usage_percent": None,
|
||||||
|
"capabilities": {
|
||||||
|
"version": None,
|
||||||
|
"node_types": []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
assert controller.gns3vm.settings["vmname"] == "Test VM"
|
assert controller.gns3vm.settings["vmname"] == "Test VM"
|
||||||
|
|
||||||
@ -135,7 +139,7 @@ def test_isEnabled(controller):
|
|||||||
assert controller.is_enabled()
|
assert controller.is_enabled()
|
||||||
|
|
||||||
|
|
||||||
def test_addCompute(controller, controller_config_path, async_run):
|
def test_add_compute(controller, controller_config_path, async_run):
|
||||||
controller._notification = MagicMock()
|
controller._notification = MagicMock()
|
||||||
c = async_run(controller.add_compute(compute_id="test1"))
|
c = async_run(controller.add_compute(compute_id="test1"))
|
||||||
controller._notification.emit.assert_called_with("compute.created", c.__json__())
|
controller._notification.emit.assert_called_with("compute.created", c.__json__())
|
||||||
|
31
tests/handlers/api/compute/test_capabilities.py
Normal file
31
tests/handlers/api/compute/test_capabilities.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2015 GNS3 Technologies Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"""
|
||||||
|
This test suite check /version endpoint
|
||||||
|
It's also used for unittest the HTTP implementation.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from gns3server.config import Config
|
||||||
|
|
||||||
|
from gns3server.version import __version__
|
||||||
|
|
||||||
|
|
||||||
|
def test_get(http_compute):
|
||||||
|
response = http_compute.get('/capabilities', example=True)
|
||||||
|
assert response.status == 200
|
||||||
|
assert response.json == {'node_types': ['cloud', 'nat', 'ethernet_hub', 'ethernet_switch', 'vpcs', 'virtualbox', 'dynamips', 'frame_relay_switch', 'atm_switch', 'qemu', 'vmware', 'docker', 'iou'], 'version': __version__}
|
@ -23,7 +23,7 @@ def test_compute_create_without_id(http_controller, controller):
|
|||||||
|
|
||||||
params = {
|
params = {
|
||||||
"protocol": "http",
|
"protocol": "http",
|
||||||
"host": "example.com",
|
"host": "localhost",
|
||||||
"port": 84,
|
"port": 84,
|
||||||
"user": "julien",
|
"user": "julien",
|
||||||
"password": "secure"
|
"password": "secure"
|
||||||
@ -36,7 +36,7 @@ def test_compute_create_without_id(http_controller, controller):
|
|||||||
assert "password" not in response.json
|
assert "password" not in response.json
|
||||||
|
|
||||||
assert len(controller.computes) == 1
|
assert len(controller.computes) == 1
|
||||||
assert controller.computes[response.json["compute_id"]].host == "example.com"
|
assert controller.computes[response.json["compute_id"]].host == "localhost"
|
||||||
|
|
||||||
|
|
||||||
def test_compute_create_with_id(http_controller, controller):
|
def test_compute_create_with_id(http_controller, controller):
|
||||||
@ -44,7 +44,7 @@ def test_compute_create_with_id(http_controller, controller):
|
|||||||
params = {
|
params = {
|
||||||
"compute_id": "my_compute_id",
|
"compute_id": "my_compute_id",
|
||||||
"protocol": "http",
|
"protocol": "http",
|
||||||
"host": "example.com",
|
"host": "localhost",
|
||||||
"port": 84,
|
"port": 84,
|
||||||
"user": "julien",
|
"user": "julien",
|
||||||
"password": "secure"
|
"password": "secure"
|
||||||
@ -56,7 +56,7 @@ def test_compute_create_with_id(http_controller, controller):
|
|||||||
assert "password" not in response.json
|
assert "password" not in response.json
|
||||||
|
|
||||||
assert len(controller.computes) == 1
|
assert len(controller.computes) == 1
|
||||||
assert controller.computes["my_compute_id"].host == "example.com"
|
assert controller.computes["my_compute_id"].host == "localhost"
|
||||||
|
|
||||||
|
|
||||||
def test_compute_get(http_controller, controller):
|
def test_compute_get(http_controller, controller):
|
||||||
@ -64,7 +64,7 @@ def test_compute_get(http_controller, controller):
|
|||||||
params = {
|
params = {
|
||||||
"compute_id": "my_compute_id",
|
"compute_id": "my_compute_id",
|
||||||
"protocol": "http",
|
"protocol": "http",
|
||||||
"host": "example.com",
|
"host": "localhost",
|
||||||
"port": 84,
|
"port": 84,
|
||||||
"user": "julien",
|
"user": "julien",
|
||||||
"password": "secure"
|
"password": "secure"
|
||||||
@ -82,7 +82,7 @@ def test_compute_update(http_controller, controller):
|
|||||||
params = {
|
params = {
|
||||||
"compute_id": "my_compute_id",
|
"compute_id": "my_compute_id",
|
||||||
"protocol": "http",
|
"protocol": "http",
|
||||||
"host": "example.com",
|
"host": "localhost",
|
||||||
"port": 84,
|
"port": 84,
|
||||||
"user": "julien",
|
"user": "julien",
|
||||||
"password": "secure"
|
"password": "secure"
|
||||||
@ -106,7 +106,7 @@ def test_compute_list(http_controller, controller):
|
|||||||
params = {
|
params = {
|
||||||
"compute_id": "my_compute_id",
|
"compute_id": "my_compute_id",
|
||||||
"protocol": "http",
|
"protocol": "http",
|
||||||
"host": "example.com",
|
"host": "localhost",
|
||||||
"port": 84,
|
"port": 84,
|
||||||
"user": "julien",
|
"user": "julien",
|
||||||
"password": "secure",
|
"password": "secure",
|
||||||
@ -124,13 +124,17 @@ def test_compute_list(http_controller, controller):
|
|||||||
assert compute == {
|
assert compute == {
|
||||||
'compute_id': 'my_compute_id',
|
'compute_id': 'my_compute_id',
|
||||||
'connected': False,
|
'connected': False,
|
||||||
'host': 'example.com',
|
'host': 'localhost',
|
||||||
'port': 84,
|
'port': 84,
|
||||||
'protocol': 'http',
|
'protocol': 'http',
|
||||||
'user': 'julien',
|
'user': 'julien',
|
||||||
'name': 'My super server',
|
'name': 'My super server',
|
||||||
'cpu_usage_percent': None,
|
'cpu_usage_percent': None,
|
||||||
'memory_usage_percent': None
|
'memory_usage_percent': None,
|
||||||
|
'capabilities': {
|
||||||
|
'version': None,
|
||||||
|
'node_types': []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -139,7 +143,7 @@ def test_compute_delete(http_controller, controller):
|
|||||||
params = {
|
params = {
|
||||||
"compute_id": "my_compute_id",
|
"compute_id": "my_compute_id",
|
||||||
"protocol": "http",
|
"protocol": "http",
|
||||||
"host": "example.com",
|
"host": "localhost",
|
||||||
"port": 84,
|
"port": 84,
|
||||||
"user": "julien",
|
"user": "julien",
|
||||||
"password": "secure"
|
"password": "secure"
|
||||||
@ -162,7 +166,7 @@ def test_compute_list_images(http_controller, controller):
|
|||||||
params = {
|
params = {
|
||||||
"compute_id": "my_compute",
|
"compute_id": "my_compute",
|
||||||
"protocol": "http",
|
"protocol": "http",
|
||||||
"host": "example.com",
|
"host": "localhost",
|
||||||
"port": 84,
|
"port": 84,
|
||||||
"user": "julien",
|
"user": "julien",
|
||||||
"password": "secure"
|
"password": "secure"
|
||||||
@ -181,7 +185,7 @@ def test_compute_list_vms(http_controller, controller):
|
|||||||
params = {
|
params = {
|
||||||
"compute_id": "my_compute",
|
"compute_id": "my_compute",
|
||||||
"protocol": "http",
|
"protocol": "http",
|
||||||
"host": "example.com",
|
"host": "localhost",
|
||||||
"port": 84,
|
"port": 84,
|
||||||
"user": "julien",
|
"user": "julien",
|
||||||
"password": "secure"
|
"password": "secure"
|
||||||
@ -200,7 +204,7 @@ def test_compute_create_img(http_controller, controller):
|
|||||||
params = {
|
params = {
|
||||||
"compute_id": "my_compute",
|
"compute_id": "my_compute",
|
||||||
"protocol": "http",
|
"protocol": "http",
|
||||||
"host": "example.com",
|
"host": "localhost",
|
||||||
"port": 84,
|
"port": 84,
|
||||||
"user": "julien",
|
"user": "julien",
|
||||||
"password": "secure"
|
"password": "secure"
|
||||||
|
Loading…
Reference in New Issue
Block a user