mirror of
https://github.com/GNS3/gns3-server
synced 2025-01-12 17:10:55 +00:00
Update VPCS and delete VPCS via controller
This commit is contained in:
parent
d7ed37ce02
commit
6b9e46950c
@ -93,6 +93,7 @@ class VM:
|
|||||||
Create the VM on the compute Node
|
Create the VM on the compute Node
|
||||||
"""
|
"""
|
||||||
data = self._vm_data()
|
data = self._vm_data()
|
||||||
|
data["vm_id"] = self._id
|
||||||
response = yield from self._compute.post("/projects/{}/{}/vms".format(self._project.id, self._vm_type), data=data)
|
response = yield from self._compute.post("/projects/{}/{}/vms".format(self._project.id, self._vm_type), data=data)
|
||||||
self._parse_vm_response(response)
|
self._parse_vm_response(response)
|
||||||
|
|
||||||
@ -109,13 +110,17 @@ class VM:
|
|||||||
:param properties: Emulator specific properties of the VM
|
:param properties: Emulator specific properties of the VM
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self._name = name
|
if name:
|
||||||
self._console = console
|
self._name = name
|
||||||
self._console_type = console_type
|
if console:
|
||||||
self._properties = properties
|
self._console = console
|
||||||
|
if console_type:
|
||||||
|
self._console_type = console_type
|
||||||
|
if properties != {}:
|
||||||
|
self._properties = properties
|
||||||
|
|
||||||
data = self._vm_data()
|
data = self._vm_data()
|
||||||
response = yield from self._compute.put("/projects/{}/{}/vms".format(self._project.id, self._vm_type), data=data)
|
response = yield from self.put(None, data=data)
|
||||||
self._parse_vm_response(response)
|
self._parse_vm_response(response)
|
||||||
|
|
||||||
def _parse_vm_response(self, response):
|
def _parse_vm_response(self, response):
|
||||||
@ -125,7 +130,7 @@ class VM:
|
|||||||
for key, value in response.json.items():
|
for key, value in response.json.items():
|
||||||
if key == "console":
|
if key == "console":
|
||||||
self._console = value
|
self._console = value
|
||||||
elif key in ["console_type", "name", "vm_id"]:
|
elif key in ["console_type", "name", "vm_id", "project_id", "vm_directory", "command_line", "status"]:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self._properties[key] = value
|
self._properties[key] = value
|
||||||
@ -135,7 +140,6 @@ class VM:
|
|||||||
Prepare VM data to send to the remote controller
|
Prepare VM data to send to the remote controller
|
||||||
"""
|
"""
|
||||||
data = copy.copy(self._properties)
|
data = copy.copy(self._properties)
|
||||||
data["vm_id"] = self._id
|
|
||||||
data["name"] = self._name
|
data["name"] = self._name
|
||||||
data["console"] = self._console
|
data["console"] = self._console
|
||||||
data["console_type"] = self._console_type
|
data["console_type"] = self._console_type
|
||||||
@ -193,17 +197,24 @@ class VM:
|
|||||||
"""
|
"""
|
||||||
HTTP post on the VM
|
HTTP post on the VM
|
||||||
"""
|
"""
|
||||||
if data:
|
if path is None:
|
||||||
return (yield from self._compute.put("/projects/{}/{}/vms/{}{}".format(self._project.id, self._vm_type, self._id, path), data=data))
|
path = "/projects/{}/{}/vms/{}".format(self._project.id, self._vm_type, self._id)
|
||||||
else:
|
else:
|
||||||
return (yield from self._compute.put("/projects/{}/{}/vms/{}{}".format(self._project.id, self._vm_type, self._id, path)))
|
path = "/projects/{}/{}/vms/{}{}".format(self._project.id, self._vm_type, self._id, path)
|
||||||
|
if data:
|
||||||
|
return (yield from self._compute.put(path, data=data))
|
||||||
|
else:
|
||||||
|
return (yield from self._compute.put(path))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def delete(self, path=None):
|
def delete(self, path=None):
|
||||||
"""
|
"""
|
||||||
HTTP post on the VM
|
HTTP post on the VM
|
||||||
"""
|
"""
|
||||||
return (yield from self._compute.delete("/projects/{}/{}/vms/{}{}".format(self._project.id, self._vm_type, self._id, path)))
|
if path is None:
|
||||||
|
return (yield from self._compute.delete("/projects/{}/{}/vms/{}".format(self._project.id, self._vm_type, self._id)))
|
||||||
|
else:
|
||||||
|
return (yield from self._compute.delete("/projects/{}/{}/vms/{}{}".format(self._project.id, self._vm_type, self._id, path)))
|
||||||
|
|
||||||
def __json__(self):
|
def __json__(self):
|
||||||
return {
|
return {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from ....web.route import Route
|
from ....web.route import Route
|
||||||
from ....schemas.vm import VM_OBJECT_SCHEMA
|
from ....schemas.vm import VM_OBJECT_SCHEMA, VM_UPDATE_SCHEMA
|
||||||
from ....controller.project import Project
|
from ....controller.project import Project
|
||||||
from ....controller import Controller
|
from ....controller import Controller
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ class VMHandler:
|
|||||||
400: "Invalid request"
|
400: "Invalid request"
|
||||||
},
|
},
|
||||||
description="Update a VM instance",
|
description="Update a VM instance",
|
||||||
input=VM_OBJECT_SCHEMA,
|
input=VM_UPDATE_SCHEMA,
|
||||||
output=VM_OBJECT_SCHEMA)
|
output=VM_OBJECT_SCHEMA)
|
||||||
def update(request, response):
|
def update(request, response):
|
||||||
project = Controller.instance().getProject(request.match_info["project_id"])
|
project = Controller.instance().getProject(request.match_info["project_id"])
|
||||||
|
@ -111,3 +111,6 @@ VM_OBJECT_SCHEMA = {
|
|||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"required": ["name", "vm_type", "compute_id"]
|
"required": ["name", "vm_type", "compute_id"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VM_UPDATE_SCHEMA = VM_OBJECT_SCHEMA
|
||||||
|
del VM_UPDATE_SCHEMA["required"]
|
||||||
|
@ -79,6 +79,10 @@ VPCS_UPDATE_SCHEMA = {
|
|||||||
"description": "Content of the VPCS startup script",
|
"description": "Content of the VPCS startup script",
|
||||||
"type": ["string", "null"]
|
"type": ["string", "null"]
|
||||||
},
|
},
|
||||||
|
"startup_script_path": {
|
||||||
|
"description": "Path of the VPCS startup script relative to project directory (IGNORED)",
|
||||||
|
"type": ["string", "null"]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
}
|
}
|
||||||
|
@ -91,15 +91,14 @@ def test_update(vm, compute, project, async_run):
|
|||||||
response.json = {"console": 2048}
|
response.json = {"console": 2048}
|
||||||
compute.put = AsyncioMagicMock(return_value=response)
|
compute.put = AsyncioMagicMock(return_value=response)
|
||||||
|
|
||||||
async_run(vm.update(console=2048, console_type="vnc", properties={"startup_script" :"echo test"}, name="demo"))
|
async_run(vm.update(console=2048, console_type="vnc", properties={"startup_script": "echo test"}, name="demo"))
|
||||||
data = {
|
data = {
|
||||||
"console": 2048,
|
"console": 2048,
|
||||||
"console_type": "vnc",
|
"console_type": "vnc",
|
||||||
"vm_id": vm.id,
|
|
||||||
"startup_script": "echo test",
|
"startup_script": "echo test",
|
||||||
"name": "demo"
|
"name": "demo"
|
||||||
}
|
}
|
||||||
compute.put.assert_called_with("/projects/{}/vpcs/vms".format(vm.project.id), data=data)
|
compute.put.assert_called_with("/projects/{}/vpcs/vms/{}".format(vm.project.id, vm.id), data=data)
|
||||||
assert vm._console == 2048
|
assert vm._console == 2048
|
||||||
assert vm._properties == {"startup_script": "echo test"}
|
assert vm._properties == {"startup_script": "echo test"}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user