mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Create VPCS VM on controller
This commit is contained in:
13 files changed
+76
-34
No files matched your search
@@ -90,9 +90,9 @@ class Hypervisor:
|
||||
data = data.__json__()
|
||||
data = json.dumps(data)
|
||||
response = yield from session.request(method, url, headers=headers, data=data)
|
||||
print(response.status)
|
||||
assert response.status < 300
|
||||
body = yield from response.read()
|
||||
if response.status >= 300:
|
||||
raise aiohttp.errors.HttpProcessingError(code=response.status, message=body)
|
||||
yield from response.release()
|
||||
return body
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ import uuid
|
||||
|
||||
|
||||
class VM:
|
||||
def __init__(self, project, hypervisor, vm_id=None, vm_type=None, name=None, console=None, console_type="telnet", **kwargs):
|
||||
|
||||
def __init__(self, project, hypervisor, vm_id=None, vm_type=None, name=None, console=None, console_type="telnet", properties={}):
|
||||
"""
|
||||
:param project: Project of the VM
|
||||
:param hypervisor: Hypervisor server where the server will run
|
||||
@@ -30,7 +31,7 @@ class VM:
|
||||
:param name: Name of the vm
|
||||
:param console: TCP port of the console
|
||||
:param console_type: Type of the console (telnet, vnc, serial..)
|
||||
:param kwargs: Emulator specific properties of the VM
|
||||
:param properties: Emulator specific properties of the VM
|
||||
"""
|
||||
|
||||
if vm_id is None:
|
||||
@@ -44,7 +45,7 @@ class VM:
|
||||
self._vm_type = vm_type
|
||||
self._console = console
|
||||
self._console_type = console_type
|
||||
self._properties = kwargs
|
||||
self._properties = properties
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
@@ -74,6 +75,7 @@ class VM:
|
||||
def create(self):
|
||||
data = self._properties
|
||||
data["vm_id"] = self._id
|
||||
data["name"] = self._name
|
||||
data["console"] = self._console
|
||||
data["console_type"] = self._console_type
|
||||
yield from self._hypervisor.post("/projects/{}/{}/vms".format(self._project.id, self._vm_type), data=data)
|
||||
@@ -81,6 +83,7 @@ class VM:
|
||||
def __json__(self):
|
||||
return {
|
||||
"hypervisor_id": self._hypervisor.id,
|
||||
"project_id": self._project.id,
|
||||
"vm_id": self._id,
|
||||
"vm_type": self._vm_type,
|
||||
"name": self._name,
|
||||
@@ -88,4 +91,3 @@ class VM:
|
||||
"console_type": self._console_type,
|
||||
"properties": self._properties
|
||||
}
|
||||
|
||||
@@ -19,4 +19,3 @@ from .hypervisor_handler import HypervisorHandler
|
||||
from .project_handler import ProjectHandler
|
||||
from .version_handler import VersionHandler
|
||||
from .vm_handler import VMHandler
|
||||
|
||||
@@ -47,4 +47,3 @@ class VMHandler:
|
||||
vm = yield from project.addVM(hypervisor, request.json.pop("vm_id", None), **request.json)
|
||||
response.set_status(201)
|
||||
response.json(vm)
|
||||
|
||||
@@ -112,6 +112,7 @@ class VPCSVM(BaseVM):
|
||||
"vm_directory": self.working_dir,
|
||||
"status": self.status,
|
||||
"console": self._console,
|
||||
"console_type": "telnet",
|
||||
"project_id": self.project.id,
|
||||
"startup_script": self.startup_script,
|
||||
"startup_script_path": self.relative_startup_script,
|
||||
|
||||
@@ -70,15 +70,19 @@ VM_OBJECT_SCHEMA = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"hypervisor_id": {
|
||||
"description": "Server identifier",
|
||||
"description": "Hypervisor identifier",
|
||||
"type": "string"
|
||||
},
|
||||
"project_id": {
|
||||
"description": "Project identifier",
|
||||
"type": "string"
|
||||
},
|
||||
"vm_id": {
|
||||
"description": "VM identifier",
|
||||
"type": "string",
|
||||
"minLength": 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}$"
|
||||
"minLength": 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}$"
|
||||
},
|
||||
"vm_type": {
|
||||
"description": "Type of VM",
|
||||
|
||||
@@ -42,6 +42,10 @@ VPCS_CREATE_SCHEMA = {
|
||||
"maximum": 65535,
|
||||
"type": ["integer", "null"]
|
||||
},
|
||||
"console_type": {
|
||||
"description": "console type",
|
||||
"enum": ["telnet"]
|
||||
},
|
||||
"startup_script": {
|
||||
"description": "Content of the VPCS startup script",
|
||||
"type": ["string", "null"]
|
||||
@@ -67,6 +71,10 @@ VPCS_UPDATE_SCHEMA = {
|
||||
"maximum": 65535,
|
||||
"type": ["integer", "null"]
|
||||
},
|
||||
"console_type": {
|
||||
"description": "console type",
|
||||
"enum": ["telnet"]
|
||||
},
|
||||
"startup_script": {
|
||||
"description": "Content of the VPCS startup script",
|
||||
"type": ["string", "null"]
|
||||
@@ -106,6 +114,10 @@ VPCS_OBJECT_SCHEMA = {
|
||||
"maximum": 65535,
|
||||
"type": "integer"
|
||||
},
|
||||
"console_type": {
|
||||
"description": "console type",
|
||||
"enum": ["telnet"]
|
||||
},
|
||||
"project_id": {
|
||||
"description": "Project UUID",
|
||||
"type": "string",
|
||||
@@ -127,5 +139,5 @@ VPCS_OBJECT_SCHEMA = {
|
||||
}
|
||||
},
|
||||
"additionalProperties": False,
|
||||
"required": ["name", "vm_id", "status", "console", "project_id", "startup_script_path", "command_line"]
|
||||
"required": ["name", "vm_id", "status", "console", "console_type", "project_id", "startup_script_path", "command_line"]
|
||||
}
|
||||
Reference in new issue
Block a user