mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Update VPCS instance
This commit is contained in:
1 parent
7abb426d04
commit
368d1ff70b
13 files changed
+144
-29
No files matched your search
@@ -17,6 +17,7 @@
|
||||
|
||||
from ..web.route import Route
|
||||
from ..schemas.vpcs import VPCS_CREATE_SCHEMA
|
||||
from ..schemas.vpcs import VPCS_UPDATE_SCHEMA
|
||||
from ..schemas.vpcs import VPCS_OBJECT_SCHEMA
|
||||
from ..schemas.vpcs import VPCS_NIO_SCHEMA
|
||||
from ..modules.vpcs import VPCS
|
||||
@@ -67,6 +68,27 @@ class VPCSHandler:
|
||||
vm = vpcs_manager.get_vm(request.match_info["uuid"])
|
||||
response.json(vm)
|
||||
|
||||
@classmethod
|
||||
@Route.put(
|
||||
r"/vpcs/{uuid}",
|
||||
status_codes={
|
||||
200: "VPCS instance updated",
|
||||
409: "Conflict"
|
||||
},
|
||||
description="Update a VPCS instance",
|
||||
input=VPCS_UPDATE_SCHEMA,
|
||||
output=VPCS_OBJECT_SCHEMA)
|
||||
def update(request, response):
|
||||
|
||||
vpcs_manager = VPCS.instance()
|
||||
vm = vpcs_manager.get_vm(request.match_info["uuid"])
|
||||
vm.name = request.json.get("name", vm.name)
|
||||
vm.console = request.json.get("console", vm.console)
|
||||
vm.script_file = request.json.get("script_file", vm.script_file)
|
||||
vm.startup_script = request.json.get("startup_script", vm.startup_script)
|
||||
|
||||
response.json(vm)
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/vpcs/{uuid}/start",
|
||||
|
||||
@@ -59,6 +59,10 @@ class BaseVM:
|
||||
:param new_name: name
|
||||
"""
|
||||
|
||||
log.info("{module} {name} [{uuid}]: renamed to {new_name}".format(module=self.module_name,
|
||||
name=self._name,
|
||||
uuid=self.uuid,
|
||||
new_name=new_name))
|
||||
self._name = new_name
|
||||
|
||||
@property
|
||||
|
||||
@@ -123,7 +123,17 @@ class VPCSVM(BaseVM):
|
||||
|
||||
return self._console
|
||||
|
||||
# FIXME: correct way to subclass a property?
|
||||
@console.setter
|
||||
def console(self, console):
|
||||
"""
|
||||
Change console port
|
||||
|
||||
:params console: Console port (integer)
|
||||
"""
|
||||
if self._console:
|
||||
self._manager.port_manager.release_console_port(self._console)
|
||||
self._console = self._manager.port_manager.reserve_console_port(console)
|
||||
|
||||
@BaseVM.name.setter
|
||||
def name(self, new_name):
|
||||
"""
|
||||
@@ -133,22 +143,11 @@ class VPCSVM(BaseVM):
|
||||
"""
|
||||
|
||||
if self._script_file:
|
||||
# update the startup.vpc
|
||||
config_path = os.path.join(self.working_dir, "startup.vpc")
|
||||
if os.path.isfile(config_path):
|
||||
try:
|
||||
with open(config_path, "r+", errors="replace") as f:
|
||||
old_config = f.read()
|
||||
new_config = old_config.replace(self._name, new_name)
|
||||
f.seek(0)
|
||||
f.write(new_config)
|
||||
except OSError as e:
|
||||
raise VPCSError("Could not amend the configuration {}: {}".format(config_path, e))
|
||||
content = self.startup_script
|
||||
content = content.replace(self._name, new_name)
|
||||
self.startup_script = content
|
||||
|
||||
log.info("VPCS {name} [{uuid}]: renamed to {new_name}".format(name=self._name,
|
||||
uuid=self.uuid,
|
||||
new_name=new_name))
|
||||
BaseVM.name = new_name
|
||||
super(VPCSVM, VPCSVM).name.__set__(self, new_name)
|
||||
|
||||
@property
|
||||
def startup_script(self):
|
||||
@@ -173,7 +172,10 @@ class VPCSVM(BaseVM):
|
||||
self._script_file = os.path.join(self.working_dir, 'startup.vpcs')
|
||||
try:
|
||||
with open(self._script_file, '+w') as f:
|
||||
f.write(startup_script)
|
||||
if startup_script is None:
|
||||
f.write('')
|
||||
else:
|
||||
f.write(startup_script)
|
||||
except OSError as e:
|
||||
raise VPCSError("Can't write VPCS startup file '{}'".format(self._script_file))
|
||||
|
||||
|
||||
@@ -63,6 +63,33 @@ VPCS_CREATE_SCHEMA = {
|
||||
"required": ["name", "project_uuid"]
|
||||
}
|
||||
|
||||
VPCS_UPDATE_SCHEMA = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"description": "Request validation to update a VPCS instance",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"description": "VPCS device name",
|
||||
"type": ["string", "null"],
|
||||
"minLength": 1,
|
||||
},
|
||||
"console": {
|
||||
"description": "console TCP port",
|
||||
"minimum": 1,
|
||||
"maximum": 65535,
|
||||
"type": ["integer", "null"]
|
||||
},
|
||||
"script_file": {
|
||||
"description": "VPCS startup script",
|
||||
"type": ["string", "null"]
|
||||
},
|
||||
"startup_script": {
|
||||
"description": "Content of the VPCS startup script",
|
||||
"type": ["string", "null"]
|
||||
},
|
||||
},
|
||||
"additionalProperties": False,
|
||||
}
|
||||
|
||||
VPCS_NIO_SCHEMA = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
|
||||
Reference in new issue
Block a user