mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 09:18:08 +00:00
Support script file
This commit is contained in:
parent
c30f7ce9a1
commit
fa57485f11
@ -9,7 +9,7 @@ POST /vpcs HTTP/1.1
|
|||||||
|
|
||||||
HTTP/1.1 200
|
HTTP/1.1 200
|
||||||
CONNECTION: close
|
CONNECTION: close
|
||||||
CONTENT-LENGTH: 160
|
CONTENT-LENGTH: 185
|
||||||
CONTENT-TYPE: application/json
|
CONTENT-TYPE: application/json
|
||||||
DATE: Thu, 08 Jan 2015 16:09:15 GMT
|
DATE: Thu, 08 Jan 2015 16:09:15 GMT
|
||||||
SERVER: Python/3.4 aiohttp/0.13.1
|
SERVER: Python/3.4 aiohttp/0.13.1
|
||||||
@ -19,5 +19,6 @@ X-ROUTE: /vpcs
|
|||||||
"console": 2000,
|
"console": 2000,
|
||||||
"name": "PC TEST 1",
|
"name": "PC TEST 1",
|
||||||
"project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80",
|
"project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80",
|
||||||
"uuid": "6373ecfa-a186-48de-be4d-3f3463d2e23c"
|
"script_file": null,
|
||||||
|
"uuid": "aa017896-574d-4a10-bcad-d3001ea98f8b"
|
||||||
}
|
}
|
||||||
|
@ -41,11 +41,11 @@ class VPCSHandler:
|
|||||||
def create(request, response):
|
def create(request, response):
|
||||||
|
|
||||||
vpcs = VPCS.instance()
|
vpcs = VPCS.instance()
|
||||||
vm = yield from vpcs.create_vm(request.json["name"], request.json["project_uuid"], uuid=request.json.get("uuid"))
|
vm = yield from vpcs.create_vm(request.json["name"],
|
||||||
response.json({"name": vm.name,
|
request.json["project_uuid"],
|
||||||
"uuid": vm.uuid,
|
uuid=request.json.get("uuid"),
|
||||||
"console": vm.console,
|
script_file=request.json.get("script_file"))
|
||||||
"project_uuid": vm.project.uuid})
|
response.json(vm)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@Route.post(
|
@Route.post(
|
||||||
|
@ -87,7 +87,7 @@ class BaseManager:
|
|||||||
return self._vms[uuid]
|
return self._vms[uuid]
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def create_vm(self, name, project_identifier, uuid=None):
|
def create_vm(self, name, project_identifier, uuid=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Create a new VM
|
Create a new VM
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ class BaseManager:
|
|||||||
if not uuid:
|
if not uuid:
|
||||||
uuid = str(uuid4())
|
uuid = str(uuid4())
|
||||||
|
|
||||||
vm = self._VM_CLASS(name, uuid, project, self)
|
vm = self._VM_CLASS(name, uuid, project, self, **kwargs)
|
||||||
future = vm.create()
|
future = vm.create()
|
||||||
if isinstance(future, asyncio.Future):
|
if isinstance(future, asyncio.Future):
|
||||||
yield from future
|
yield from future
|
||||||
|
@ -52,9 +52,10 @@ class VPCSVM(BaseVM):
|
|||||||
:param project: Project instance
|
:param project: Project instance
|
||||||
:param manager: parent VM Manager
|
:param manager: parent VM Manager
|
||||||
:param console: TCP console port
|
:param console: TCP console port
|
||||||
|
:param script_file: A VPCS startup script
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, name, uuid, project, manager, console=None):
|
def __init__(self, name, uuid, project, manager, console=None, script_file=None):
|
||||||
|
|
||||||
super().__init__(name, uuid, project, manager)
|
super().__init__(name, uuid, project, manager)
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ class VPCSVM(BaseVM):
|
|||||||
self._started = False
|
self._started = False
|
||||||
|
|
||||||
# VPCS settings
|
# VPCS settings
|
||||||
self._script_file = ""
|
self._script_file = script_file
|
||||||
self._ethernet_adapter = EthernetAdapter() # one adapter with 1 Ethernet interface
|
self._ethernet_adapter = EthernetAdapter() # one adapter with 1 Ethernet interface
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -103,6 +104,14 @@ class VPCSVM(BaseVM):
|
|||||||
|
|
||||||
self._check_vpcs_version()
|
self._check_vpcs_version()
|
||||||
|
|
||||||
|
def __json__(self):
|
||||||
|
|
||||||
|
return {"name": self.name,
|
||||||
|
"uuid": self.uuid,
|
||||||
|
"console": self.console,
|
||||||
|
"project_uuid": self.project.uuid,
|
||||||
|
"script_file": self.script_file}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def console(self):
|
def console(self):
|
||||||
"""
|
"""
|
||||||
|
@ -50,6 +50,10 @@ VPCS_CREATE_SCHEMA = {
|
|||||||
"maximum": 65535,
|
"maximum": 65535,
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
"script_file": {
|
||||||
|
"description": "VPCS startup script",
|
||||||
|
"type": ["string", "null"]
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"required": ["name", "project_uuid"]
|
"required": ["name", "project_uuid"]
|
||||||
@ -143,7 +147,11 @@ VPCS_OBJECT_SCHEMA = {
|
|||||||
"minLength": 36,
|
"minLength": 36,
|
||||||
"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}$"
|
||||||
}
|
},
|
||||||
|
"script_file": {
|
||||||
|
"description": "VPCS startup script",
|
||||||
|
"type": ["string", "null"]
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"required": ["name", "uuid", "console", "project_uuid"]
|
"required": ["name", "uuid", "console", "project_uuid"]
|
||||||
|
@ -35,6 +35,16 @@ def test_vpcs_create(server, project):
|
|||||||
assert response.route == "/vpcs"
|
assert response.route == "/vpcs"
|
||||||
assert response.json["name"] == "PC TEST 1"
|
assert response.json["name"] == "PC TEST 1"
|
||||||
assert response.json["project_uuid"] == project.uuid
|
assert response.json["project_uuid"] == project.uuid
|
||||||
|
assert response.json["script_file"] is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_vpcs_create_script_file(server, project):
|
||||||
|
response = server.post("/vpcs", {"name": "PC TEST 1", "project_uuid": project.uuid, "script_file": "/tmp/test"})
|
||||||
|
assert response.status == 200
|
||||||
|
assert response.route == "/vpcs"
|
||||||
|
assert response.json["name"] == "PC TEST 1"
|
||||||
|
assert response.json["project_uuid"] == project.uuid
|
||||||
|
assert response.json["script_file"] == "/tmp/test"
|
||||||
|
|
||||||
|
|
||||||
def test_vpcs_nio_create_udp(server, vm):
|
def test_vpcs_nio_create_udp(server, vm):
|
||||||
|
Loading…
Reference in New Issue
Block a user