mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Add method to delete and update computes
This commit is contained in:
7 files changed
+143
-5
No files matched your search
@@ -117,6 +117,16 @@ class Controller:
|
||||
self.notification.emit("compute.updated", self._computes[compute_id].__json__())
|
||||
return self._computes[compute_id]
|
||||
|
||||
@asyncio.coroutine
|
||||
def delete_compute(self, compute_id):
|
||||
"""
|
||||
Delete a compute node
|
||||
:param compute_id: Compute server identifier
|
||||
"""
|
||||
compute = self.get_compute(compute_id)
|
||||
del self._computes[compute_id]
|
||||
self.notification.emit("compute.deleted", compute.__json__())
|
||||
|
||||
@property
|
||||
def notification(self):
|
||||
"""
|
||||
|
||||
@@ -42,9 +42,9 @@ class Compute:
|
||||
assert controller is not None
|
||||
log.info("Create compute %s", compute_id)
|
||||
self._id = compute_id
|
||||
self._protocol = protocol
|
||||
self._host = host
|
||||
self._port = port
|
||||
self.protocol = protocol
|
||||
self.host = host
|
||||
self.port = port
|
||||
self._user = None
|
||||
self._password = None
|
||||
self._connected = False
|
||||
@@ -73,6 +73,15 @@ class Compute:
|
||||
else:
|
||||
self._auth = None
|
||||
|
||||
@asyncio.coroutine
|
||||
def update(self, **kwargs):
|
||||
for kw in kwargs:
|
||||
setattr(self, kw, kwargs[kw])
|
||||
if self._session:
|
||||
self._session.close()
|
||||
self._connected = False
|
||||
self._controller.notification.emit("compute.updated", self.__json__())
|
||||
|
||||
@property
|
||||
def version(self):
|
||||
"""
|
||||
@@ -117,6 +126,10 @@ class Compute:
|
||||
"""
|
||||
return self._host
|
||||
|
||||
@host.setter
|
||||
def host(self, host):
|
||||
self._host = host
|
||||
|
||||
@property
|
||||
def port(self):
|
||||
"""
|
||||
@@ -124,6 +137,10 @@ class Compute:
|
||||
"""
|
||||
return self._port
|
||||
|
||||
@port.setter
|
||||
def port(self, port):
|
||||
self._port = port
|
||||
|
||||
@property
|
||||
def protocol(self):
|
||||
"""
|
||||
@@ -131,6 +148,10 @@ class Compute:
|
||||
"""
|
||||
return self._protocol
|
||||
|
||||
@protocol.setter
|
||||
def protocol(self, protocol):
|
||||
self._protocol = protocol
|
||||
|
||||
@property
|
||||
def user(self):
|
||||
return self._user
|
||||
|
||||
@@ -21,7 +21,7 @@ from aiohttp.web import HTTPForbidden
|
||||
from gns3server.web.route import Route
|
||||
from gns3server.config import Config
|
||||
from gns3server.compute.project_manager import ProjectManager
|
||||
from gns3server.schemas.compute import COMPUTE_CREATE_SCHEMA, COMPUTE_OBJECT_SCHEMA
|
||||
from gns3server.schemas.compute import COMPUTE_CREATE_SCHEMA, COMPUTE_OBJECT_SCHEMA, COMPUTE_UPDATE_SCHEMA
|
||||
from gns3server.controller import Controller
|
||||
|
||||
import logging
|
||||
@@ -92,6 +92,26 @@ class ComputeHandler:
|
||||
asyncio.async(server.shutdown_server())
|
||||
response.set_status(201)
|
||||
|
||||
@Route.put(
|
||||
r"/computes/{compute_id:.+}",
|
||||
description="Get a compute server information",
|
||||
status_codes={
|
||||
200: "Compute server updated",
|
||||
400: "Invalid request",
|
||||
404: "Instance doesn't exist"
|
||||
},
|
||||
input=COMPUTE_UPDATE_SCHEMA,
|
||||
output=COMPUTE_OBJECT_SCHEMA)
|
||||
def update(request, response):
|
||||
|
||||
controller = Controller.instance()
|
||||
compute = controller.get_compute(request.match_info["compute_id"])
|
||||
|
||||
# Ignore these because we only use them when creating a node
|
||||
request.json.pop("compute_id", None)
|
||||
yield from compute.update(**request.json)
|
||||
response.set_status(200)
|
||||
response.json(compute)
|
||||
|
||||
@Route.get(
|
||||
r"/computes/{compute_id:.+}",
|
||||
@@ -105,3 +125,20 @@ class ComputeHandler:
|
||||
controller = Controller.instance()
|
||||
compute = controller.get_compute(request.match_info["compute_id"])
|
||||
response.json(compute)
|
||||
|
||||
@Route.delete(
|
||||
r"/computes/{compute_id:.+}",
|
||||
parameters={
|
||||
"project_id": "Project UUID",
|
||||
"compute_id": "Compute UUID"
|
||||
},
|
||||
status_codes={
|
||||
204: "Instance deleted",
|
||||
400: "Invalid request",
|
||||
404: "Instance doesn't exist"
|
||||
},
|
||||
description="Delete a compute instance")
|
||||
def delete(request, response):
|
||||
controller = Controller.instance()
|
||||
yield from controller.delete_compute(request.match_info["compute_id"])
|
||||
response.set_status(204)
|
||||
@@ -54,6 +54,8 @@ COMPUTE_CREATE_SCHEMA = {
|
||||
"required": ["compute_id", "protocol", "host", "port"]
|
||||
}
|
||||
|
||||
COMPUTE_UPDATE_SCHEMA = COMPUTE_CREATE_SCHEMA
|
||||
|
||||
COMPUTE_OBJECT_SCHEMA = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"description": "Request validation to a GNS3 compute object instance",
|
||||
@@ -93,5 +95,5 @@ COMPUTE_OBJECT_SCHEMA = {
|
||||
}
|
||||
},
|
||||
"additionalProperties": False,
|
||||
"required": ["compute_id", "protocol", "host", "port", "name"]
|
||||
"required": ["compute_id", "protocol", "host", "port", "name", "connected"]
|
||||
}
|
||||
Reference in new issue
Block a user