-#!/usr/bin/python
#
# Copyright (c) 2003 Intel Corporation
# All rights reserved.
def Run(vars, log):
"""
Setup the block devices for install, partition them w/ LVM
-
+
Expect the following variables from the store:
INSTALL_BLOCK_DEVICES list of block devices to install onto
TEMP_PATH somewhere to store what we need to run
"""
log.write("\n\nStep: Install: partitioning disks.\n")
-
+
# make sure we have the variables we need
try:
TEMP_PATH = vars["TEMP_PATH"]
bs_request = BootServerRequest.BootServerRequest(vars)
-
+
# disable swap if its on
utils.sysexec_noerr("swapoff {}".format(PARTITIONS["swap"]), log)
# shutdown and remove any lvm groups/volumes
utils.sysexec_noerr("vgscan", log)
- utils.sysexec_noerr("vgchange -ay", log)
+ utils.sysexec_noerr("vgchange -ay", log)
utils.sysexec_noerr("lvremove -f {}".format(PARTITIONS["root"]), log)
utils.sysexec_noerr("lvremove -f {}".format(PARTITIONS["swap"]), log)
utils.sysexec_noerr("lvremove -f {}".format(PARTITIONS["vservers"]), log)
log.write("Running vgscan for devices\n")
utils.sysexec_noerr("vgscan", log)
-
+
used_devices = []
INSTALL_BLOCK_DEVICES.sort()
used_devices.append(device)
log.write("Successfully initialized {}\n".format(device))
else:
- log.write("Unable to partition {], not using it.\n".format(device))
+ log.write("Unable to partition {}, not using it.\n".format(device))
continue
# list of devices to be used with vgcreate
for device in used_devices:
part_path = get_partition_path_from_device(device, vars, log)
partitions.append(part_path)
-
+
# create raid partition
raid_partition = create_raid_partition(partitions, vars, log)
if raid_partition != None:
- partitions = [raid_partition]
- log.write("PARTITIONS {}\n".format(str(partitions)))
+ partitions = [raid_partition]
+ log.write("partitions={}\n".format(partitions))
# initialize the physical volumes
for part_path in partitions:
if not create_lvm_physical_volume(part_path, vars, log):
# check if we want a separate partition for VMs
one_partition = vars['ONE_PARTITION']=='1'
- if (one_partition):
+ if one_partition:
remaining_extents = get_remaining_extents_on_vg(vars, log)
utils.sysexec("lvcreate -l{} -nroot planetlab".format(remaining_extents), log)
else:
if NODE_MODEL_OPTIONS & ModelOptions.BADHD:
option = '-c'
txt = " with bad block search enabled, which may take a while"
-
+
# filesystems partitions names and their corresponding
# reserved-blocks-percentages
- filesystems = {"root":5,"vservers":0}
+ filesystems = {"root": 5, "vservers": 0}
# ROOT filesystem is always with ext2
fs = 'root'
mkfs = "mkfs.btrfs"
if os.system("mkfs.btrfs --help 2>&1 | grep force") == 0:
mkfs += " -f"
- mkfs +=" {}".format(devname)
+ mkfs += " {}".format(devname)
utils.sysexec(mkfs, log)
# as of 2013/02 it looks like there's not yet an option to set fsck frequency with btrfs
# list of block devices used may be updated
vars["INSTALL_BLOCK_DEVICES"] = used_devices
+ utils.display_disks_status(PARTITIONS, "End of InstallPartitionDisks", log)
+
return 1
# two forms, depending on which version of pyparted we have
# v1 does not have a 'version' method
- # v2 and above does, but to make it worse,
+ # v2 and above does, but to make it worse,
# parted-3.4 on f14 has parted.version broken and raises SystemError
try:
parted.version()
- return single_partition_device_2_x (device, vars, log)
+ return single_partition_device_2_x(device, vars, log)
except AttributeError:
# old parted does not have version at all
- return single_partition_device_1_x (device, vars, log)
+ return single_partition_device_1_x(device, vars, log)
except SystemError:
# let's assume this is >=2
- return single_partition_device_2_x (device, vars, log)
+ return single_partition_device_2_x(device, vars, log)
except:
raise
-def single_partition_device_1_x (device, vars, log):
-
+def single_partition_device_1_x(device, vars, log):
+
lvm_flag = parted.partition_flag_get_by_name('lvm')
-
+
try:
log.write("Using pyparted 1.x\n")
# wipe the old partition table
0, 1)
# make it an lvm partition
- new_part.set_flag(lvm_flag,1)
+ new_part.set_flag(lvm_flag, 1)
# actually add the partition to the disk
disk.add_partition(new_part, constraint)
disk.commit()
del disk
-
- except BootManagerException as e:
- log.write("BootManagerException while running: {}\n".format(str(e)))
+
+ except BootManagerException as exc:
+ log.write("BootManagerException while running: {}\n".format(str(exc)))
return 0
- except parted.error as e:
- log.write("parted exception while running: {}\n".format(str(e)))
+ except parted.error as exc:
+ log.write("parted exception while running: {}\n".format(str(exc)))
return 0
-
+
return 1
-def single_partition_device_2_x (device, vars, log):
+def single_partition_device_2_x(device, vars, log):
try:
log.write("Using pyparted 2.x\n")
# Thierry june 2012 -- for disks larger than 2TB
# calling this with part_type='msdos' would fail at the maximizePartition stage
# create a new partition table
- def partition_table (device, part_type, fs_type):
+ def partition_table(device, part_type, fs_type):
# wipe the old partition table
utils.sysexec("dd if=/dev/zero of={} bs=512 count=1".format(device), log)
# get the device
dev = parted.Device(device)
disk = parted.freshDisk(dev, part_type)
# create one big partition on each block device
- constraint = parted.constraint.Constraint (device=dev)
- geometry = parted.geometry.Geometry (device=dev, start=0, end=1)
- fs = parted.filesystem.FileSystem (type=fs_type, geometry=geometry)
- new_part = parted.partition.Partition (disk, type=parted.PARTITION_NORMAL,
+ constraint = parted.constraint.Constraint(device=dev)
+ geometry = parted.geometry.Geometry(device=dev, start=0, end=1)
+ fs = parted.filesystem.FileSystem(type=fs_type, geometry=geometry)
+ new_part = parted.partition.Partition(disk, type=parted.PARTITION_NORMAL,
fs=fs, geometry=geometry)
# make it an lvm partition
new_part.setFlag(parted.PARTITION_LVM)
disk.addPartition(new_part, constraint)
disk.maximizePartition(new_part, constraint)
disk.commit()
- log.write ("Current disk for {} - partition type {}\n{}\n".format(device, part_type, disk))
- log.write ("Current dev for {}\n{}\n".format(device, dev))
+ log.write("Current disk for {} - partition type {}\n{}\n".format(device, part_type, disk))
+ log.write("Current dev for {}\n{}\n".format(device, dev))
del disk
try:
- partition_table (device, 'msdos', 'ext2')
+ partition_table(device, 'msdos', 'ext2')
except:
- partition_table (device, 'gpt', 'ext2')
+ partition_table(device, 'gpt', 'ext2')
except Exception as e:
log.write("Exception inside single_partition_device_2_x : {}\n".format(str(e)))
import traceback
traceback.print_exc(file=log)
return 0
-
+
return 1
def create_raid_partition(partitions, vars, log):
"""
- create raid array using specified partitions.
- """
+ create raid array using specified partitions.
+ """
raid_part = None
raid_enabled = False
node_tags = BootAPI.call_api_function(vars, "GetNodeTags",
lvl = 1
else:
lvl = 5
-
+
# make the array
part_list = " ".join(partitions)
raid_part = "/dev/md0"
log.write("create_raid_partition failed.\n")
raid_part = None
- return raid_part
+ return raid_part
def get_partition_path_from_device(device, vars, log):
"""
return the free amount of extents on the planetlab volume group
"""
-
+
c_stdout, c_stdin = popen2.popen2("vgdisplay -c planetlab")
result = string.strip(c_stdout.readline())
c_stdout.close()
c_stdin.close()
remaining_extents = string.split(result, ":")[15]
-
+
return remaining_extents