def get_href(self, filename, **kwargs): if not filename: return '' s = settings.GLOBAL fname = norm_filename(files.unicode_filename(filename, s.FILESYSTEM_ENCODING)) f = url_for('file_serving', filename=fname, **kwargs) return f
def delete(self, id): try: self.client.remove_container(container=id, force=True) except Exception as e: self.client.stop(container=id) self.client.remove_container(container=id) return redirect(url_for(Containers.index))
def restart(self, id): self.client.restart(container=id) if self.client.inspect_container(container=id)["State"]["Running"]: # cmd = "pipework "+ settings["DOCKER"]["NETWORK"] + " " +name + " " + ip +"/24" # else: cmd = ( "pipework " + settings["DOCKER"]["NETWORK"] + " " + self.client.inspect_container(container=id)["Name"][1:] + " dhcp" ) print cmd os.system(cmd) return redirect(url_for(Containers.index))
def url_for_static(filename=None, **kwargs): from uliweb import url_for, settings from urlparse import urlparse if filename.startswith('/'): return filename r = urlparse(filename) if r.scheme or r.netloc: return filename kwargs['filename'] = filename #add STATIC_VER support ver = settings.GLOBAL.STATIC_VER if ver: kwargs['ver'] = ver return url_for('uliweb.contrib.staticfiles.static', **kwargs)
def add(self): if request.method == "GET": images = [] for i in self.client.images(): images.append(i["RepoTags"][0]) return {"images": sorted(images)} elif request.method == "POST": image = request.params["image"] name = request.params["name"] command = request.params["command"] ip = request.params["ip"] if len(name) <= 1: return json({"success": False, "message": "name长度不能小于一个字符"}) containerId = self.client.create_container( image=image, name=name, command=command, stdin_open=True, tty=True, detach=True )["Id"] print containerId self.client.start(container=containerId) cmd = "" if self.client.inspect_container(container=containerId)["State"]["Running"] and ip.strip(): cmd = "pipework " + settings["DOCKER"]["NETWORK"] + " " + name + " " + ip + "/24" else: cmd = "pipework " + settings["DOCKER"]["NETWORK"] + " " + name + " dhcp" print cmd # print "docker exec "+containerId + """ bash -c "echo 'root:""" + command + """' | chpasswd" """ print os.system(cmd) # ip = str(commands.getoutput("docker exec "+ containerId +" ifconfig eth1|sed -n 2p|awk '{ print $2 }'|awk -F : '{ print $2 }'")).lower() # print ip # if ip.find("error") ==-1: # #con = functions.get_model(Container) # c = con( # containerid = containerId, # name = name, # ip = ip # ) # c.save() print json({"success": True, "container": containerId}) return json({"success": True, "container": containerId}) else: return redirect(url_for(Containers.add))
def _login(next=None): from uliweb import request, Redirect, url_for if not request.user: path = functions.request_url() Redirect(next or url_for('login', next=path))
def _get_url(self, action, **kwargs): return url_for('.'.join([self.__class__.__module__, self.__class__.__name__, action]), **kwargs)
def _login(next=None): from uliweb import request, Redirect, url_for if not request.user: path = request.url Redirect(next or url_for('login', next=path))
def stop(self, id): self.client.stop(container=id) return redirect(url_for(Containers.index))
def has_login(next=None): from uliweb import request, redirect, url_for if not request.user: path = request.url return redirect(next or url_for('login', next=path))
def _get_url(self, action, **kwargs): return url_for( '.'.join( [self.__class__.__module__, self.__class__.__name__, action]), **kwargs)
def _convert_name(self, value, data): return u'<a href="{}">{}</a>'.format(url_for(self.view, id=data.id), value)