No need for start_vm and stop_vm in the manager.

pull/100/head
Jeremy 10 years ago
parent beb27b3f69
commit f231b06833

@ -62,10 +62,11 @@ class VirtualBoxHandler:
404: "VirtualBox VM instance doesn't exist"
},
description="Start a VirtualBox VM instance")
def create(request, response):
def start(request, response):
vbox_manager = VirtualBox.instance()
yield from vbox_manager.start_vm(request.match_info["uuid"])
vm = vbox_manager.get_vm(request.match_info["uuid"])
yield from vm.start()
response.set_status(204)
@classmethod
@ -80,8 +81,9 @@ class VirtualBoxHandler:
404: "VirtualBox VM instance doesn't exist"
},
description="Stop a VirtualBox VM instance")
def create(request, response):
def stop(request, response):
vbox_manager = VirtualBox.instance()
yield from vbox_manager.stop_vm(request.match_info["uuid"])
vm = vbox_manager.get_vm(request.match_info["uuid"])
yield from vm.stop()
response.set_status(204)

@ -102,10 +102,11 @@ class VPCSHandler:
404: "VPCS instance doesn't exist"
},
description="Start a VPCS instance")
def create(request, response):
def start(request, response):
vpcs_manager = VPCS.instance()
yield from vpcs_manager.start_vm(request.match_info["uuid"])
vm = vpcs_manager.get_vm(request.match_info["uuid"])
yield from vm.start()
response.set_status(204)
@classmethod
@ -120,10 +121,11 @@ class VPCSHandler:
404: "VPCS instance doesn't exist"
},
description="Stop a VPCS instance")
def create(request, response):
def stop(request, response):
vpcs_manager = VPCS.instance()
yield from vpcs_manager.stop_vm(request.match_info["uuid"])
vm = vpcs_manager.get_vm(request.match_info["uuid"])
yield from vm.stop()
response.set_status(204)
@Route.post(

@ -126,20 +126,9 @@ class BaseManager:
uuid = str(uuid4())
vm = self._VM_CLASS(name, uuid, project, self, *args, **kwargs)
future = vm.create()
if isinstance(future, asyncio.Future):
yield from future
if asyncio.iscoroutinefunction(vm.create):
yield from vm.create()
else:
vm.create()
self._vms[vm.uuid] = vm
return vm
@asyncio.coroutine
def start_vm(self, uuid):
vm = self.get_vm(uuid)
yield from vm.start()
@asyncio.coroutine
def stop_vm(self, uuid):
vm = self.get_vm(uuid)
yield from vm.stop()

@ -15,7 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
log = logging.getLogger(__name__)
@ -29,9 +28,9 @@ 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))
log.debug("{module}: {name} [{uuid}] initialized".format(module=self.manager.module_name,
name=self.name,
uuid=self.uuid))
# TODO: When delete release console ports
@ -63,10 +62,10 @@ class BaseVM:
:param new_name: 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))
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
@ -102,7 +101,9 @@ class BaseVM:
Creates the VM.
"""
return
log.info("{module}: {name} [{uuid}] created".format(module=self.manager.module_name,
name=self.name,
uuid=self.uuid))
def start(self):
"""

@ -27,6 +27,7 @@ class ProjectManager:
"""
def __init__(self):
self._projects = {}
@classmethod

@ -81,7 +81,7 @@ class ColouredStreamHandler(logging.StreamHandler):
def init_logger(level, quiet=False):
stream_handler = ColouredStreamHandler(sys.stdout)
stream_handler.formatter = ColouredFormatter("{asctime} {levelname:8} {filename}:{lineno}#RESET# {message}", "%Y-%m-%d %H:%M:%S", "{")
stream_handler.formatter = ColouredFormatter("{asctime} {levelname} {filename}:{lineno}#RESET# {message}", "%Y-%m-%d %H:%M:%S", "{")
if quiet:
stream_handler.addFilter(logging.Filter(name="user_facing"))
logging.getLogger('user_facing').propagate = False

Loading…
Cancel
Save