def _post(self, job, data): nthread = NotificationThread(id=job.id) disk = filesystems.VirtualDisk(id=data["id"], size=data["size"]) disk.create(will_crypt=data["crypt"], nthread=nthread) if data["crypt"]: try: msg = "Encrypting virtual disk..." nthread.update(Notification("info", "Filesystems", msg)) disk.encrypt(data["passwd"]) except Exception as e: disk.remove() raise msg = "Virtual disk created successfully" nthread.complete(Notification("success", "Filesystems", msg)) push_record("filesystem", disk.serialized)
def post(self): msg = request.get_json()["notification"] if not msg.get("message") or not msg.get("level")\ or not msg.get("comp"): abort(400) notif = Notification(msg["level"], msg["comp"], msg["message"], msg.get("cls"), msg.get("title")) # If ID is provided at POST, assume part of thread if msg.get("id"): nthread = NotificationThread(id=msg["id"]) if msg.get("complete"): nthread.complete(notif) else: nthread.update(notif) msg["message_id"] = notif.message_id else: notif.send() return jsonify(notification=msg), 201
def install(job, to_install): errors = False nthread = NotificationThread(id=job.id) nthread.title = "Setting up your server..." for x in to_install: a = applications.get(x) msg = "Installing {0}...".format(x) nthread.update(Notification("info", "FirstRun", msg)) try: a.install() push_record("app", a.serialized) except: errors = True if to_install: if errors: msg = ("One or more applications failed to install. " "Check the App Store pane for more information.") nthread.complete(Notification("warning", "FirstRun", msg)) else: msg = ("You may need to restart your device before " "changes will take effect.") nthread.complete(Notification("success", "FirstRun", msg))