def install(self, extra_vars={}, enable=True, nthread=None): """ Install reverse proxy, including prep and app recipes. :param dict extra_vars: Extra form variables as provided by app :param bool enable: Enable the site in nginx on install? :param message message: Message object to update with status """ if not nthread: nthread = NotificationThread() try: self._install(extra_vars, enable, nthread) except Exception as e: nthread.complete(Notification("error", "Webs", str(e))) raise
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))
def _operation(self, job, install, remove): if install: try: pacman.refresh() prereqs = pacman.needs_for(install) upgr = (x["id"] for x in pacman.get_installed() if x.get("upgradable")) if sorted(upgr) == sorted(install): # Upgrade msg = "Performing system upgrade..." msg = Notification("info", "Packages", msg) nthread = NotificationThread(id=job.id, message=msg) pacman.upgrade() else: # Install title = "Installing {0} package(s)".format(len(prereqs)) msg = Notification("info", "Packages", ", ".join(prereqs)) nthread = NotificationThread(id=job.id, title=title, message=msg) pacman.install(install) for x in prereqs: try: info = process_info(pacman.get_info(x)) if "installed" not in info: info["installed"] = True push_record("package", info) except: pass except Exception as e: nthread.complete(Notification("error", "Packages", str(e))) return if remove: try: prereqs = pacman.depends_for(remove) title = "Removing {0} package(s)".format(len(prereqs)) msg = Notification("info", "Packages", ", ".join(prereqs)) nthread = NotificationThread(id=job.id, title=title, message=msg) pacman.remove(remove) for x in prereqs: try: info = process_info(pacman.get_info(x)) if "installed" not in info: info["installed"] = False push_record("package", info) except: pass except Exception as e: nthread.complete(Notification("error", "Packages", str(e))) return msg = "Operations completed successfully" nthread.complete(Notification("success", "Packages", msg))