Support script file

This commit is contained in:
Julien Duponchelle 2015-01-20 19:56:18 +01:00
parent c30f7ce9a1
commit fa57485f11
6 changed files with 40 additions and 12 deletions

View File

@ -9,7 +9,7 @@ POST /vpcs HTTP/1.1
HTTP/1.1 200
CONNECTION: close
CONTENT-LENGTH: 160
CONTENT-LENGTH: 185
CONTENT-TYPE: application/json
DATE: Thu, 08 Jan 2015 16:09:15 GMT
SERVER: Python/3.4 aiohttp/0.13.1
@ -19,5 +19,6 @@ X-ROUTE: /vpcs
"console": 2000,
"name": "PC TEST 1",
"project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80",
"uuid": "6373ecfa-a186-48de-be4d-3f3463d2e23c"
"script_file": null,
"uuid": "aa017896-574d-4a10-bcad-d3001ea98f8b"
}

View File

@ -41,11 +41,11 @@ class VPCSHandler:
def create(request, response):
vpcs = VPCS.instance()
vm = yield from vpcs.create_vm(request.json["name"], request.json["project_uuid"], uuid=request.json.get("uuid"))
response.json({"name": vm.name,
"uuid": vm.uuid,
"console": vm.console,
"project_uuid": vm.project.uuid})
vm = yield from vpcs.create_vm(request.json["name"],
request.json["project_uuid"],
uuid=request.json.get("uuid"),
script_file=request.json.get("script_file"))
response.json(vm)
@classmethod
@Route.post(

View File

@ -87,7 +87,7 @@ class BaseManager:
return self._vms[uuid]
@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
@ -104,7 +104,7 @@ class BaseManager:
if not uuid:
uuid = str(uuid4())
vm = self._VM_CLASS(name, uuid, project, self)
vm = self._VM_CLASS(name, uuid, project, self, **kwargs)
future = vm.create()
if isinstance(future, asyncio.Future):
yield from future

View File

@ -52,9 +52,10 @@ class VPCSVM(BaseVM):
:param project: Project instance
:param manager: parent VM Manager
: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)
@ -68,7 +69,7 @@ class VPCSVM(BaseVM):
self._started = False
# VPCS settings
self._script_file = ""
self._script_file = script_file
self._ethernet_adapter = EthernetAdapter() # one adapter with 1 Ethernet interface
try:
@ -103,6 +104,14 @@ class VPCSVM(BaseVM):
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
def console(self):
"""

View File

@ -50,6 +50,10 @@ VPCS_CREATE_SCHEMA = {
"maximum": 65535,
"type": "integer"
},
"script_file": {
"description": "VPCS startup script",
"type": ["string", "null"]
},
},
"additionalProperties": False,
"required": ["name", "project_uuid"]
@ -143,7 +147,11 @@ VPCS_OBJECT_SCHEMA = {
"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}$"
}
},
"script_file": {
"description": "VPCS startup script",
"type": ["string", "null"]
},
},
"additionalProperties": False,
"required": ["name", "uuid", "console", "project_uuid"]

View File

@ -35,6 +35,16 @@ def test_vpcs_create(server, project):
assert response.route == "/vpcs"
assert response.json["name"] == "PC TEST 1"
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):