示例#1
0
def generate_partition(type_or_name, partition_dict):
    fs_dict = partition_dict.get('file_system')

    if fs_dict:
        fs_object = generate_file_system(fs_dict)
        LOG.debug('Adding %s file system' % fs_object)
    else:
        fs_object = None

    mount_point = partition_dict.get('mount_point')

    if fs_object:
        fsck_option = fsck_pass(fs_object, partition_dict, mount_point)
    else:
        fsck_option = False

    p = Partition(
        type_or_name=type_or_name,
        size_or_percent=generate_size(partition_dict['size']),
        flags=partition_dict.get('flags', []),
        file_system=fs_object,
        mount_point=mount_point,
        fsck_option=fsck_option)

    if 'lvm' in p.flags:
        # We need to preserve this mapping for generating volume groups
        __pv_linker__[partition_dict['name']] = p

    # For software RAID, we need an index to rendered partition objects
    __partition_linker__[partition_dict['name']] = p

    return p
示例#2
0
from press.models.partition import PartitionTableModel
from press.layout import EXT4, Partition, PercentString, Layout, SWAP
from press.layout.lvm import LogicalVolume, PhysicalVolume

from press.logger import setup_logging

import logging
setup_logging()

log = logging.getLogger(__name__)

disk = '/dev/loop0'

p1 = Partition('primary',
               '2GiB',
               file_system=EXT4('BOOT'),
               flags=['boot'],
               mount_point='/boot',
               fsck_option=2)
p2 = Partition('primary',
               '512MiB',
               file_system=SWAP('SWAP'),
               mount_point='swap')
p3 = Partition('primary',
               '512MiB',
               file_system=EXT4(
                   'TMP',
                   mount_options=['defaults', 'nosuid', 'noexec', 'nodev']),
               mount_point='/tmp',
               fsck_option=2)
p4 = Partition('primary', PercentString('100%FREE'), flags=['lvm'])
示例#3
0
from press.models.lvm import VolumeGroupModel
from press.models.partition import PartitionTableModel
from press.layout import EXT4, Partition, PercentString, Layout, SWAP
from press.layout.lvm import LogicalVolume, PhysicalVolume

from press.logger import setup_logging

import logging
setup_logging()

log = logging.getLogger(__name__)

disk = '/dev/loop0'

p1 = Partition('primary', '1MiB', mount_point='/boot')
p2 = Partition('primary', '1MiB')
p3 = Partition('primary', '512MiB')

p4 = Partition('logical', PercentString('100%FREE'))

pm1 = PartitionTableModel('msdos', disk=disk)

pm1.add_partitions([p1, p2, p3, p4])

log.debug(pm1.allocated_space)

l1 = Layout(loop_only=True)

l1.add_partition_table_from_model(pm1)

log.debug(l1.disks)
示例#4
0
s2 = Size('1.5GiB')
print s2.bytes
print s2.humanize

s3 = Size(14)

s4 = s2 + s3
print s4.bytes


disk = Disk('/dev/loop0', size='20GiB')
table1 = PartitionTable('gpt', size=disk.size.bytes)
disk.partition_table = table1

ext4 = EXT4('BOOT')
p1 = Partition('primary', '4GiB', file_system=ext4)
p2 = Partition('logical', PercentString('25%FREE'), file_system=ext4)

table1.add_partition(p1)
table1.add_partition(p2)

print table1.current_usage
print table1.free_space

print table1

print table1.partitions[1].size.bytes
print disk.partition_table.partitions[1].size.bytes

layout = Layout(loop_only=True)
示例#5
0
from press.models.partition import PartitionTableModel
from press.layout import EXT4, Partition, PercentString, Size, Layout, SWAP
from press.logger import setup_logging

import logging
setup_logging()

log = logging.getLogger(__name__)

disk = '/dev/loop0'

p1 = Partition('primary',
               PercentString('100%FREE'),
               file_system=EXT4('ROOT'),
               mount_point='/')

pm1 = PartitionTableModel('msdos', disk=disk)

pm1.add_partition(p1)

log.debug(pm1.allocated_space)

l1 = Layout(loop_only=True)

l1.add_partition_table_from_model(pm1)

log.debug(l1.disks)
log.debug(l1.disks[disk].partition_table)

l1.apply()
log.info('Apply completed!')
示例#6
0
from press.layout import Partition
from press.layout.filesystems.extended import EXT4
from press.layout.lvm import PhysicalVolume, VolumeGroup, LogicalVolume
from press.logger import setup_logging

from size import PercentString

import logging
setup_logging()

log = logging.getLogger(__name__)
partition = Partition('logical', size_or_percent='511MiB', lvm=True)
partition.devname = '/dev/loop0p5'
pv1 = PhysicalVolume(partition)

vg1 = VolumeGroup('vg_test', [pv1])

lv1 = LogicalVolume('lv_test1', '100MiB', EXT4('LVM'), mount_point='/lvm')
lv2 = LogicalVolume('lv_test2', PercentString('20%FREE'))
lv3 = LogicalVolume('lv_test3', PercentString('100%FREE'))

vg1.add_logical_volumes([lv1, lv2, lv3])

print(vg1)
示例#7
0
except:
    print('Please pass a path to a configuration file to run.')
    print(
        "ex. python2.7 doc/examples/end_to_end_test.py configuration/debian7.yaml"
    )
    sys.exit()

setup_logging()

log = logging.getLogger(__name__)

disk = '/dev/sda'

p1 = Partition('primary',
               '250MiB',
               file_system=EXT4('BOOT'),
               boot=True,
               mount_point='/boot')
p2 = Partition('primary', '512MiB', file_system=SWAP('SWAP'))
p3 = Partition('logical', '512MiB', file_system=EXT4(), mount_point='/tmp')
p4 = Partition('logical',
               PercentString('85%FREE'),
               file_system=EXT4('ROOT'),
               mount_point='/')

pm1 = PartitionTableModel('msdos', disk=disk)

pm1.add_partitions([p1, p2, p3, p4])

log.debug(pm1.allocated_space)