Add module name to base manager.

This commit is contained in:
Jeremy committed 2015-01-21 15:21:15 -07:00
1 parent 97cefa23fb
commit 0b1b27db8f
8 files changed
+60 -44

No files matched your search

+10
View File
@@ -49,6 +49,16 @@ class BaseManager:
cls._instance = cls()
return cls._instance
@property
def module_name(self):
"""
Returns the module name.
:returns: module name
"""
return self.__class__.__name__
@property
def port_manager(self):
"""
+9 -5
View File
@@ -29,6 +29,10 @@ class BaseVM:
self._project = project
self._manager = manager
log.info("{module}: {name} [{uuid}] has been created".format(module=self.manager.module_name,
name=self.name,
uuid=self.uuid))
# TODO: When delete release console ports
@property
@@ -59,10 +63,10 @@ class BaseVM:
:param new_name: name
"""
log.info("{module} {name} [{uuid}]: renamed to {new_name}".format(module=self.module_name,
name=self._name,
uuid=self.uuid,
new_name=new_name))
log.info("{module}: {name} [{uuid}]: renamed to {new_name}".format(module=self.manager.module_name,
name=self.name,
uuid=self.uuid,
new_name=new_name))
self._name = new_name
@property
@@ -91,7 +95,7 @@ class BaseVM:
Return VM working directory
"""
return self._project.vm_working_directory(self.module_name, self._uuid)
return self._project.vm_working_directory(self.manager.module_name.lower(), self._uuid)
def create(self):
"""
+2 -2
View File
@@ -47,7 +47,7 @@ class Project:
self._path = os.path.join(self._location, self._uuid)
try:
os.makedirs(os.path.join(self._path, 'vms'), exist_ok=True)
os.makedirs(os.path.join(self._path, "vms"), exist_ok=True)
except OSError as e:
raise aiohttp.web.HTTPInternalServerError(text="Could not create project directory: {}".format(e))
@@ -75,7 +75,7 @@ class Project:
:param vm_uuid: VM UUID
"""
p = os.path.join(self._path, "vms", module, vm_uuid)
p = os.path.join(self._path, module, vm_uuid)
try:
os.makedirs(p, exist_ok=True)
except FileExistsError:
+20 -24
View File
@@ -49,7 +49,7 @@ class VirtualBoxVM(BaseVM):
VirtualBox VM implementation.
"""
def __init__(self, name, uuid, project, manager, vmname, linked_clone):
def __init__(self, name, uuid, project, manager, vmname, linked_clone, console=None):
super().__init__(name, uuid, project, manager)
@@ -71,22 +71,14 @@ class VirtualBoxVM(BaseVM):
if not os.access(self._vboxmanage_path, os.X_OK):
raise VirtualBoxError("VBoxManage is not executable")
self._vmname = vmname
self._started = False
self._linked_clone = linked_clone
self._system_properties = {}
self._queue = asyncio.Queue()
self._created = asyncio.Future()
self._running = True
self._worker = asyncio.async(self._run())
return
self._command = []
self._vbox_user = vbox_user
self._telnet_server_thread = None
self._serial_pipe = None
# VirtualBox settings
self._console = console
self._ethernet_adapters = []
@@ -96,27 +88,30 @@ class VirtualBoxVM(BaseVM):
self._adapter_start_index = 0
self._adapter_type = "Intel PRO/1000 MT Desktop (82540EM)"
working_dir_path = os.path.join(working_dir, "vbox")
if vbox_id and not os.path.isdir(working_dir_path):
raise VirtualBoxError("Working directory {} doesn't exist".format(working_dir_path))
# create the device own working directory
self.working_dir = working_dir_path
if linked_clone:
if vbox_id and os.path.isdir(os.path.join(self.working_dir, self._vmname)):
if uuid and os.path.isdir(os.path.join(self.working_dir, self._vmname)):
vbox_file = os.path.join(self.working_dir, self._vmname, self._vmname + ".vbox")
self._execute("registervm", [vbox_file])
self._reattach_hdds()
else:
self._create_linked_clone()
self._maximum_adapters = 8
self.adapters = 2 # creates 2 adapters by default
#self._maximum_adapters = 8
#self.adapters = 2 # creates 2 adapters by default
log.info("VirtualBox VM {name} [id={id}] has been created".format(name=self._name,
id=self._id))
return
self._command = []
self._vbox_user = vbox_user
self._telnet_server_thread = None
self._serial_pipe = None
def __json__(self):
return {"name": self.name,
"uuid": self.uuid,
"project_uuid": self.project.uuid}
@asyncio.coroutine
def _execute(self, subcommand, args, timeout=60):
@@ -156,12 +151,13 @@ class VirtualBoxVM(BaseVM):
try:
yield from self._get_system_properties()
#TODO: check for API version
self._created.set_result(True)
except VirtualBoxError as e:
self._created.set_exception(e)
return
while True:
while self._running:
future, subcommand, args = yield from self._queue.get()
try:
yield from self._execute(subcommand, args)
+2 -2
View File
@@ -106,8 +106,8 @@ class VPCSVM(BaseVM):
def __json__(self):
return {"name": self._name,
"uuid": self._uuid,
return {"name": self.name,
"uuid": self.uuid,
"console": self._console,
"project_uuid": self.project.uuid,
"script_file": self.script_file,