示例#1
0
文件: filesystems.py 项目: ns408/core
def list_filesystems():
    """List filesystems"""
    try:
        data = filesystems.get()
        for x in data:
            click.echo(
                click.style(x.id, fg="white", bold=True) +
                click.style(" (" + x.path + ")", fg="green")
            )
            click.echo(
                click.style(" * Type: ", fg="yellow") +
                "{0} {1}".format(
                    "Physical" if isinstance(filesystems.DiskPartition)
                    else "Virtual",
                    x.fstype
                )
            )
            click.echo(
                click.style(" * Size: ", fg="yellow") +
                str_fsize(x.size)
            )
            click.echo(
                click.style(" * Encrypted: ", fg="white") +
                ("Yes" if x.crypt else "No")
            )
            click.echo(
                click.style(" * Mounted: ", fg="yellow") +
                ("At " + x.mountpoint if x.mountpoint else "No")
            )
    except Exception as e:
        raise CLIException(str(e))
示例#2
0
 def put(self, id):
     data = json.loads(request.data)["filesystem"]
     disk = filesystems.get(id)
     if not id or not disk:
         abort(404)
     try:
         if data["operation"] == "mount":
             op = "mounted"
             if disk.mountpoint:
                 abort(400)
             elif disk.crypt and not data.get("passwd"):
                 abort(403)
             elif data.get("mountpoint"):
                 disk.mountpoint = data["mountpoint"]
             disk.mount(data.get("passwd"))
         elif data["operation"] == "umount":
             op = "unmounted"
             disk.umount()
         elif data["operation"] == "enable":
             op = "enabled"
             disk.enable()
         elif data["operation"] == "disable":
             op = "disabled"
             disk.disable()
     except Exception, e:
         resp = jsonify(message="Operation failed: %s" % str(e))
         resp.status_code = 422
         return resp
示例#3
0
文件: filesystems.py 项目: ns408/core
def umount(id):
    """Unmount a filesystem"""
    try:
        fs = filesystems.get(id)
        fs.umount()
        logger.success('ctl:fs:umount', 'Unmounted {0}'.format(id))
    except Exception as e:
        raise CLIException(str(e))
示例#4
0
文件: filesystems.py 项目: ns408/core
def delete(id):
    """Delete a virtual disk"""
    try:
        fs = filesystems.get(id)
        fs.remove()
        logger.success('ctl:fs:delete', 'Deleted {0}'.format(id))
    except Exception as e:
        raise CLIException(str(e))
示例#5
0
文件: filesystems.py 项目: ns408/core
def disable(id):
    """Disable mounting a filesystem on boot"""
    try:
        fs = filesystems.get(id)
        fs.disable()
        logger.success('ctl:fs:disable', 'Disabled {0}'.format(id))
    except Exception as e:
        raise CLIException(str(e))
示例#6
0
文件: filesystems.py 项目: ns408/core
def enable(id):
    """Mount a filesystem on boot"""
    try:
        fs = filesystems.get(id)
        fs.enable()
        logger.success('ctl:fs:enable', 'Enabled {0}'.format(id))
    except Exception as e:
        raise CLIException(str(e))
示例#7
0
 def get(self, id):
     disks = filesystems.get(id)
     if id and not disks:
         abort(404)
     if type(disks) == list:
         return jsonify(filesystems=[x.as_dict() for x in disks])
     else:
         return jsonify(filesystem=disks.as_dict())
