|
|
@ -29,10 +29,11 @@ from calculate.lib.datavars import (TableVariable, Variable, VariableError,
|
|
|
|
ReadonlyVariable, ReadonlyTableVariable,
|
|
|
|
ReadonlyVariable, ReadonlyTableVariable,
|
|
|
|
SourceReadonlyVariable, VariableInterface,
|
|
|
|
SourceReadonlyVariable, VariableInterface,
|
|
|
|
HumanReadable)
|
|
|
|
HumanReadable)
|
|
|
|
|
|
|
|
import calculate.lib.utils.device as device
|
|
|
|
from calculate.lib.utils.device import (getDeviceType,
|
|
|
|
from calculate.lib.utils.device import (getDeviceType,
|
|
|
|
getPartitionType, getPartitionDevice,
|
|
|
|
getPartitionType, getPartitionDevice,
|
|
|
|
raid, lvm, getPartitionSize,
|
|
|
|
getPartitionSize,
|
|
|
|
humanreadableSize, udev, sysfs,
|
|
|
|
humanreadableSize,
|
|
|
|
getUUIDDict, getCommonDeviceName)
|
|
|
|
getUUIDDict, getCommonDeviceName)
|
|
|
|
from calculate.install.variables.autopartition import Sizes
|
|
|
|
from calculate.install.variables.autopartition import Sizes
|
|
|
|
from calculate.lib.utils.files import (listDirectory, pathJoin, readFile,
|
|
|
|
from calculate.lib.utils.files import (listDirectory, pathJoin, readFile,
|
|
|
@ -53,27 +54,27 @@ class DeviceHelper(VariableInterface):
|
|
|
|
def getBlockDevices(self):
|
|
|
|
def getBlockDevices(self):
|
|
|
|
"""Get interest devices from sys block path"""
|
|
|
|
"""Get interest devices from sys block path"""
|
|
|
|
return filter(self.rePassDevice.search,
|
|
|
|
return filter(self.rePassDevice.search,
|
|
|
|
udev.get_block_devices())
|
|
|
|
device.udev.get_block_devices())
|
|
|
|
|
|
|
|
|
|
|
|
def separateDevice(self, device):
|
|
|
|
def separateDevice(self, dev):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Separate device word and number on tuple
|
|
|
|
Separate device word and number on tuple
|
|
|
|
|
|
|
|
|
|
|
|
Using for sort. (Example: sda2 ("sda",2), md5p1 ("md",5,"p",1)
|
|
|
|
Using for sort. (Example: sda2 ("sda",2), md5p1 ("md",5,"p",1)
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
return map(lambda x: int(x) if x.isdigit() else x,
|
|
|
|
return map(lambda x: int(x) if x.isdigit() else x,
|
|
|
|
re.findall('\d+|\D+', device))
|
|
|
|
re.findall('\d+|\D+', dev))
|
|
|
|
|
|
|
|
|
|
|
|
def mapUdevProperty(self, var, prop, default):
|
|
|
|
def mapUdevProperty(self, var, prop, default):
|
|
|
|
"""Get each element from var through udev [prop]"""
|
|
|
|
"""Get each element from var through udev [prop]"""
|
|
|
|
return map(lambda x: udev.get_device_info(name=x).get(prop, default),
|
|
|
|
return [device.udev.get_device_info(name=x).get(prop, default)
|
|
|
|
self.Get(var))
|
|
|
|
for x in self.Get(var)]
|
|
|
|
|
|
|
|
|
|
|
|
def getPerfectName(self, device, defaultValue=None):
|
|
|
|
def getPerfectName(self, dev, defaultValue=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Get dev name or human-readable lvm name
|
|
|
|
Get dev name or human-readable lvm name
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
info = udev.get_device_info(name=device)
|
|
|
|
info = device.udev.get_device_info(name=dev)
|
|
|
|
if 'DM_VG_NAME' in info and 'DM_LV_NAME' in info:
|
|
|
|
if 'DM_VG_NAME' in info and 'DM_LV_NAME' in info:
|
|
|
|
lvmDeviceName = '/dev/{vg}/{lv}'.format(vg=info['DM_VG_NAME'],
|
|
|
|
lvmDeviceName = '/dev/{vg}/{lv}'.format(vg=info['DM_VG_NAME'],
|
|
|
|
lv=info['DM_LV_NAME'])
|
|
|
|
lv=info['DM_LV_NAME'])
|
|
|
@ -84,11 +85,11 @@ class DeviceHelper(VariableInterface):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return defaultValue
|
|
|
|
return defaultValue
|
|
|
|
|
|
|
|
|
|
|
|
def getLvmName(self, device):
|
|
|
|
def getLvmName(self, dev):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Get lvm name
|
|
|
|
Get lvm name
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
return self.getPerfectName(device, defaultValue="")
|
|
|
|
return self.getPerfectName(dev, defaultValue="")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#######################################################
|
|
|
|
#######################################################
|
|
|
@ -137,8 +138,9 @@ class VariableOsDeviceDev(DeviceHelper, ReadonlyVariable):
|
|
|
|
|
|
|
|
|
|
|
|
# get devices from block sys directories(discard mem,sr,loop and other)
|
|
|
|
# get devices from block sys directories(discard mem,sr,loop and other)
|
|
|
|
devices = (x for x in self.getBlockDevices() if x.count('/') == 2)
|
|
|
|
devices = (x for x in self.getBlockDevices() if x.count('/') == 2)
|
|
|
|
devnames = udev.syspath_to_devname(
|
|
|
|
devnames = device.udev.syspath_to_devname(
|
|
|
|
x for x in devices if udev.is_device(udev.get_device_info(x)))
|
|
|
|
x for x in devices
|
|
|
|
|
|
|
|
if device.udev.is_device(device.udev.get_device_info(x)))
|
|
|
|
|
|
|
|
|
|
|
|
return list(sorted((x for x in devnames),
|
|
|
|
return list(sorted((x for x in devnames),
|
|
|
|
key=self.separateDevice))
|
|
|
|
key=self.separateDevice))
|
|
|
@ -161,7 +163,7 @@ class VariableOsDeviceDev(DeviceHelper, ReadonlyVariable):
|
|
|
|
self.parent.Invalidate(self.name)
|
|
|
|
self.parent.Invalidate(self.name)
|
|
|
|
self.parent.Invalidate('os_install_disk_uuid')
|
|
|
|
self.parent.Invalidate('os_install_disk_uuid')
|
|
|
|
self.parent.Invalidate('os_disk_dev')
|
|
|
|
self.parent.Invalidate('os_disk_dev')
|
|
|
|
udev.clear_cache()
|
|
|
|
device.udev.clear_cache()
|
|
|
|
except OSError as e:
|
|
|
|
except OSError as e:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
@ -172,10 +174,10 @@ class VariableOsDeviceType(ReadonlyVariable):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
type = "list"
|
|
|
|
type = "list"
|
|
|
|
|
|
|
|
|
|
|
|
def getType(self, device):
|
|
|
|
def getType(self, dev):
|
|
|
|
device_name = path.basename(device)
|
|
|
|
device_name = path.basename(dev)
|
|
|
|
if device_name in self.usbdevices:
|
|
|
|
if device_name in self.usbdevices:
|
|
|
|
if sysfs.read(sysfs.Path.Block,device_name,
|
|
|
|
if device.sysfs.read(device.sysfs.Path.Block,device_name,
|
|
|
|
"removable").strip() == 1:
|
|
|
|
"removable").strip() == 1:
|
|
|
|
return "flash"
|
|
|
|
return "flash"
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -247,10 +249,10 @@ class VariableOsDeviceSsdSet(ReadonlyVariable):
|
|
|
|
def get(self):
|
|
|
|
def get(self):
|
|
|
|
"""Get device partition table"""
|
|
|
|
"""Get device partition table"""
|
|
|
|
|
|
|
|
|
|
|
|
def isSsd(device, name):
|
|
|
|
def isSsd(dev, name):
|
|
|
|
prop = udev.get_device_info(name=device)
|
|
|
|
prop = device.udev.get_device_info(name=dev)
|
|
|
|
rpm = prop.get(self.udev_property, None)
|
|
|
|
rpm = prop.get(self.udev_property, None)
|
|
|
|
if (any(x in device for x in self.devnames)
|
|
|
|
if (any(x in dev for x in self.devnames)
|
|
|
|
or rpm == "0" or any(x in name for x in self.ssd_names)):
|
|
|
|
or rpm == "0" or any(x in name for x in self.ssd_names)):
|
|
|
|
return "on"
|
|
|
|
return "on"
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -271,8 +273,8 @@ class VariableOsDeviceSyspath(ReadonlyVariable):
|
|
|
|
def get(self):
|
|
|
|
def get(self):
|
|
|
|
"""Get device partition table"""
|
|
|
|
"""Get device partition table"""
|
|
|
|
|
|
|
|
|
|
|
|
def getSysPath(device):
|
|
|
|
def getSysPath(dev):
|
|
|
|
prop = udev.get_device_info(name=device)
|
|
|
|
prop = device.udev.get_device_info(name=dev)
|
|
|
|
syspath = prop.get(self.udev_property, "")
|
|
|
|
syspath = prop.get(self.udev_property, "")
|
|
|
|
return syspath
|
|
|
|
return syspath
|
|
|
|
|
|
|
|
|
|
|
@ -310,12 +312,12 @@ class VariableOsDeviceTable(ReadonlyVariable):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
type = "list"
|
|
|
|
type = "list"
|
|
|
|
|
|
|
|
|
|
|
|
def getTableByChild(self, device):
|
|
|
|
def getTableByChild(self, dev):
|
|
|
|
"""Get table by child partitions"""
|
|
|
|
"""Get table by child partitions"""
|
|
|
|
syspath = udev.get_syspath(name=device)
|
|
|
|
syspath = device.udev.get_syspath(name=dev)
|
|
|
|
shortname = path.basename(device)
|
|
|
|
shortname = path.basename(dev)
|
|
|
|
for child in sysfs.glob(syspath, "%s*" % shortname):
|
|
|
|
for child in device.sysfs.glob(syspath, "%s*" % shortname):
|
|
|
|
udevinfo = udev.get_device_info(path=child)
|
|
|
|
udevinfo = device.udev.get_device_info(path=child)
|
|
|
|
map_names = {'mbr': 'dos',
|
|
|
|
map_names = {'mbr': 'dos',
|
|
|
|
'msdos': 'dos'}
|
|
|
|
'msdos': 'dos'}
|
|
|
|
table = (udevinfo.get('ID_PART_ENTRY_SCHEME', '') or
|
|
|
|
table = (udevinfo.get('ID_PART_ENTRY_SCHEME', '') or
|
|
|
@ -328,16 +330,16 @@ class VariableOsDeviceTable(ReadonlyVariable):
|
|
|
|
autopartition = self.Get('cl_autopartition_set') == 'on'
|
|
|
|
autopartition = self.Get('cl_autopartition_set') == 'on'
|
|
|
|
autoDevice = self.Get('cl_autopartition_device')
|
|
|
|
autoDevice = self.Get('cl_autopartition_device')
|
|
|
|
|
|
|
|
|
|
|
|
def getTable(device):
|
|
|
|
def getTable(dev):
|
|
|
|
prop = udev.get_device_info(name=device)
|
|
|
|
prop = device.udev.get_device_info(name=dev)
|
|
|
|
return prop.get('ID_PART_TABLE_TYPE',
|
|
|
|
return prop.get('ID_PART_TABLE_TYPE',
|
|
|
|
self.getTableByChild(device))
|
|
|
|
self.getTableByChild(dev))
|
|
|
|
|
|
|
|
|
|
|
|
def getByAutopartition(device):
|
|
|
|
def getByAutopartition(dev):
|
|
|
|
if autopartition and autoDevice == device:
|
|
|
|
if autopartition and autoDevice == dev:
|
|
|
|
return self.Get('cl_autopartition_table')
|
|
|
|
return self.Get('cl_autopartition_table')
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return getTable(device)
|
|
|
|
return getTable(dev)
|
|
|
|
|
|
|
|
|
|
|
|
return map(getByAutopartition,
|
|
|
|
return map(getByAutopartition,
|
|
|
|
self.Get('os_device_dev'))
|
|
|
|
self.Get('os_device_dev'))
|
|
|
@ -353,11 +355,11 @@ class VariableOsDeviceName(ReadonlyVariable):
|
|
|
|
'mmcblk': 'Multimedia Card'
|
|
|
|
'mmcblk': 'Multimedia Card'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def getName(self, device):
|
|
|
|
def getName(self, dev):
|
|
|
|
devicepath = udev.get_syspath(name=device)
|
|
|
|
devicepath = device.udev.get_syspath(name=dev)
|
|
|
|
if devicepath:
|
|
|
|
if devicepath:
|
|
|
|
vendor = sysfs.read(devicepath, "device/vendor").strip()
|
|
|
|
vendor = device.sysfs.read(devicepath, "device/vendor").strip()
|
|
|
|
model = sysfs.read(devicepath, "device/model").strip()
|
|
|
|
model = device.sysfs.read(devicepath, "device/model").strip()
|
|
|
|
if vendor or model:
|
|
|
|
if vendor or model:
|
|
|
|
return ("%s %s" %
|
|
|
|
return ("%s %s" %
|
|
|
|
(vendor, model)).strip()
|
|
|
|
(vendor, model)).strip()
|
|
|
@ -424,7 +426,7 @@ class VariableOsDiskDev(DeviceHelper, ReadonlyVariable):
|
|
|
|
disks = self.getBlockDevices()
|
|
|
|
disks = self.getBlockDevices()
|
|
|
|
parents = {re_parent.search(x).group()
|
|
|
|
parents = {re_parent.search(x).group()
|
|
|
|
for x in disks if x.count("/") > 2}
|
|
|
|
for x in disks if x.count("/") > 2}
|
|
|
|
dev_names = udev.syspath_to_devname(
|
|
|
|
dev_names = device.udev.syspath_to_devname(
|
|
|
|
(x for x in disks if x not in parents),
|
|
|
|
(x for x in disks if x not in parents),
|
|
|
|
dropempty=False)
|
|
|
|
dropempty=False)
|
|
|
|
return list(sorted((x for x in dev_names), key=self.separateDevice))
|
|
|
|
return list(sorted((x for x in dev_names), key=self.separateDevice))
|
|
|
@ -472,10 +474,10 @@ class VariableOsDiskFormat(ReadonlyVariable):
|
|
|
|
"""Get current disk filesystem"""
|
|
|
|
"""Get current disk filesystem"""
|
|
|
|
fstab = FStab('/etc/fstab', devs=self.Get('os_disk_dev'))
|
|
|
|
fstab = FStab('/etc/fstab', devs=self.Get('os_disk_dev'))
|
|
|
|
|
|
|
|
|
|
|
|
def getFormat(device):
|
|
|
|
def getFormat(dev):
|
|
|
|
prop = udev.get_device_info(name=device)
|
|
|
|
prop = device.udev.get_device_info(name=dev)
|
|
|
|
return prop.get('FSTAB_TYPE') or \
|
|
|
|
return prop.get('FSTAB_TYPE') or \
|
|
|
|
fstab.getBy(what=fstab.TYPE, eq=device) or \
|
|
|
|
fstab.getBy(what=fstab.TYPE, eq=dev) or \
|
|
|
|
prop.get('ID_FS_TYPE', '')
|
|
|
|
prop.get('ID_FS_TYPE', '')
|
|
|
|
|
|
|
|
|
|
|
|
return map(getFormat,
|
|
|
|
return map(getFormat,
|
|
|
@ -506,18 +508,18 @@ class VariableOsDiskType(ReadonlyVariable):
|
|
|
|
lvmUsedDisks[diskName]))
|
|
|
|
lvmUsedDisks[diskName]))
|
|
|
|
return diskName, diskType
|
|
|
|
return diskName, diskType
|
|
|
|
|
|
|
|
|
|
|
|
for device, diskType in types:
|
|
|
|
for dev, diskType in types:
|
|
|
|
prop = udev.get_device_info(name=device)
|
|
|
|
prop = device.udev.get_device_info(name=dev)
|
|
|
|
if "raid" in diskType:
|
|
|
|
if "raid" in diskType:
|
|
|
|
for x in raid.devices(prop.get('DEVPATH', '')):
|
|
|
|
for x in device.raid.devices(prop.get('DEVPATH', '')):
|
|
|
|
raidUsedDisks[x] = device
|
|
|
|
raidUsedDisks[x] = dev
|
|
|
|
if diskType.endswith("lvm"):
|
|
|
|
if diskType.endswith("lvm"):
|
|
|
|
for x in lvm.used_partitions(prop.get('DM_VG_NAME', ''),
|
|
|
|
for x in device.lvm.used_partitions(prop.get('DM_VG_NAME', ''),
|
|
|
|
prop.get('DM_LV_NAME', '')):
|
|
|
|
prop.get('DM_LV_NAME', '')):
|
|
|
|
if x in lvmUsedDisks:
|
|
|
|
if x in lvmUsedDisks:
|
|
|
|
lvmUsedDisks[x].append(device)
|
|
|
|
lvmUsedDisks[x].append(dev)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
lvmUsedDisks[x] = [device]
|
|
|
|
lvmUsedDisks[x] = [dev]
|
|
|
|
return map(lambda x: x[1],
|
|
|
|
return map(lambda x: x[1],
|
|
|
|
map(forMember,
|
|
|
|
map(forMember,
|
|
|
|
types))
|
|
|
|
types))
|
|
|
@ -571,9 +573,9 @@ class VariableOsDiskParent(ReadonlyVariable):
|
|
|
|
|
|
|
|
|
|
|
|
def get(self):
|
|
|
|
def get(self):
|
|
|
|
"""Get disk parent"""
|
|
|
|
"""Get disk parent"""
|
|
|
|
return map(getPartitionDevice,
|
|
|
|
return [getPartitionDevice(x)
|
|
|
|
map(lambda x: udev.get_device_info(name=x).get('DEVPATH', ''),
|
|
|
|
for x in (device.udev.get_device_info(name=y).get('DEVPATH', '')
|
|
|
|
self.Get('os_disk_dev')))
|
|
|
|
for y in self.Get("os_disk_dev"))]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VariableOsDiskId(DeviceHelper, ReadonlyVariable):
|
|
|
|
class VariableOsDiskId(DeviceHelper, ReadonlyVariable):
|
|
|
@ -608,8 +610,8 @@ class VariableOsDiskGrub(ReadonlyVariable):
|
|
|
|
self.Get('os_device_map')))
|
|
|
|
self.Get('os_device_map')))
|
|
|
|
|
|
|
|
|
|
|
|
def getGrubMap(devParent):
|
|
|
|
def getGrubMap(devParent):
|
|
|
|
device, parent = devParent
|
|
|
|
dev, parent = devParent
|
|
|
|
prop = udev.get_device_info(name=device)
|
|
|
|
prop = device.udev.get_device_info(name=dev)
|
|
|
|
partnum = int(prop.get('ID_PART_ENTRY_NUMBER', 0))
|
|
|
|
partnum = int(prop.get('ID_PART_ENTRY_NUMBER', 0))
|
|
|
|
if parent in devicesMap.keys() and partnum:
|
|
|
|
if parent in devicesMap.keys() and partnum:
|
|
|
|
return "%s,%d" % (devicesMap[parent], partnum - 1)
|
|
|
|
return "%s,%d" % (devicesMap[parent], partnum - 1)
|
|
|
@ -633,7 +635,8 @@ class VariableOsDiskPart(ReadonlyVariable):
|
|
|
|
return \
|
|
|
|
return \
|
|
|
|
map(lambda x: x[0] if x[1] else "",
|
|
|
|
map(lambda x: x[0] if x[1] else "",
|
|
|
|
map(lambda x: (
|
|
|
|
map(lambda x: (
|
|
|
|
getPartitionType(udev.get_device_info(name=x[0])), x[1]),
|
|
|
|
getPartitionType(
|
|
|
|
|
|
|
|
device.udev.get_device_info(name=x[0])), x[1]),
|
|
|
|
self.ZipVars('os_disk_dev', 'os_disk_parent')))
|
|
|
|
self.ZipVars('os_disk_dev', 'os_disk_parent')))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -673,8 +676,8 @@ class VariableOsDiskOptions(ReadonlyVariable):
|
|
|
|
def get(self):
|
|
|
|
def get(self):
|
|
|
|
fstab = FStab('/etc/fstab', devs=self.Get('os_disk_dev'))
|
|
|
|
fstab = FStab('/etc/fstab', devs=self.Get('os_disk_dev'))
|
|
|
|
|
|
|
|
|
|
|
|
def getFormat(device):
|
|
|
|
def getFormat(dev):
|
|
|
|
return fstab.getBy(what=fstab.OPTS, eq=device)
|
|
|
|
return fstab.getBy(what=fstab.OPTS, eq=dev)
|
|
|
|
|
|
|
|
|
|
|
|
return map(getFormat,
|
|
|
|
return map(getFormat,
|
|
|
|
self.Get('os_disk_dev'))
|
|
|
|
self.Get('os_disk_dev'))
|
|
|
@ -885,9 +888,9 @@ class VariableOsLocationSource(LocationHelper, DeviceHelper, Variable):
|
|
|
|
###########################
|
|
|
|
###########################
|
|
|
|
disks = filter(lambda x: x.startswith('/dev/'), value)
|
|
|
|
disks = filter(lambda x: x.startswith('/dev/'), value)
|
|
|
|
# get original /dev names
|
|
|
|
# get original /dev names
|
|
|
|
cnDisks = map(lambda x: udev.get_device_info(name=x).get('DEVNAME', x),
|
|
|
|
cnDisks = (device.udev.get_device_info(name=x).get('DEVNAME', x)
|
|
|
|
disks)
|
|
|
|
for x in disks)
|
|
|
|
wrongDevices = list(set(cnDisks) - \
|
|
|
|
wrongDevices = list(set(cnDisks) -
|
|
|
|
set(self.fixOsDiskDev()))
|
|
|
|
set(self.fixOsDiskDev()))
|
|
|
|
if wrongDevices:
|
|
|
|
if wrongDevices:
|
|
|
|
raise VariableError(_("Wrong device '%s'") % wrongDevices[0])
|
|
|
|
raise VariableError(_("Wrong device '%s'") % wrongDevices[0])
|
|
|
@ -2036,10 +2039,10 @@ class VariableOsInstallRootType(LocationHelper, Variable):
|
|
|
|
return "flash"
|
|
|
|
return "flash"
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
rootdev = self.Get('os_install_root_dev')
|
|
|
|
rootdev = self.Get('os_install_root_dev')
|
|
|
|
device = getPartitionDevice(
|
|
|
|
dev = getPartitionDevice(
|
|
|
|
udev.get_device_info(name=rootdev).get('DEVPATH', ''))
|
|
|
|
device.udev.get_device_info(name=rootdev).get('DEVPATH', ''))
|
|
|
|
device_type = self.Select(
|
|
|
|
device_type = self.Select(
|
|
|
|
'os_device_type', where='os_device_dev', eq=device, limit=1)
|
|
|
|
'os_device_type', where='os_device_dev', eq=dev, limit=1)
|
|
|
|
if device_type in ("usb-hdd", "flash"):
|
|
|
|
if device_type in ("usb-hdd", "flash"):
|
|
|
|
return "usb-hdd"
|
|
|
|
return "usb-hdd"
|
|
|
|
return "hdd"
|
|
|
|
return "hdd"
|
|
|
|