def publish(self, uuid, vhost, port, redirect404): store=self.getByUuid(uuid) if store==None: raise Exception("Unknown store") if store.vhost<>"" or store.port<>"": raise Exception("Store is already published") with open(Config.NGINX_DIR+"/"+uuid, 'w''') as f: f.write("server {\n ") f.write(" listen "+port+";\n") f.write(" server_name "+vhost+";\n") f.write(" access_log /var/log/nginx/"+uuid+".access;\n") if store.type=="LI": f.write(" types { } \n") f.write(" add_header Content-Disposition 'attachment' ;\n") if redirect404<>None: f.write(" error_page 404 "+redirect404+" ;\n") f.write(" location / { root /var/www/volumes/"+store.diskuuid+"/"+uuid+"; } \n") f.write("}\n") store.element.setAttribute("vhost", vhost) store.element.setAttribute("port", str(port)) if redirect404<>None: store.element.setAttribute("redirect404", redirect404) self.save() tools.reloadNginx() return vhost+":"+str(port)
return vhost+":"+str(port) def remove(self, uuid): store=self.getByUuid(uuid) if store==None: raise Exception("Unknown store") if store.vhost<>"" or store.port<>"": self.unpublish(uuid) try: rmtree(Config.STORES_ROOT+"/"+store.diskuuid+"/"+uuid) except Exception, e: pass store.element.parentNode.removeChild(store.element) self.save() return "OK" def unpublish(self,uuid): store=self.getByUuid(uuid) if store==None: raise Exception("Unknown store") if store.vhost=="" and store.port=="": raise Exception("Store is not published") try: os.unlink(Config.NGINX_DIR+"/"+uuid) except Exception, e: pass store.element.removeAttribute("port") store.element.removeAttribute("vhost") store.element.removeAttribute("redirect404") self.save() tools.reloadNginx() return "OK"