remove options dict from state state jsons/apis for simiplicity
This commit is contained in:
parent
4d2723e048
commit
dfb8ca7c01
|
@ -1,38 +1,34 @@
|
||||||
{
|
{
|
||||||
"machine_id": "ubuntu",
|
"machine_id": "ubuntu",
|
||||||
"spec": {
|
"properties": {
|
||||||
"options": {
|
"type": "q",
|
||||||
"type": "q",
|
"autostart": true,
|
||||||
"autostart": true,
|
"respawn": true,
|
||||||
"respawn": true
|
"cores": 2,
|
||||||
},
|
"mem": 1024,
|
||||||
"properties": {
|
"drives": [
|
||||||
"cores": 2,
|
{
|
||||||
"mem": 1024,
|
"disk": "ubuntu-root",
|
||||||
"drives": [
|
"index": 0,
|
||||||
{
|
"if": "virtio"
|
||||||
"disk": "ubuntu-root",
|
},
|
||||||
"index": 0,
|
{
|
||||||
"if": "virtio"
|
"disk": "multipreseed-14.04.iso",
|
||||||
},
|
"index": 1,
|
||||||
{
|
"media": "cdrom"
|
||||||
"disk": "multipreseed-14.04.iso",
|
}
|
||||||
"index": 1,
|
],
|
||||||
"media": "cdrom"
|
"netifaces": [
|
||||||
}
|
{
|
||||||
],
|
"type": "nic",
|
||||||
"netifaces": [
|
"vlan": 0,
|
||||||
{
|
"model": "e1000",
|
||||||
"type": "nic",
|
"macaddr": "82:25:60:41:07:98"
|
||||||
"vlan": 0,
|
},
|
||||||
"model": "e1000",
|
{
|
||||||
"macaddr": "82:25:60:41:07:98"
|
"type": "tap"
|
||||||
},
|
}
|
||||||
{
|
],
|
||||||
"type": "tap"
|
"vnc": 10
|
||||||
}
|
|
||||||
],
|
|
||||||
"vnc": 10
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
CherryPy==8.5.0
|
|
@ -235,7 +235,7 @@ class ZApiMachines():
|
||||||
machine = {"machine_id": _machine_id,
|
machine = {"machine_id": _machine_id,
|
||||||
"_status": machine_spec.machine.get_status()}
|
"_status": machine_spec.machine.get_status()}
|
||||||
if not summary:
|
if not summary:
|
||||||
machine.update({"spec": machine_spec.serialize()})
|
machine.update({"properties": machine_spec.serialize()})
|
||||||
|
|
||||||
machines[_machine_id] = machine
|
machines[_machine_id] = machine
|
||||||
if machine_id is not None:
|
if machine_id is not None:
|
||||||
|
|
|
@ -46,7 +46,7 @@ class QMachine(Machine):
|
||||||
proc.wait()
|
proc.wait()
|
||||||
logging.info("qemu process has exited")
|
logging.info("qemu process has exited")
|
||||||
self.proc = None
|
self.proc = None
|
||||||
if not self.block_respawns and self.spec.options.get("respawn", False):
|
if not self.block_respawns and self.spec.properties.get("respawn", False):
|
||||||
self.start_machine()
|
self.start_machine()
|
||||||
|
|
||||||
def stop_machine(self):
|
def stop_machine(self):
|
||||||
|
|
|
@ -57,7 +57,7 @@ class ZHypervisorDaemon(object):
|
||||||
Load all disks and ensure reachability
|
Load all disks and ensure reachability
|
||||||
"""
|
"""
|
||||||
for disk in self.state.get_disks():
|
for disk in self.state.get_disks():
|
||||||
self.add_disk(disk["disk_id"], {"options": disk["options"], "properties": disk["properties"]})
|
self.add_disk(disk["disk_id"], disk["properties"])
|
||||||
|
|
||||||
def init_machines(self):
|
def init_machines(self):
|
||||||
"""
|
"""
|
||||||
|
@ -65,11 +65,11 @@ class ZHypervisorDaemon(object):
|
||||||
"""
|
"""
|
||||||
for machine_info in self.state.get_machines():
|
for machine_info in self.state.get_machines():
|
||||||
machine_id = machine_info["machine_id"]
|
machine_id = machine_info["machine_id"]
|
||||||
self.add_machine(machine_id, machine_info["spec"])
|
self.add_machine(machine_id, machine_info["properties"])
|
||||||
|
|
||||||
# Launch if machine is an autostarted machine
|
# Launch if machine is an autostarted machine
|
||||||
machine = self.machines[machine_id]
|
machine = self.machines[machine_id]
|
||||||
if machine.options.get("autostart", False) and machine.machine.get_status() == "stopped":
|
if machine.properties.get("autostart", False) and machine.machine.get_status() == "stopped":
|
||||||
machine.start()
|
machine.start()
|
||||||
|
|
||||||
def signal_handler(self, signum, frame):
|
def signal_handler(self, signum, frame):
|
||||||
|
@ -106,8 +106,8 @@ class ZHypervisorDaemon(object):
|
||||||
Create a disk
|
Create a disk
|
||||||
"""
|
"""
|
||||||
assert disk_id not in self.disks, "Cannot update disks, only create supported"
|
assert disk_id not in self.disks, "Cannot update disks, only create supported"
|
||||||
disk_type = disk_spec["options"]["type"]
|
disk_type = disk_spec["type"]
|
||||||
disk_datastore = disk_spec["options"]["datastore"]
|
disk_datastore = disk_spec["datastore"]
|
||||||
datastore = self.datastores[disk_datastore]
|
datastore = self.datastores[disk_datastore]
|
||||||
if disk_type == "qdisk":
|
if disk_type == "qdisk":
|
||||||
disk = QDisk(datastore, disk_id, disk_spec)
|
disk = QDisk(datastore, disk_id, disk_spec)
|
||||||
|
@ -137,14 +137,13 @@ class ZHypervisorDaemon(object):
|
||||||
"""
|
"""
|
||||||
Create or update a machine.
|
Create or update a machine.
|
||||||
:param machine_id: alphanumeric id of machine to modify/create
|
:param machine_id: alphanumeric id of machine to modify/create
|
||||||
:param machine_spec: dictionary of machine options - see example/ubuntu.json
|
:param machine_spec: dictionary of machine properties - see example/ubuntu.json
|
||||||
:param write: commit machinge changes to on-disk state
|
:param write: commit machinge changes to on-disk state
|
||||||
"""
|
"""
|
||||||
# Find / create the machine
|
# Find / create the machine
|
||||||
if machine_id in self.machines:
|
if machine_id in self.machines:
|
||||||
machine = self.machines[machine_id]
|
machine = self.machines[machine_id]
|
||||||
machine.options = machine_spec["options"]
|
machine.properties = machine_spec
|
||||||
machine.properties = machine_spec["properties"]
|
|
||||||
else:
|
else:
|
||||||
machine = MachineSpec(self, machine_id, machine_spec)
|
machine = MachineSpec(self, machine_id, machine_spec)
|
||||||
self.machines[machine_id] = machine
|
self.machines[machine_id] = machine
|
||||||
|
@ -190,7 +189,7 @@ class ZDataStore(object):
|
||||||
except:
|
except:
|
||||||
if init_ok:
|
if init_ok:
|
||||||
with open(metainfo_path, "w") as f:
|
with open(metainfo_path, "w") as f:
|
||||||
json.dump({}, f)
|
json.dump({}, f, sort_keys=True, indent=4)
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
logging.info("Initialized datastore %s at %s", name, self.root_path)
|
logging.info("Initialized datastore %s at %s", name, self.root_path)
|
||||||
|
@ -229,7 +228,7 @@ class ZConfig(object):
|
||||||
"""
|
"""
|
||||||
with open(os.path.join(self.machine_data_dir, "{}.json".format(machine_id)), "w") as f:
|
with open(os.path.join(self.machine_data_dir, "{}.json".format(machine_id)), "w") as f:
|
||||||
json.dump({"machine_id": machine_id,
|
json.dump({"machine_id": machine_id,
|
||||||
"spec": machine_spec}, f, indent=4)
|
"properties": machine_spec}, f, indent=4, sort_keys=True)
|
||||||
|
|
||||||
def write_machine_o(self, machine_obj):
|
def write_machine_o(self, machine_obj):
|
||||||
"""
|
"""
|
||||||
|
@ -258,8 +257,7 @@ class ZConfig(object):
|
||||||
def write_disk(self, disk_id, disk_spec):
|
def write_disk(self, disk_id, disk_spec):
|
||||||
with open(os.path.join(self.disk_data_dir, "{}.json".format(disk_id)), "w") as f:
|
with open(os.path.join(self.disk_data_dir, "{}.json".format(disk_id)), "w") as f:
|
||||||
disk = {"disk_id": disk_id,
|
disk = {"disk_id": disk_id,
|
||||||
"options": disk_spec["options"],
|
"properties": disk_spec}
|
||||||
"properties": disk_spec["properties"]}
|
|
||||||
json.dump(disk, f, indent=4)
|
json.dump(disk, f, indent=4)
|
||||||
|
|
||||||
def remove_disk(self, disk_id):
|
def remove_disk(self, disk_id):
|
||||||
|
@ -283,7 +281,7 @@ def main():
|
||||||
"default": {
|
"default": {
|
||||||
"path": "/opt/z/datastore/machines/"
|
"path": "/opt/z/datastore/machines/"
|
||||||
}
|
}
|
||||||
}}, f, indent=4)
|
}}, f, indent=4, sort_keys=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(args.config) as f:
|
with open(args.config) as f:
|
||||||
|
|
|
@ -16,14 +16,13 @@ class MachineSpec(object):
|
||||||
self.master = master
|
self.master = master
|
||||||
self.machine_id = machine_id
|
self.machine_id = machine_id
|
||||||
|
|
||||||
self.options = spec["options"]
|
self.properties = spec
|
||||||
self.properties = spec["properties"]
|
|
||||||
|
|
||||||
# TODO replace if/else with better system
|
# TODO replace if/else with better system
|
||||||
if self.options["type"] == "q":
|
if self.properties["type"] == "q":
|
||||||
self.machine = QMachine(self)
|
self.machine = QMachine(self)
|
||||||
else:
|
else:
|
||||||
raise Exception("Unknown machine type: {}".format(self.options["type"]))
|
raise Exception("Unknown machine type: {}".format(self.properties["type"]))
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""
|
"""
|
||||||
|
@ -43,12 +42,10 @@ class MachineSpec(object):
|
||||||
"""
|
"""
|
||||||
Write the machine's config to disk
|
Write the machine's config to disk
|
||||||
"""
|
"""
|
||||||
self.master.add_machine(self.machine_id, {"options": self.options, "properties": self.properties},
|
self.master.add_machine(self.machine_id, self.properties, write=True)
|
||||||
write=True)
|
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
"""
|
"""
|
||||||
Return a serializable form of this machine's specs
|
Return a serializable form of this machine's specs
|
||||||
"""
|
"""
|
||||||
return {"options": self.options,
|
return self.properties
|
||||||
"properties": self.properties}
|
|
||||||
|
|
|
@ -70,8 +70,7 @@ class ZDisk(object):
|
||||||
def __init__(self, datastore, disk_id, spec):
|
def __init__(self, datastore, disk_id, spec):
|
||||||
self.datastore = datastore
|
self.datastore = datastore
|
||||||
self.disk_id = disk_id
|
self.disk_id = disk_id
|
||||||
self.options = spec["options"]
|
self.properties = spec
|
||||||
self.properties = spec["properties"]
|
|
||||||
self.validate()
|
self.validate()
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
@ -88,8 +87,7 @@ class ZDisk(object):
|
||||||
os.makedirs(self.get_path(), exist_ok=True)
|
os.makedirs(self.get_path(), exist_ok=True)
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
return {"options": self.options,
|
return self.properties
|
||||||
"properties": self.properties}
|
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
raise NotImplemented()
|
raise NotImplemented()
|
||||||
|
|
Loading…
Reference in New Issue