def addProxy(name, proxy): input = request.get_json(silent=True) try: container = LXCContainer({'name': name}) return response.replySuccess(container.addProxy(proxy, input)) except ValueError as e: return response.replyFailed(message=e.__str__())
def startContainer(name): try: container = LXCContainer({'name': name}) container.start() return response.replySuccess(container.info()) except ValueError as e: return response.replyFailed(message=e.__str__())
def restartContainer(name): try: container = LXCContainer({'name': name}) container.restart() return response.replySuccess(container.info(), message='Container {} restarted successfully.'.format(name)) except ValueError as e: return response.replyFailed(message=e.__str__())
def unfreezeContainer(name): try: container = LXCContainer({'name': name}) container.unfreeze() return response.replySuccess(container.info(), message='Container {} is unfrozen.'.format(name)) except ValueError as e: return response.replyFailed(message=e.__str__())
def containers(): client = LXDModule() result = [] containers = client.listContainers() for container in containers: c = LXCContainer({'name': container.get('name')}) result.append(c.info()) return response.reply(result)
def deleteContainer(name): input = request.get_json(silent=True) force = False if input == None else input.get('force') try: container = LXCContainer({'name': name}) container.delete(force) return response.reply(None) except ValueError as ex: return response.replyFailed(message=ex.__str__())
def updateContainer(): input = request.get_json(silent=True) validation = doValidate(input) if validation: return response.reply(message=validation.message, status=403) try: client = LXCContainer(input) return response.reply(client.update()) except ValueError as ex: return response.reply(message=ex.__str__(), status=403)
def moveContainer(name): input = request.get_json(silent=True) validation = doValidateCloneMove(input) if validation: return response.reply(message=validation.message, status=403) input['name'] = name try: container = LXCContainer(input) return response.replySuccess(container.move()) except ValueError as e: return response.replyFailed(message=e.__str__())
def exportContainer(name): input = request.get_json(silent=True) validation = doValidateImageExport(input) if validation: return response.reply(message=validation.message, status=403) force = False if input.get('force') == None else input.get('force') input['name'] = name try: container = LXCContainer(input) return response.replySuccess(container.export(force)) except ValueError as e: return response.replyFailed(message=e.__str__())
def containerDetails(name): try: container = LXCContainer({'name': name}) return render_template('container-details.html', currentpage='Container Details', container=container.info(), profiles = getProfiles(), lxdui_current_version=VERSION) except ValueError as ex: return render_template('container-details.html', currentpage='Container Details', container=None, name=name, message=ex.__str__(), lxdui_current_version=VERSION)
def createContainer(): input = request.get_json(silent=True) validation = doValidate(input) if validation: return response.reply(message=validation.message, status=403) input = [input] if not isinstance(input, list) else input try: result = [] for container in input: client = LXCContainer(container) result.append(client.create()) return response.reply(result) except ValueError as ex: return response.reply(message=ex.__str__(), status=403)
def get(self, name='new', token=None): if not checkAuthentication(token): raise tornado.web.HTTPError(403) shellType = findShellTypeOfContainer(LXCContainer({'name': name})) shell = [ 'bash', '-c', 'lxc exec {} -- /bin/{}'.format(name, shellType) ] name, terminal = self.application.settings[ 'term_manager'].new_named_terminal(shell_command=shell) self.redirect("/terminal/open/" + name + '/' + token, permanent=False)
def stopContainer(name): try: container = LXCContainer({'name': name}) ephemeral = container.info()['ephemeral'] container.stop() if ephemeral: return response.replySuccess(container.info(), message='Container {} stopped successfully.'.format(name)) return response.replySuccess(container.info(), message='Container {} stopped successfully.'.format(name)) except ValueError as e: return response.replyFailed(message=e.__str__())
def container(): try: containers = LXDModule().listContainers() result = [] for container in containers: c = LXCContainer({'name': container.get('name')}) result.append(c.info()) images = LXDModule().listLocalImages() profiles = LXDModule().listProfiles() return render_template('containers.html', currentpage='Containers', containers=result, images = images, profiles = profiles, memory=memory(), lxdui_current_version=VERSION) except: return render_template('containers.html', currentpage='Containers', containers=[], images=[], profiles=[], memory=memory(), lxdui_current_version=VERSION)
def creatNetwork(name): input = request.get_json(silent=True) validation = doValidate(input) if validation: return response.replyFailed(message=validation.message) input['IPv6_ENABLED'] = False bridgeNet = BridgeNetwork() lxcTask = bridgeNet._form_to_LXC_SET_TASK(input) bridgeNet._execute_LXC_NETWORK_TERMINAL(lxcTask, name) mainConfig = bridgeNet.get_lxd_main_bridge_config(name) for container in mainConfig['used_by']: LXCContainer({'name': container}).restart() return response.replySuccess(mainConfig['result'])
def updateNetwork(name): input = request.get_json(silent=True) validation = doValidate(input) if validation: return response.replyFailed(message=validation.message) input['IPv6_ENABLED'] = False network = LXCNetwork({'name': name}) network.updateNetwork(input, name) mainConfig = network.info() for container in mainConfig['used_by']: LXCContainer({'name': container}).restart() return response.replySuccess(mainConfig['result'])
def stopContainer(name): try: container = LXCContainer({'name': name}) ephemeral = container.info()['ephemeral'] container.stop() if ephemeral: return response.replySuccess(data={}, message='success') return response.replySuccess(container.info()) except ValueError as e: return response.replyFailed(message=e.__str__())
def removeNetwork(name, network): try: container = LXCContainer({'name': name}) return response.replySuccess(container.removeNetwork(network)) except ValueError as e: return response.replyFailed(message=e.__str__())
def removeProxy(name, proxy): try: container = LXCContainer({'name': name}) return response.replySuccess(container.removeProxy(proxy)) except ValueError as e: return response.replyFailed(message=e.__str__())