示例#1
0
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__())
示例#2
0
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__())
示例#3
0
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__())
示例#4
0
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__())
示例#5
0
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)
示例#6
0
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__())
示例#7
0
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)
示例#8
0
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__())
示例#9
0
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__())
示例#10
0
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)
示例#11
0
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)
示例#12
0
 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)
示例#13
0
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__())
示例#14
0
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)
示例#15
0
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'])
示例#16
0
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'])
示例#17
0
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__())
示例#18
0
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__())
示例#19
0
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__())