def post(self, veid): sql = models.VM.select(models.VM.q.veid == int(veid))[0] if sql.user != self.current_user and sql.user: self.redirect(self.reverse_url("containers")+"?error=1") return vm = sql.vz if vm.running: self.redirect(self.reverse_url("containers")+"?error=5") return proc = vm.destroy() for i in sql.varnishBackend: for i2 in i.cond: i2.destroySelf() i.destroySelf() for i in sql.portForward: i.destroySelf() if sql.munin: sql.munin.destroySelf() import munin, vmfw munin.update(models.Munin.select(), models.User.select()) vmfw.update(models.PortForward.select()) vmfw.restart() varnish.updateBackend(models.VarnishBackend.select()) varnish.updateRecv(models.VarnishCond.select()) varnish.restart() sql.destroySelf() time.sleep(1) # wait for dusts to settle self.redirect(self.get_argument("return", self.reverse_url("containers")+"?msg=3"))
def post(self, veid): self.set_header("Content-type", "text/json") if not _config.getboolean("munin", "enabled"): return sql = models.VM.select(models.VM.q.veid == int(veid))[0] if sql.user != self.current_user or not sql.user: self.write(simplejson.dumps({"error": _("VM not owned by current user")})) return if self.get_argument("status") == "toggle": e = not sql.munin else: e = self.get_argument("status") == "true" import munin if e: if not munin.check_ip(sql.vz.ip): self.write(simplejson.dumps({"error": _("Cannot connect to Munin on the VM.")})) return models.Munin(vm=sql) else: sql.munin.destroySelf() munin.update(models.Munin.select(), models.User.select()) self.write(simplejson.dumps({"status": bool(sql.munin)}))