Beispiel #1
0
def list(name):
    path = request.args.get('path')
    if path == None:
        return jsonify([])
        #return response.replyFailed('Path is missing')

    input = {}
    input['name'] = name
    input['path'] = path

    try:
        fileManager = LXCFileManager(input)
        try:
            results = []
            #Folder
            items = json.loads(fileManager.download().decode('utf-8'))['metadata']
            for item in items:
                input['path'] = path + '/' + item
                results.append({
                    'title': item,
                    'key': item,
                    'folder': isFolder(LXCFileManager(input)),
                    'lazy': isFolder(LXCFileManager(input)),
                })

            return jsonify(results)
            return response.reply(results)
        except:
            #File
            return jsonify([])
            return response.replyFailed('Please enter a valid directory path')
            #result = fileManager.download()

    except ValueError as ex:
        return response.replyFailed(ex.__str__())
Beispiel #2
0
def download_file(name):
    path = request.args.get('path')
    token = request.args.get('token')
    print (token)
    if not checkAuthentication(token):
        return response.replyFailed('Not authorized')

    if path == None:
        return jsonify([])

    input = {}
    input['name'] = name
    input['path'] = path

    try:
        try:
            #Folder
            fileManager = LXCFileManager(input)
            items = json.loads(fileManager.download().decode('utf-8'))['metadata']
            return response.replyFailed('Please select a file for download')
        except:
            #File
            fileManager = LXCFileManager(input)
            file = io.BytesIO(fileManager.download())
            return send_file(file, attachment_filename=path.rsplit("/").pop(), mimetype="application/octet-stream", as_attachment=True)

    except ValueError as ex:
        return response.replyFailed(ex.__str__())
Beispiel #3
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__())
Beispiel #4
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.reply(profile.updateProfile())
    except ValueError as ex:
        return response.replyFailed(message=ex.__str__())
Beispiel #5
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 jsonify(profile.createProfile())
    except ValueError as ex:
        return response.replyFailed(ex.__str__())
Beispiel #6
0
def update_storage_pool(name):
    data = request.get_json()
    data['name'] = name
    validation = doValidate(data)
    if validation:
        return response.replyFailed(message=validation.message)
    try:
        storagePool = LXCStoragePool(data)
        return response.replySuccess(
            storagePool.updateProfile(),
            message='Storage Pool {} updated successfully.'.format(name))
    except ValueError as ex:
        return response.replyFailed(message=ex.__str__())
Beispiel #7
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__())
Beispiel #8
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__())
Beispiel #9
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__())
Beispiel #10
0
def delete_profile(name):
    try:
        profile = LXCProfile({'name': name})
        profile.deleteProfile()
        return response.reply()
    except ValueError as ex:
        return response.replyFailed(message=ex.__str__())
Beispiel #11
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__())
Beispiel #12
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__())
Beispiel #13
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'])
Beispiel #14
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__())
Beispiel #15
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'])
Beispiel #16
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__())
Beispiel #17
0
def upload_file(name):
    input = None
    try:
        file = request.files.get('file')
        input = {
            'name':name,
            'path':request.form.get('path')+file.filename,
            'file':file
        }
    except:
        return  response.replyFailed(message='Missing one the required fields: [path,file]')

    try:
        fileManager = LXCFileManager(input)
        return response.reply(fileManager.push())
    except ValueError as ex:
        return response.replyFailed(ex.__str__())
Beispiel #18
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__())
Beispiel #19
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__())
Beispiel #20
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__())
Beispiel #21
0
def download(name):
    input = request.get_json(silent=True)
    input['name'] = name

    try:
        fileManager = LXCFileManager(input)
        return response.reply(fileManager.download())
    except ValueError as ex:
        return response.replyFailed(ex.__str__())
Beispiel #22
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__())
Beispiel #23
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__())
Beispiel #24
0
def networks():
    try:
        client = LXDModule()
        return jsonify({
            'status': 200,
            'message': 'ok',
            'data': client.listNetworks()
        })
    except ValueError as e:
        return response.replyFailed(message=e.__str__())
Beispiel #25
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__())
Beispiel #26
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__())
Beispiel #27
0
def edit_file(name):
    input = request.get_json(silent=True)

    input['name'] = name

    try:
        fileManager = LXCFileManager(input)
        fileManager.delete()
        return response.reply(fileManager.push())
    except ValueError as ex:
        return response.replyFailed(ex.__str__())
Beispiel #28
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__())
Beispiel #29
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'])
Beispiel #30
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__())