From 79bf279f4abd66fc527271d508497f673e111014 Mon Sep 17 00:00:00 2001 From: dave Date: Wed, 28 Dec 2016 19:05:19 -0800 Subject: [PATCH] Misc improvements & cleanup --- example/zd.json | 3 ++- zhypervisor/api/api.py | 19 +++---------------- zhypervisor/daemon.py | 3 +-- zhypervisor/util.py | 3 --- 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/example/zd.json b/example/zd.json index 56eb481..e5c8b08 100644 --- a/example/zd.json +++ b/example/zd.json @@ -15,5 +15,6 @@ "path": "/media/realm/tmp/qemu-testin/banto/", "init": true } - } + }, + "apiport": 3000 } diff --git a/zhypervisor/api/api.py b/zhypervisor/api/api.py index 5bc816e..9e3d9da 100644 --- a/zhypervisor/api/api.py +++ b/zhypervisor/api/api.py @@ -34,7 +34,7 @@ class ZApi(object): # self.app_root = BSApiRoot(self).mount('/api') # self.ui = Mountable(conf={'/': { # 'tools.staticdir.on': True, - # 'tools.staticdir.dir': os.getcwd() + '/ui/build', # TODO don't hardcode + # 'tools.staticdir.dir': os.getcwd() + '/ui/build', # 'tools.staticdir.index': 'index.html'}}).mount('/ui') cherrypy.config.update({ @@ -43,7 +43,7 @@ class ZApi(object): 'tools.sessions.locking': 'explicit', 'tools.sessions.timeout': 525600, 'request.show_tracebacks': True, - 'server.socket_port': 3000, # TODO configurable port + 'server.socket_port': self.master.config.get("apiport", 3000), 'server.thread_pool': 25, 'server.socket_host': '0.0.0.0', 'server.show_tracebacks': True, @@ -70,7 +70,7 @@ class ZApiV1(Mountable): super().__init__(conf={ "/machine": {'request.dispatch': cherrypy.dispatch.MethodDispatcher()}, "/disk": {'request.dispatch': cherrypy.dispatch.MethodDispatcher()}, - # "/task": {'request.dispatch': cherrypy.dispatch.MethodDispatcher()}, # @TODO this conf belongs in the child + # "/task": {'request.dispatch': cherrypy.dispatch.MethodDispatcher()}, # "/logs": { # 'tools.staticdir.on': True, # 'tools.staticdir.dir': root.master.log_path, @@ -142,7 +142,6 @@ class ZApiMachineRestart(object): def GET(self, machine_id=None): """ Start the machine - TODO can we not repeat this from Stop/Start? """ assert machine_id in self.root.master.machines self.root.master.forceful_stop(machine_id) @@ -271,12 +270,6 @@ class ZApiDisks(): :param disk_id: id of disk to create or modify 'param disk_spec: json dictionary describing the disk. see the 'spec' key of example/ubuntu-root.json """ - - assert disk_id not in self.root.master.disks or \ - self.root.master.disks[disk_id].get_status() == "idle", \ - "Disk must not be attached to modify" # TODO to a running machine? - # TODO move asserts out of the API - disk_spec = json.loads(disk_spec) self.root.master.add_disk(disk_id, disk_spec, write=True) return disk_id @@ -286,11 +279,5 @@ class ZApiDisks(): Delete a disk. Raises 404 if no such disk exists. Raises error if disk is not idle (detached) :param disk_id: ID of disk to remove """ - try: - assert self.root.master.disks[disk_id].get_status() == "idle", \ - "Disk must be detached to delete" - except KeyError: - raise cherrypy.HTTPError(status=404) - self.root.master.remove_disk(disk_id) return disk_id diff --git a/zhypervisor/daemon.py b/zhypervisor/daemon.py index 7aa3038..2b463c3 100644 --- a/zhypervisor/daemon.py +++ b/zhypervisor/daemon.py @@ -100,7 +100,7 @@ class ZHypervisorDaemon(object): """ Create a disk """ - assert disk_id not in self.disks, "Cannot update disks" + assert disk_id not in self.disks, "Cannot update disks, only create supported" disk_type = disk_spec["options"]["type"] disk_datastore = disk_spec["options"]["datastore"] datastore = self.datastores[disk_datastore] @@ -122,7 +122,6 @@ class ZHypervisorDaemon(object): """ Remove a disk from the system """ - assert self.disks[disk_id].get_status() == "idle", "Disk must be idle to delete" self.disks[disk_id].delete() del self.disks[disk_id] self.state.remove_disk(disk_id) diff --git a/zhypervisor/util.py b/zhypervisor/util.py index 5f43a51..a22fccb 100644 --- a/zhypervisor/util.py +++ b/zhypervisor/util.py @@ -91,8 +91,5 @@ class ZDisk(object): return {"options": self.options, "properties": self.properties} - def get_status(self): - return "idle" # TODO - def delete(self): raise NotImplemented()