z-hypervisor/zhypervisor/machine.py

48 lines
1.3 KiB
Python
Raw Normal View History

2016-12-26 16:42:48 -08:00
import logging
from zhypervisor.clients.qmachine import QMachine
class MachineSpec(object):
2016-12-26 17:14:28 -08:00
"""
Represents a machine we may control
"""
2016-12-26 16:42:48 -08:00
def __init__(self, master, machine_id, machine_type, spec):
2016-12-26 17:14:28 -08:00
"""
Initialize options and properties of the machine. More importantly, initialize the self.machine object which
should be a subclass of zhypervisor.util.Machine.
"""
2016-12-26 16:42:48 -08:00
logging.info("Initting machine %s", machine_id)
self.master = master
self.machine_id = machine_id
self.machine_type = machine_type
2016-12-26 17:14:28 -08:00
self.options = spec["options"]
self.properties = spec["properties"]
2016-12-26 16:42:48 -08:00
# TODO replace if/else with better system
if machine_type == "q":
self.machine = QMachine(self)
else:
raise Exception("Unknown machine type: {}".format(machine_type))
def start(self):
2016-12-26 17:14:28 -08:00
"""
Start this machine (pass-through)
"""
2016-12-26 16:42:48 -08:00
self.machine.start_machine()
def stop(self):
2016-12-26 17:14:28 -08:00
"""
Stop this machine
"""
2016-12-26 16:42:48 -08:00
self.machine.block_respawns = True
self.machine.stop_machine()
2016-12-26 17:14:28 -08:00
def serialize(self):
"""
Return a serializable form of this machine's specs
"""
return {"options": self.options,
"properties": self.properties}