Новые параметры авторазметки

master3.4 3.4.5
parent f87e69036a
commit 96a518a14a

@ -69,6 +69,29 @@ class AutopartitionError(Exception):
pass
class SchemeOpt(object):
Swap = "swap"
Update = "update"
UEFI = "uefi"
LVM = "lvm"
Calculate = "calculate"
class SchemeDevices(object):
Swap = "swap"
Root1 = "system1"
Root2 = "system2"
UEFI = "uefi"
Data = "calculate"
@classmethod
def get_by_opt(cls, opt):
opt_map = {SchemeOpt.Swap: cls.Swap,
SchemeOpt.UEFI: cls.UEFI,
SchemeOpt.Calculate: cls.Data}
return opt_map.get(opt, opt)
class AutoPartition(object):
"""
Autopartition maker
@ -307,9 +330,9 @@ class AutoPartition(object):
lvname = disk.rpartition('/')[2]
if not self._createLogicalVolume(vgname, lvname, size):
raise AutopartitionError(
_("Failed to create logical volume {name}")
.format(name=lvname))
self._waitDevice('/dev/%s/root' % vgname)
_("Failed to create logical volume {name}").format(
name=lvname))
self._waitDevice('/dev/%s/%s' % (vgname, SchemeDevices.Root1))
class AutopartitionHelper(VariableInterface):
@ -318,55 +341,54 @@ class AutopartitionHelper(VariableInterface):
"""
def deviceOpts(self, listvalue):
l = [x for x in listvalue if x not in ("home", "lvm", "raid", "grub")]
for i in ("uefi", "swap", "boot"):
l = [x for x in listvalue if x not in (SchemeOpt.LVM,)]
for i in (SchemeOpt.UEFI, SchemeOpt.Swap):
if i in l:
l.remove(i)
yield i
yield SchemeDevices.get_by_opt(i)
break
yield "root2"
if "root" in l:
l.remove("root")
yield "root"
yield SchemeDevices.Root1
if SchemeOpt.Update in l:
l.remove(SchemeOpt.Update)
yield SchemeDevices.Root2
for i in l:
yield i
yield SchemeDevices.get_by_opt(i)
def bindOpts(self, listvalue):
return filter(lambda x: x in ("data",),
return filter(lambda x: x in (SchemeOpt.Calculate,),
listvalue)
def mpByOpts(self, value):
mapMp = {'swap': 'swap',
'boot': '/boot',
'root2': '/',
'root': '',
'uefi': '/boot/efi',
'data': '/var/calculate'}
mapMp = {SchemeDevices.Swap: 'swap',
SchemeDevices.Root1: '/',
SchemeDevices.Root2: '',
SchemeDevices.UEFI: '/boot/efi',
SchemeDevices.Data: '/var/calculate'}
return mapMp.get(value, '')
def sourceMpByOpts(self, value):
mapMp = {'data': '/var/calculate/home'}
mapMp = {SchemeOpt.Calculate: '/var/calculate/home'}
return mapMp.get(value, '')
def targetMpByOpts(self, value):
mapMp = {'data': '/home'}
mapMp = {SchemeOpt.Calculate: '/home'}
return mapMp.get(value, '')
def getAutopartitionScheme(self):
optOrder = {'uefi': 0,
'root': 1,
'home': 2,
'swap': 3,
'boot': 4,
'data': 5,
"""
Получить список опций отсортированный в нужном порядке
"""
optOrder = {SchemeOpt.UEFI: 0,
SchemeOpt.Update: 1,
SchemeOpt.Swap: 2,
SchemeOpt.Calculate: 3,
}
return sorted(self.Get('cl_autopartition_scheme'), key=optOrder.get)
def uncompatible(self):
if self.Get('cl_autopartition_set') == "off":
return \
_("Autopartition options are not available with manual "
"partitioning")
return _("Autopartition options are not available with manual "
"partitioning")
return ""
@ -546,23 +568,30 @@ class VariableClAutopartitionScheme(AutopartitionHelper, AutoPartition,
def get(self):
if self.Get('os_uefi_set') == 'on':
return ["uefi", "swap", "root", "data"]
return [SchemeOpt.UEFI,
SchemeOpt.Swap,
SchemeOpt.Update,
SchemeOpt.Calculate]
elif self.Get('cl_autopartition_table') == 'gpt':
return ["swap", "root", "data"]
return [SchemeOpt.Swap,
SchemeOpt.Update,
SchemeOpt.Calculate]
else:
return ["swap", "root", "data"]
return [SchemeOpt.Swap,
SchemeOpt.Update,
SchemeOpt.Calculate]
def choice(self):
return [
("swap", _("Swap partition")),
("root", _("Additional root partition")),
("data", _("/var/calculate partition")),
("uefi", _("Use the UEFI bootloader")),
("lvm", _("Use LVM")),
(SchemeOpt.Swap, _("Swap partition")),
(SchemeOpt.Update, _("The partition for the update")),
(SchemeOpt.Calculate, _("/var/calculate partition")),
(SchemeOpt.UEFI, _("Use the UEFI bootloader")),
(SchemeOpt.LVM, _("Use LVM")),
]
def check(self, value):
if "uefi" in value:
if SchemeOpt.UEFI in value:
if self.Get('os_uefi_set') == 'off':
raise VariableError(
_("Your system must be loaded in UEFI for using this "
@ -676,7 +705,8 @@ class VariableClAutopartitionLvmSet(ReadonlyVariable):
type = "bool"
def get(self):
return "on" if "lvm" in self.Get('cl_autopartition_scheme') else "off"
return ("on" if SchemeOpt.LVM in self.Get('cl_autopartition_scheme')
else "off")
class VariableClAutopartitionUefiSet(ReadonlyVariable):
@ -686,7 +716,8 @@ class VariableClAutopartitionUefiSet(ReadonlyVariable):
type = "bool"
def get(self):
return "on" if "uefi" in self.Get('cl_autopartition_scheme') else "off"
return ("on" if SchemeOpt.UEFI in self.Get('cl_autopartition_scheme')
else "off")
class VariableClAutopartitionLvmVgname(Variable):
@ -697,7 +728,7 @@ class VariableClAutopartitionLvmVgname(Variable):
def get(self):
def generateName(startName):
yield startName
for i in count(2):
for i in count(20):
yield "%s%d" % (startName, i)
for name in generateName("calculate"):
@ -732,10 +763,8 @@ class VariableClAutopartitionDiskDev(AutopartitionHelper, ReadonlyVariable):
def generateLvm(self, scheme=(), devices=(), **kwargs):
vgname = self.Get('cl_autopartition_lvm_vgname')
number = 1
for line in map(lambda x: {'root': 'root2',
'root2': 'root'}.get(x, x),
self.deviceOpts(scheme)):
if line in ("boot", "uefi"):
for line in self.deviceOpts(scheme):
if line in (SchemeDevices.UEFI,):
if (number == 4 and
self.Get('cl_autopartition_bios_grub_set') == 'on'):
number += 1
@ -771,7 +800,7 @@ class VariableClAutopartitionDiskScheme(AutopartitionHelper, ReadonlyVariable):
def generateScheme(self, scheme):
"""
Generate mount points for automount scheme
Generate scheme for automount scheme
"""
for line in self.deviceOpts(scheme):
yield line
@ -818,9 +847,9 @@ class VariableClAutopartitionDiskFormat(AutopartitionHelper, ReadonlyVariable):
Generate filesystems for automount scheme
"""
for line in self.deviceOpts(scheme):
if line == "swap":
if line == SchemeDevices.Swap:
yield "swap"
elif line == "uefi":
elif line == SchemeDevices.UEFI:
yield "vfat"
else:
yield FileSystemManager.defaultFS['hdd']
@ -860,9 +889,7 @@ class VariableClAutopartitionDiskPart(AutopartitionHelper, ReadonlyVariable):
scheme = self.getAutopartitionScheme()
table = self.Get('cl_autopartition_table')
if scheme:
return list(self.generatePart(scheme,
self.Get(
'cl_autopartition_table') == 'dos'))
return list(self.generatePart(scheme, table == 'dos'))
return []
@ -890,18 +917,18 @@ class VariableClAutopartitionDiskSize(AutopartitionHelper, ReadonlyVariable):
def generateSize(self, scheme, memory, bootsize, uefisize, rootsize,
availsize, minrootsize):
args = {'swap': memory,
'root': rootsize,
'root2': rootsize,
'boot': bootsize,
'uefi': uefisize,
args = {SchemeDevices.Swap: memory,
SchemeDevices.Root1: rootsize,
SchemeDevices.Root2: rootsize,
SchemeDevices.UEFI: uefisize,
}
minrootsize = int(minrootsize)
deviceOpts = list(self.deviceOpts(scheme))
for line in deviceOpts[:-1]:
availsize -= int(args.get(line, 0))
yield str(args.get(line, 0))
if "root" in deviceOpts[-1] and availsize < minrootsize:
if deviceOpts[-1] in (SchemeDevices.Root1,
SchemeDevices.Root2) and availsize < minrootsize:
yield str(minrootsize)
elif availsize < 1 * Sizes.G:
yield str(1 * Sizes.G)
@ -914,26 +941,20 @@ class VariableClAutopartitionDiskSize(AutopartitionHelper, ReadonlyVariable):
device = self.Get('cl_autopartition_device')
availSize = self.Get('cl_autopartition_device_size')
if device:
return list(self.generateSize(scheme,
self.Get(
'cl_autopartition_swap_size'),
self.Get(
'cl_autopartition_boot_size'),
self.Get(
'cl_autopartition_uefi_size'),
self.Get(
'cl_autopartition_root_size'),
int(availSize),
self.Get(
'cl_autopartition_root_size_min')
))
return list(self.generateSize(
scheme,
self.Get('cl_autopartition_swap_size'),
self.Get('cl_autopartition_boot_size'),
self.Get('cl_autopartition_uefi_size'),
self.Get('cl_autopartition_root_size'),
int(availSize),
self.Get('cl_autopartition_root_size_min')))
return []
def humanReadable(self):
allSize = self.Get('cl_autopartition_free_size')
return map(humanreadableSize,
map(lambda x: allSize if x == "allfree" else x,
self.Get()))
map(lambda x: allSize if x == "allfree" else x, self.Get()))
class VariableClAutopartitionUefiSize(Variable):

Loading…
Cancel
Save