Esempio n. 1
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__())
Esempio n. 2
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__())
Esempio n. 3
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__())
Esempio n. 4
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__())
Esempio n. 5
0
def networkInfo(name):
    bridgeNet = BridgeNetwork()
    mainConfig = bridgeNet.get_lxd_main_bridge_config(name)
    if mainConfig['error']:
        return response.replyFailed(message=mainConfig['message'])

    return response.replySuccess(mainConfig['result'])
Esempio n. 6
0
def networkInfo(name):
    network = LXCNetwork({'name': name})
    mainConfig = network.info()
    if mainConfig['error']:
        return response.replyFailed(message=mainConfig['message'])

    return response.replySuccess(mainConfig['result'])
Esempio n. 7
0
def snapshotInfo(name, container):
    print(name)
    try:
        snapshot = LXCSnapshot({'container': container, 'name': name})
        return response.replySuccess(snapshot.snapshotInfo())
    except ValueError as e:
        return response.replyFailed(message=e.__str__())
Esempio n. 8
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__())
Esempio n. 9
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__())
Esempio n. 10
0
def delete(fingerprint):
    try:
        image = LXCImage({'fingerprint': fingerprint})
        return response.replySuccess(
            image.deleteImage(),
            message='Image {} deleted successfully.'.format(fingerprint))
    except ValueError as e:
        return response.replyFailed(message=e.__str__())
Esempio n. 11
0
def delete_profile(name):
    try:
        profile = LXCProfile({'name': name})
        profile.deleteProfile()
        return response.replySuccess(
            data=None, message='Profile {} deleted successfully.'.format(name))
    except ValueError as ex:
        return response.replyFailed(message=ex.__str__())
Esempio n. 12
0
def delete_storage_pool(name):
    try:
        storagePool = LXCStoragePool({'name': name})
        storagePool.deleteStoragePool()
        return response.replySuccess(
            data=None,
            message='Storage Pool {} deleted successfully.'.format(name))
    except ValueError as ex:
        return response.replyFailed(message=ex.__str__())
Esempio n. 13
0
def remoteDetails():
    try:
        alias = ''
        args = request.args
        if args['alias']:
            alias = args['alias']
        client = LXDModule()
        return response.replySuccess(client.detailsRemoteImage(alias))
    except ValueError as e:
        return response.replyFailed(message=e.__str__())
Esempio n. 14
0
def downloadImage():
    input = request.get_json(silent=True)
    validation = doValidate(input)
    if validation:
        return response.replyFailed(message=validation.message)
    try:
        client = LXDModule()
        return response.replySuccess(client.downloadImage(input.get('image')))
    except ValueError as e:
        return response.replyFailed(message=e.__str__())
Esempio n. 15
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__())
Esempio n. 16
0
def createSnapshot(name, container):
    try:
        input = request.get_json(silent=True)
        stateful = False
        if input != None:
            if input.get('stateful') != None:
                stateful = input.get('stateful')

        snapshot = LXCSnapshot({'name': name, 'container': container})
        return response.replySuccess(snapshot.snapshot(stateful), message='Snapshot {} for container {} created successfully.'.format(name, container))
    except ValueError as e:
        return response.replyFailed(message=e.__str__())
Esempio n. 17
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
    network = LXCNetwork({'name': name})
    network.createNetwork(input, name)

    mainConfig = network.info()
    return response.replySuccess(mainConfig['result'])
Esempio n. 18
0
def createContainerSnapshot(name, container):
    input = request.get_json(silent=True)
    validation = doValidateCloneMove(input)
    if validation:
        return response.reply(message=validation.message, status=403)

    input['name'] = name
    input['container'] = container
    try:
        snapshot = LXCSnapshot(input)
        return response.replySuccess(snapshot.snapshotCreateContainer(), message='Container {} created from {} snapshot successfully.'.format(input['newContainer'], name))
    except ValueError as e:
        return response.replyFailed(message=e.__str__())
Esempio n. 19
0
def update_profile(name):
    data = request.get_json()
    data['name'] = name
    validation = doValidate(data)
    if validation:
        return response.replyFailed(message=validation.message)
    try:
        profile = LXCProfile(data)
        return response.replySuccess(
            profile.updateProfile(),
            message='Profile {} updated successfully.'.format(name))
    except ValueError as ex:
        return response.replyFailed(message=ex.__str__())
Esempio n. 20
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__())
Esempio n. 21
0
def create_profile():
    input = request.get_json(silent=True)
    validation = doValidate(input)
    if validation:
        return response.replyFailed(message=validation.message)

    try:
        profile = LXCProfile(input)
        return response.replySuccess(
            profile.createProfile(),
            message='Profile {} created successfully.'.format(
                input.get('name')))
    except ValueError as ex:
        return response.replyFailed(ex.__str__())
Esempio n. 22
0
def create_storage_pool():
    input = request.get_json(silent=True)
    validation = doValidate(input)
    if validation:
        return response.replyFailed(message=validation.message)

    try:
        storagePool = LXCStoragePool(input)
        return response.replySuccess(
            storagePool.createStoragePool(),
            message='Storage Pool {} created successfully.'.format(
                input.get('name')))
    except ValueError as ex:
        return response.replyFailed(ex.__str__())
Esempio n. 23
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'])
Esempio n. 24
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'])
Esempio n. 25
0
def containerSnapshots(container):
    try:
        snapshot = LXCSnapshot({'container': container})
        return response.replySuccess(snapshot.snapshotList())
    except ValueError as e:
        return response.replyFailed(message=e.__str__())
Esempio n. 26
0
def network():
    try:
        client = LXDModule()
        return response.replySuccess(client.listNetworks())
    except ValueError as e:
        return response.replyFailed(message=e.__str__())
Esempio n. 27
0
def deleteNetwork(name):
    bridgeNet = BridgeNetwork()
    bridgeNet.delete_network(name)

    client = LXDModule()
    return response.replySuccess(client.listNetworks())
Esempio n. 28
0
def restoreSnapshot(name, container):
    try:
        snapshot = LXCSnapshot({'name': name, 'container': container})
        return response.replySuccess(snapshot.snapshotRestore(), message='Container {} restored from  snapshot {} successfully.'.format(container, name))
    except ValueError as e:
        return response.replyFailed(message=e.__str__())
Esempio n. 29
0
def publishSnapshot(name, container):
    try:
        snapshot = LXCSnapshot({'name': name, 'container': container})
        return response.replySuccess(snapshot.snapshotPublish(), message='Container {} published from {} snapshot successfully.'.format(container, name))
    except ValueError as e:
        return response.replyFailed(message=e.__str__())
Esempio n. 30
0
def deleteSnapshot(name, container):
    try:
        snapshot = LXCSnapshot({'name': name, 'container': container})
        return response.replySuccess(snapshot.snapshotDelete(), message='Snapshot {} deleted successfully from container.'.format(name, container))
    except ValueError as e:
        return response.replyFailed(message=e.__str__())