mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
API for creating a VM
This commit is contained in:
14 files changed
+405
-48
No files matched your search
@@ -18,6 +18,8 @@
|
||||
import asyncio
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from .vm import VM
|
||||
|
||||
|
||||
class Project:
|
||||
"""
|
||||
@@ -42,6 +44,7 @@ class Project:
|
||||
self._path = path
|
||||
self._temporary = temporary
|
||||
self._hypervisors = set()
|
||||
self._vms = {}
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
@@ -64,6 +67,20 @@ class Project:
|
||||
self._hypervisors.add(hypervisor)
|
||||
yield from hypervisor.post("/projects", self)
|
||||
|
||||
@asyncio.coroutine
|
||||
def addVM(self, hypervisor, vm_id, **kwargs):
|
||||
"""
|
||||
Create a vm or return an existing vm
|
||||
|
||||
:param kwargs: See the documentation of VM
|
||||
"""
|
||||
if vm_id not in self._vms:
|
||||
vm = VM(self, hypervisor, vm_id=vm_id, **kwargs)
|
||||
yield from vm.create()
|
||||
self._vms[vm.id] = vm
|
||||
return vm
|
||||
return self._vms[vm_id]
|
||||
|
||||
@asyncio.coroutine
|
||||
def close(self):
|
||||
for hypervisor in self._hypervisors:
|
||||
|
||||
Reference in new issue
Block a user