Drop queue codes because it's too specific

This commit is contained in:
Julien Duponchelle 2015-01-19 13:47:20 +01:00
parent 2c3b0061a2
commit f0880c4a37
2 changed files with 13 additions and 42 deletions

View File

@ -28,14 +28,12 @@ class BaseVM:
def __init__(self, name, identifier, manager): def __init__(self, name, identifier, manager):
self._loop = asyncio.get_event_loop()
self._queue = asyncio.Queue()
self._name = name self._name = name
self._id = identifier self._id = identifier
self._created = asyncio.Future() self._created = asyncio.Future()
self._manager = manager self._manager = manager
self._config = Config.instance() self._config = Config.instance()
self._worker = asyncio.async(self._run()) asyncio.async(self._create())
log.info("{type} device {name} [id={id}] has been created".format(type=self.__class__.__name__, log.info("{type} device {name} [id={id}] has been created".format(type=self.__class__.__name__,
name=self._name, name=self._name,
id=self._id)) id=self._id))
@ -74,31 +72,13 @@ class BaseVM:
@asyncio.coroutine @asyncio.coroutine
def _create(self): def _create(self):
""" """
Called when the run loop start Called when the run module is created and ready to receive
commands. It's asynchronous.
""" """
raise NotImplementedError
@asyncio.coroutine
def _run(self, timeout=60):
try:
yield from self._create()
self._created.set_result(True) self._created.set_result(True)
except VMError as e: log.info("{type} device {name} [id={id}] has been created".format(type=self.__class__.__name__,
self._created.set_exception(e) name=self._name,
return id=self._id))
while True:
future, command = yield from self._queue.get()
try:
try:
yield from asyncio.wait_for(self._execute(command), timeout=timeout)
except asyncio.TimeoutError:
raise VMError("{} has timed out after {} seconds!".format(command, timeout))
future.set_result(True)
except Exception as e:
future.set_exception(e)
def wait_for_creation(self): def wait_for_creation(self):
return self._created return self._created
@ -111,17 +91,12 @@ class BaseVM:
raise NotImplementedError raise NotImplementedError
def put(self, *args):
"""
Add to the processing queue of the VM
:returns: future @asyncio.coroutine
def stop(self):
"""
Starts the VM process.
""" """
future = asyncio.Future() raise NotImplementedError
try:
args.insert(0, future)
self._queue.put_nowait(args)
except asyncio.qeues.QueueFull:
raise VMError("Queue is full")
return future

View File

@ -173,10 +173,6 @@ class VPCSDevice(BaseVM):
except (OSError, subprocess.SubprocessError) as e: except (OSError, subprocess.SubprocessError) as e:
raise VPCSError("Error while looking for the VPCS version: {}".format(e)) raise VPCSError("Error while looking for the VPCS version: {}".format(e))
@asyncio.coroutine
def _create(self):
pass
@asyncio.coroutine @asyncio.coroutine
def start(self): def start(self):
""" """