示例#8
0
def firstrun():
    data = request.get_json()
    resize_boards = [
        "Raspberry Pi", "Raspberry Pi 2", "Raspberry Pi 3", "Cubieboard2",
        "Cubietruck", "BeagleBone Black", "ODROID-U"
    ]
    if data.get("resize_sd_card", None)\
            and config.get("enviro", "board") in resize_boards:
        part = 1 if config.get("enviro", "board").startswith("Cubie") else 2
        p1str = 'd\nn\np\n1\n\n\nw\n'
        p2str = 'd\n2\nn\np\n2\n\n\nw\n'
        shell('fdisk /dev/mmcblk0', stdin=(p1str if part == 1 else p2str))
        if not os.path.exists('/etc/cron.d'):
            os.mkdir('/etc/cron.d')
        with open('/etc/cron.d/resize', 'w') as f:
            f.write('@reboot root e2fsck -fy /dev/mmcblk0p{0}\n'.format(part))
            f.write('@reboot root resize2fs /dev/mmcblk0p{0}\n'.format(part))
            f.write('@reboot root rm /etc/cron.d/resize\n')
            f.close()
    if data.get("use_gpu_mem", None) \
            and config.get("enviro", "board").startswith("Raspberry"):
        f = filesystems.get("mmcblk0p1")
        if not f.is_mounted:
            f.mountpoint = "/boot"
            f.mount()
        cfgdata = []
        if os.path.exists('/boot/config.txt'):
            with open("/boot/config.txt", "r") as f:
                for x in f.readlines():
                    if x.startswith("gpu_mem"):
                        x = "gpu_mem=16\n"
                    cfgdata.append(x)
                if "gpu_mem=16\n" not in cfgdata:
                    cfgdata.append("gpu_mem=16\n")
            with open("/boot/config.txt", "w") as f:
                f.writelines(cfgdata)
        else:
            with open("/boot/config.txt", "w") as f:
                f.write("gpu_mem=16\n")
    if data.get("cubie_mac", None) \
            and config.get("enviro", "board").startswith("Cubie"):
        if config.get("enviro", "board") == "Cubieboard2":
            with open('/boot/uEnv.txt', 'w') as f:
                opt_str = 'extraargs=mac_addr={0}\n'
                f.write(opt_str.format(data.get("cubie_mac")))
        elif config.get("enviro", "board") == "Cubietruck":
            with open('/etc/modprobe.d/gmac.conf', 'w') as f:
                opt_str = 'options sunxi_gmac mac_str="{0}"\n'
                f.write(opt_str.format(data.get("cubie_mac")))
    if data.get("install"):
        as_job(install, data["install"])
    rootpwd = ""
    if data.get("protectRoot"):
        rootpwd = random_string(16)
        shell("passwd root", stdin="{0}\n{0}\n".format(rootpwd))
    security.initialize_firewall()
    return jsonify(rootpwd=rootpwd)
示例#9
0
 def get(self, id):
     disks = filesystems.get(id)
     if id and not disks:
         abort(404)
     if isinstance(
             disks, (filesystems.VirtualDisk, filesystems.DiskPartition)):
         return jsonify(filesystem=disks.serialized)
     else:
         return jsonify(filesystems=[x.serialized for x in disks])
示例#10
0
文件: filesystems.py 项目: ns408/core
def mount(id, password):
    """Mount a filesystem"""
    try:
        fs = filesystems.get(id)
        if fs.crypt and not password:
            password = click.prompt(
                "Please enter your password to mount this filesystem",
                hide_input=True)
        fs.mount(password)
        logger.success('ctl:fs:mount', 'Mounted {0}'.format(id))
    except Exception as e:
        raise CLIException(str(e))
示例#11
0
 def put(self, id):
     data = request.get_json()["filesystem"]
     disk = filesystems.get(id)
     if not id or not disk:
         abort(404)
     try:
         if data["operation"] == "mount":
             if disk.mountpoint:
                 abort(400)
             elif disk.crypt and not data.get("passwd"):
                 abort(403)
             elif data.get("mountpoint"):
                 disk.mountpoint = data["mountpoint"]
             disk.mount(data.get("passwd"))
         elif data["operation"] == "umount":
             disk.umount()
         elif data["operation"] == "enable":
             disk.enable()
         elif data["operation"] == "disable":
             disk.disable()
     except Exception as e:
         logger.error("Filesystems", str(e))
         return jsonify(errors={"msg": str(e)}), 500
     return jsonify(filesystem=disk.serialized)
示例#12
0
 def delete(self, id):
     disk = filesystems.get(id)
     if not id or not disk:
         abort(404)
     disk.remove()
     return Response(status=204)
示例#13
0
 def delete(self, id):
     disk = filesystems.get(id)
     if not id or not disk:
         abort(404)
     disk.remove()
     return Response(status=204)