mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Return what is supported by a compute node
Ref https://github.com/GNS3/gns3-gui/issues/1448
This commit is contained in:
15 files changed
+210
-68
No files matched your search
@@ -58,6 +58,14 @@ class BaseManager:
|
||||
self._port_manager = None
|
||||
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
|
||||
def nodes(self):
|
||||
"""
|
||||
|
||||
@@ -34,3 +34,10 @@ class Builtin(BaseManager):
|
||||
def __init__(self):
|
||||
|
||||
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_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):
|
||||
"""
|
||||
:param project_id: UUID of the project
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import socket
|
||||
import asyncio
|
||||
import aiohttp
|
||||
|
||||
@@ -64,13 +65,14 @@ class Controller:
|
||||
log.info("Start controller")
|
||||
yield from self.load()
|
||||
server_config = Config.instance().get_section_config("Server")
|
||||
self._computes["local"] = Compute(compute_id="local",
|
||||
controller=self,
|
||||
protocol=server_config.get("protocol", "http"),
|
||||
host=server_config.get("host", "localhost"),
|
||||
port=server_config.getint("port", 3080),
|
||||
user=server_config.get("user", ""),
|
||||
password=server_config.get("password", ""))
|
||||
yield from self.add_compute(compute_id="local",
|
||||
name=socket.gethostname(),
|
||||
protocol=server_config.get("protocol", "http"),
|
||||
host=server_config.get("host", "localhost"),
|
||||
port=server_config.getint("port", 3080),
|
||||
user=server_config.get("user", ""),
|
||||
password=server_config.get("password", ""),
|
||||
force=True)
|
||||
yield from self.gns3vm.auto_start_vm()
|
||||
|
||||
@asyncio.coroutine
|
||||
@@ -228,8 +230,8 @@ class Controller:
|
||||
compute = Compute(compute_id=compute_id, controller=self, name=name, **kwargs)
|
||||
self._computes[compute.id] = compute
|
||||
self.save()
|
||||
yield from compute.connect()
|
||||
self.notification.emit("compute.created", compute.__json__())
|
||||
|
||||
return compute
|
||||
else:
|
||||
self.notification.emit("compute.updated", self._computes[compute_id].__json__())
|
||||
|
||||
@@ -90,9 +90,12 @@ class Compute:
|
||||
self._connected = False
|
||||
self._controller = controller
|
||||
self._set_auth(user, password)
|
||||
self._version = None
|
||||
self._cpu_usage_percent = None
|
||||
self._memory_usage_percent = None
|
||||
self._capabilities = {
|
||||
"version": None,
|
||||
"node_types": []
|
||||
}
|
||||
self.name = name
|
||||
# Websocket for notifications
|
||||
self._ws = None
|
||||
@@ -155,13 +158,6 @@ class Compute:
|
||||
yield from self._ws.close()
|
||||
self._ws = None
|
||||
|
||||
@property
|
||||
def version(self):
|
||||
"""
|
||||
:returns: Version of compute node (string or None if not connected)
|
||||
"""
|
||||
return self._version
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""
|
||||
@@ -173,8 +169,6 @@ class Compute:
|
||||
def name(self, name):
|
||||
if name is not None:
|
||||
self._name = name
|
||||
elif self._id == "local":
|
||||
self._name = socket.gethostname()
|
||||
else:
|
||||
if self._user:
|
||||
user = self._user
|
||||
@@ -284,7 +278,8 @@ class Compute:
|
||||
"user": self._user,
|
||||
"connected": self._connected,
|
||||
"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
|
||||
@@ -336,24 +331,27 @@ class Compute:
|
||||
@asyncio.coroutine
|
||||
def http_query(self, method, path, data=None, **kwargs):
|
||||
if not self._connected:
|
||||
yield from self._connect()
|
||||
yield from self.connect()
|
||||
if not self._connected:
|
||||
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)
|
||||
return response
|
||||
|
||||
@asyncio.coroutine
|
||||
def _connect(self):
|
||||
def connect(self):
|
||||
"""
|
||||
Check if remote server is accessible
|
||||
"""
|
||||
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:
|
||||
self._http_session.close()
|
||||
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]:
|
||||
self._http_session.close()
|
||||
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")
|
||||
try:
|
||||
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.info("GNS3 VM has been stopped")
|
||||
self.running = False
|
||||
@@ -18,6 +18,7 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
from .capabilities_handler import CapabilitiesHandler
|
||||
from .network_handler import NetworkHandler
|
||||
from .project_handler import ProjectHandler
|
||||
from .dynamips_vm_handler import DynamipsVMHandler
|
||||
|
||||
@@ -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
|
||||
})
|
||||
@@ -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
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from .capabilities import CAPABILITIES_SCHEMA
|
||||
|
||||
COMPUTE_CREATE_SCHEMA = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
@@ -102,10 +103,7 @@ COMPUTE_OBJECT_SCHEMA = {
|
||||
"maximum": 100,
|
||||
"minimum": 0
|
||||
},
|
||||
"version": {
|
||||
"description": "Version of the GNS3 remote compute server",
|
||||
"type": ["string", "null"]
|
||||
}
|
||||
"capabilities": CAPABILITIES_SCHEMA
|
||||
},
|
||||
"additionalProperties": False,
|
||||
"required": ["compute_id", "protocol", "host", "port", "name"]
|
||||
|
||||
+20
-16
@@ -17,6 +17,25 @@
|
||||
|
||||
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 = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"description": "List of binary images",
|
||||
@@ -87,22 +106,7 @@ NODE_OBJECT_SCHEMA = {
|
||||
"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}$"
|
||||
},
|
||||
"node_type": {
|
||||
"description": "Type of node",
|
||||
"enum": ["cloud",
|
||||
"nat",
|
||||
"ethernet_hub",
|
||||
"ethernet_switch",
|
||||
"frame_relay_switch",
|
||||
"atm_switch",
|
||||
"docker",
|
||||
"dynamips",
|
||||
"vpcs",
|
||||
"virtualbox",
|
||||
"vmware",
|
||||
"iou",
|
||||
"qemu"]
|
||||
},
|
||||
"node_type": NODE_TYPE_SCHEMA,
|
||||
"node_directory": {
|
||||
"description": "Working directory of the node. Read only",
|
||||
"type": ["null", "string"]
|
||||
|
||||
Reference in new issue
Block a user