コード例 #1
0
    def handle_api_fstab(self, http_context):

        if http_context.method == 'GET':
            self.fstab_config = FSTabConfig(path='/etc/fstab')
            self.fstab_config.load()
            return self.fstab_config.tree.to_dict()

        if http_context.method == 'POST':
            config = http_context.json_body()['config']
            new_fstab = FSTabConfig(content='')
            new_fstab.load()

            for filesystem in config:
                device = FilesystemData()
                for property, value in filesystem.items():
                    setattr(device, property, value)
                new_fstab.tree.filesystems.append(device)

            data = new_fstab.save()[None]

            # Always make a backup
            os.rename('/etc/fstab', '/etc/fstab.bak')

            try:
                with open('/etc/fstab', 'w') as f:
                    f.write(data)
                return True
            except Exception as e:
                raise EndpointError(e)
コード例 #2
0
ファイル: views.py プロジェクト: Mu-L/ajenti
    def handle_api_set_fstab(self, http_context):
        """
        Write the fstab file.
        Make a backup when save a new fstab file.

        :param http_context: HttpContext
        :type http_context: HttpContext
        :return: Success or not
        :rtype: bool or throw error in save mode
        """

        config = http_context.json_body()['config']
        new_fstab = FSTabConfig(content='')
        new_fstab.load()

        for filesystem in config:
            device = FilesystemData()
            for prop, value in filesystem.items():
                setattr(device, prop, value)
            new_fstab.tree.filesystems.append(device)

        data = new_fstab.save()[None]

        # Always make a backup
        os.rename('/etc/fstab', '/etc/fstab.bak')

        try:
            with open('/etc/fstab', 'w') as f:
                f.write(data)
            return True
        except Exception as e:
            raise EndpointError(e)
コード例 #3
0
ファイル: main.py プロジェクト: rockworldmi/ajenti
    def init(self):
        self.title = 'Filesystems'
        self.icon = 'hdd'
        self.category = 'System'
        self.append(self.ui.inflate('fstab:main'))

        self.find('type').labels = [
            'Auto', 'EXT2', 'EXT3', 'EXT4', 'NTFS', 'FAT', 'ZFS', 'ReiserFS',
            'Samba', 'None', 'Loop'
        ]
        self.find('type').values = [
            'auto', 'ext2', 'ext3', 'ext4', 'ntfs', 'vfat', 'zfs', 'reiser',
            'smb', 'none', 'loop'
        ]

        self.fstab_config = FSTabConfig(path='/etc/fstab')
        self.mounts = MountsBackend.get()

        self.binder = Binder(None, self)
        self.find('fstab').find(
            'filesystems').new_item = lambda c: FilesystemData()

        def post_mount_bind(object, collection, item, ui):
            ui.find('umount').on('click', self.on_umount, item)

        self.find('mounts').find(
            'filesystems').post_item_bind = post_mount_bind
コード例 #4
0
ファイル: views.py プロジェクト: starnetwork/ajenti
    def handle_api_fstab(self, http_context):
        """
        Load (through get) and write (through post) the fstab file.
        Make a backup when save a new fstab file.
        Method GET.
        Method POST.

        :param http_context: HttpContext
        :type http_context: HttpContext
        :return: Fstab as dict in load mode, success or not in save mode
        :rtype: dict in load mode, bool or throw error in save mode
        """

        if http_context.method == 'GET':
            self.fstab_config = FSTabConfig(path='/etc/fstab')
            self.fstab_config.load()
            return self.fstab_config.tree.to_dict()

        if http_context.method == 'POST':
            config = http_context.json_body()['config']
            new_fstab = FSTabConfig(content='')
            new_fstab.load()

            for filesystem in config:
                device = FilesystemData()
                for prop, value in filesystem.items():
                    setattr(device, prop, value)
                new_fstab.tree.filesystems.append(device)

            data = new_fstab.save()[None]

            # Always make a backup
            os.rename('/etc/fstab', '/etc/fstab.bak')

            try:
                with open('/etc/fstab', 'w') as f:
                    f.write(data)
                return True
            except Exception as e:
                raise EndpointError(e)
コード例 #5
0
ファイル: views.py プロジェクト: Mu-L/ajenti
    def handle_api_get_fstab(self, http_context):
        """
        Load the fstab file.

        :param http_context: HttpContext
        :type http_context: HttpContext
        :return: Fstab as dict
        :rtype: dict in load mode
        """

        self.fstab_config = FSTabConfig(path='/etc/fstab')
        self.fstab_config.load()
        return self.fstab_config.tree.to_dict()
コード例 #6
0
import os
import reconfigure

from reconfigure.configs import FSTabConfig
from reconfigure.items.fstab import FilesystemData
from functions import printScript
from functions import subProc

title = os.path.basename(__file__).replace('.py', '').split('_')[1]
logfile = constants.LOGDIR + '/setup.' + title + '.log'

printScript('', 'begin')
printScript(title)

# patch fstab with mount options
config = FSTabConfig(path='/etc/fstab')
config.load()
c = 0
mountpoints = ['/', '/srv']
while True:
    # try all fstab entries
    try:
        for i in mountpoints:
            # if mountpoint matches change mount options
            if config.tree.filesystems[c].mountpoint == i:
                msg = 'Modifying mount options for ' + i + ' '
                printScript(msg, '', False, False, True)
                try:
                    # get mount options from constants
                    config.tree.filesystems[c].options = constants.ROOTMNTOPTS
                    # save fstab