You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
957 lines
33 KiB
957 lines
33 KiB
13 years ago
|
#-*- coding: utf-8 -*-
|
||
|
|
||
11 years ago
|
# Copyright 2008-2013 Calculate Ltd. http://www.calculate-linux.org
|
||
13 years ago
|
#
|
||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
# you may not use this file except in compliance with the License.
|
||
|
# You may obtain a copy of the License at
|
||
|
#
|
||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||
|
#
|
||
|
# Unless required by applicable law or agreed to in writing, software
|
||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
# See the License for the specific language governing permissions and
|
||
|
# limitations under the License.
|
||
|
|
||
|
import os
|
||
|
import sys
|
||
|
import re
|
||
|
from os import path
|
||
13 years ago
|
from time import sleep
|
||
13 years ago
|
from calculate.lib.datavars import TableVariable,Variable,VariableError, \
|
||
|
ReadonlyVariable, ReadonlyTableVariable
|
||
13 years ago
|
from calculate.lib.utils.device import (getUdevDeviceInfo,getDeviceType,
|
||
|
getPartitionType,getPartitionDevice,getRaidPartitions,
|
||
13 years ago
|
getLvmPartitions,getPartitionSize,getUUIDDict,
|
||
12 years ago
|
humanreadableSize,refreshUdev)
|
||
13 years ago
|
from calculate.lib.utils.files import (listDirectory,pathJoin,readFile,FStab,
|
||
13 years ago
|
readLinesFile,process,getProgPath)
|
||
12 years ago
|
from calculate.install.distr import PartitionDistributive
|
||
13 years ago
|
from calculate.install.fs_manager import FileSystemManager
|
||
11 years ago
|
from calculate.lib.utils.tools import Sizes
|
||
13 years ago
|
from itertools import *
|
||
|
import operator
|
||
13 years ago
|
|
||
|
|
||
|
from calculate.lib.cl_lang import setLocalTranslate
|
||
13 years ago
|
setLocalTranslate('cl_install3',sys.modules[__name__])
|
||
13 years ago
|
|
||
13 years ago
|
|
||
11 years ago
|
class SizeHelper:
|
||
|
def set(self,value):
|
||
|
# convert table from value to MB
|
||
|
sizeMap = {'kB':1/1000.0,
|
||
|
'K':1/1024.0,
|
||
|
'M':1.0,
|
||
|
'Mb':1000/1024.0,
|
||
|
'G':1024,
|
||
|
'Gb':1000,
|
||
|
'T':1024*1024,
|
||
|
'Tb':1000*1000}
|
||
|
value = value.strip()
|
||
|
reSizeValue = re.compile('^(\d+)\s*(%s)?'%"|".join(sizeMap.keys()))
|
||
|
res = reSizeValue.search(value)
|
||
|
if not res:
|
||
|
return "0"
|
||
|
intValue = int(res.group(1))
|
||
|
if res.group(2):
|
||
|
intValue = intValue * sizeMap[res.group(2)]
|
||
|
return str(int(intValue))
|
||
|
|
||
13 years ago
|
MINROOTSIZE=7*Sizes.G
|
||
13 years ago
|
|
||
13 years ago
|
class AutopartitionError(Exception):
|
||
|
"""
|
||
|
Autopartition error
|
||
|
"""
|
||
|
pass
|
||
|
|
||
13 years ago
|
class AutoPartition:
|
||
|
"""
|
||
|
Autopartition maker
|
||
|
"""
|
||
11 years ago
|
def recreateSpace(self,table,device,data,lvm,vgname,bios_grub,bios_grub_size):
|
||
12 years ago
|
"""
|
||
|
Recreate disk space by table device data lvm flag and vgname
|
||
|
|
||
|
table (gpt,dos)
|
||
|
device - list devices ['/dev/sda']
|
||
|
data - partitions data [['/dev/calculate/boot','/boot','ext4',534234234'gpt]...]
|
||
|
lvm True or False
|
||
|
vgname lvm Volume Group Name
|
||
|
"""
|
||
13 years ago
|
if lvm:
|
||
11 years ago
|
self.recreateLvm(table,device,data,vgname,bios_grub,bios_grub_size)
|
||
13 years ago
|
else:
|
||
11 years ago
|
self.recreatePartitionTable(table,device,data,bios_grub,bios_grub_size)
|
||
12 years ago
|
refreshUdev()
|
||
13 years ago
|
|
||
11 years ago
|
def recreatePartitionTable(self,table,device,data,bios_grub,bios_grub_size):
|
||
13 years ago
|
"""
|
||
|
"""
|
||
13 years ago
|
mapDispatch = {'dos':self.recreatePartitionTableDos,
|
||
|
'gpt':self.recreatePartitionTableGpt}
|
||
|
if table in mapDispatch:
|
||
11 years ago
|
mapDispatch[table](device,data,bios_grub,bios_grub_size)
|
||
13 years ago
|
else:
|
||
|
raise AutoPartitionError(
|
||
|
_('Autopartitioning for %s is not supported')%table)
|
||
13 years ago
|
|
||
11 years ago
|
def recreatePartitionTableDos(self,device,data,bios_grub,bios_grub_size):
|
||
13 years ago
|
"""
|
||
13 years ago
|
Create DOS partition table by /sbin/fdisk
|
||
13 years ago
|
"""
|
||
|
NEW_PARTITION_TABLE = "o\n"
|
||
|
NEW_PRIMARY_PARTITION = "n\np\n\n\n"
|
||
|
NEW_EXTENDED_PARTITION = "n\ne\n\n"
|
||
|
NEW_LOGICAL_PARTITION = "n\n\n"
|
||
|
MAX_SIZE = "\n"
|
||
|
WRITE_AND_QUIT = "w\nq\n"
|
||
|
|
||
|
fdiskProg = getProgPath('/sbin/fdisk')
|
||
13 years ago
|
fdisk = process(fdiskProg,device[0])
|
||
13 years ago
|
fdisk.write(NEW_PARTITION_TABLE)
|
||
|
num = 1
|
||
13 years ago
|
for size in map(lambda x:str(Sizes().to_K(int(x))) \
|
||
|
if x.isdigit() else x,
|
||
|
map(operator.itemgetter(3),data)):
|
||
13 years ago
|
if num == 4:
|
||
|
fdisk.write(NEW_EXTENDED_PARTITION+MAX_SIZE)
|
||
|
num += 1
|
||
13 years ago
|
size = MAX_SIZE if size == "allfree" else "+%sK\n"%size
|
||
13 years ago
|
if num < 4:
|
||
|
fdisk.write(NEW_PRIMARY_PARTITION+size)
|
||
|
else:
|
||
|
fdisk.write(NEW_LOGICAL_PARTITION+size)
|
||
|
num +=1
|
||
|
fdisk.write(WRITE_AND_QUIT)
|
||
|
|
||
13 years ago
|
fdisk.success()
|
||
13 years ago
|
self._waitDevice(device[0]+str(num-1))
|
||
13 years ago
|
|
||
11 years ago
|
def recreatePartitionTableGpt(self,device,data,bios_grub=True,
|
||
|
bios_grub_size=0):
|
||
13 years ago
|
"""
|
||
|
Create GPT partition table by /sbin/gdisk
|
||
|
"""
|
||
13 years ago
|
NEW_PARTITION_TABLE = "3\no\ny\n"
|
||
13 years ago
|
NEW_PARTITION = "n\n\n\n"
|
||
13 years ago
|
NEW_BIOSBOOT_PARTITION = "n\n\n\n%s\nef02\n"
|
||
13 years ago
|
MAX_SIZE = "\n\n"
|
||
|
WRITE_AND_QUIT = "w\ny\n"
|
||
|
|
||
12 years ago
|
BIOS_BOOT_PART_NUM = 4
|
||
11 years ago
|
BIOS_BOOT_PART_SIZE = "%dM"%(int(bios_grub_size) / Sizes.M)
|
||
12 years ago
|
|
||
13 years ago
|
fdiskProg = getProgPath('/usr/sbin/gdisk')
|
||
13 years ago
|
fdisk = process(fdiskProg,device[0])
|
||
13 years ago
|
fdisk.write(NEW_PARTITION_TABLE)
|
||
|
num = 1
|
||
12 years ago
|
biosBootCreated = not bios_grub
|
||
13 years ago
|
for size in map(lambda x:str(Sizes().to_K(int(x))) \
|
||
|
if x.isdigit() else x,
|
||
|
map(operator.itemgetter(3),data)):
|
||
12 years ago
|
if num == BIOS_BOOT_PART_NUM and not biosBootCreated:
|
||
12 years ago
|
fdisk.write(NEW_BIOSBOOT_PARTITION%
|
||
|
("+%s"%BIOS_BOOT_PART_SIZE))
|
||
13 years ago
|
biosBootCreated = True
|
||
13 years ago
|
num += 1
|
||
13 years ago
|
if size == "allfree":
|
||
13 years ago
|
if biosBootCreated:
|
||
|
size = MAX_SIZE
|
||
|
else:
|
||
12 years ago
|
size = "-%s\n\n"%BIOS_BOOT_PART_SIZE
|
||
13 years ago
|
else:
|
||
|
size = "+%sK\n\n"%size
|
||
13 years ago
|
fdisk.write(NEW_PARTITION+size)
|
||
|
num +=1
|
||
13 years ago
|
if not biosBootCreated:
|
||
|
fdisk.write(NEW_BIOSBOOT_PARTITION%"")
|
||
13 years ago
|
fdisk.write(WRITE_AND_QUIT)
|
||
|
fdisk.success()
|
||
13 years ago
|
self._waitDevice(device[0]+str(num-1))
|
||
|
|
||
|
def _waitDevice(self,device):
|
||
13 years ago
|
for waittime in (0.1,0.2,0.5,1,2,4):
|
||
13 years ago
|
if path.exists(device):
|
||
13 years ago
|
return True
|
||
|
else:
|
||
|
sleep(waittime)
|
||
13 years ago
|
raise AutopartitionError(
|
||
12 years ago
|
_("Failed to found partition %s after creating the partition table")
|
||
13 years ago
|
%device)
|
||
|
|
||
|
def _createPhisicalVolumes(self,devices):
|
||
|
pvCreateProg = getProgPath('/sbin/pvcreate')
|
||
13 years ago
|
return process(pvCreateProg,"-ff",*devices).success()
|
||
13 years ago
|
|
||
|
def _createVolumesGroup(self,vgname,disks):
|
||
|
vgCreateProg = getProgPath('/sbin/vgcreate')
|
||
|
return process(vgCreateProg,vgname,*disks).success()
|
||
|
|
||
|
def _createLogicalVolume(self,vgname,lvname,size):
|
||
|
if size.isdigit():
|
||
|
size = str(Sizes().to_K(int(size)))
|
||
|
if size == "allfree":
|
||
|
sizeparam = "-l100%FREE"
|
||
|
else:
|
||
|
sizeparam = "-L%sK"%size
|
||
|
lvCreateProg = getProgPath('/sbin/lvcreate')
|
||
|
return process(lvCreateProg,sizeparam,vgname,"-n",lvname).success()
|
||
|
|
||
|
def _removeVolumeGroup(self,vgname):
|
||
|
vgRemoveProg = getProgPath('/sbin/vgremove')
|
||
13 years ago
|
# double remove volume group
|
||
|
return process(vgRemoveProg,vgname,"-f").success() or \
|
||
|
process(vgRemoveProg,vgname,"-f").success()
|
||
13 years ago
|
|
||
13 years ago
|
def clearLvm(self,devices,dv):
|
||
|
"""
|
||
|
Remove lvm physical volumes from devices
|
||
|
"""
|
||
|
vgRemoveProg = getProgPath('/sbin/vgremove')
|
||
|
pvRemoveProg = getProgPath('/sbin/pvremove')
|
||
|
lvRemoveProg = getProgPath('/sbin/lvremove')
|
||
|
disks = dv.Select('os_disk_dev',where='os_disk_parent',_in=devices)
|
||
13 years ago
|
failed = False
|
||
13 years ago
|
for group, pair in groupby(dv.Select(['os_lvm_vgname','os_lvm_lvname'],
|
||
13 years ago
|
where='os_lvm_pvname',_in=disks,
|
||
|
sort="ASC/1"),
|
||
|
operator.itemgetter(0)):
|
||
13 years ago
|
for vgname,lvname in pair:
|
||
13 years ago
|
failed |= self.doubleExec(lvRemoveProg,
|
||
|
"%s/%s"%(vgname,lvname),"-f")
|
||
|
failed |= self.doubleExec(vgRemoveProg,group,"-f")
|
||
13 years ago
|
for pvname in list(set(disks)&set(dv.Get('os_lvm_pvname'))):
|
||
13 years ago
|
failed |= self.doubleExec(pvRemoveProg,pvname,"-ffy")
|
||
13 years ago
|
return not failed
|
||
13 years ago
|
|
||
13 years ago
|
def doubleExec(self,*args):
|
||
|
"""
|
||
|
Running double exec command with 2 seconds interval
|
||
|
"""
|
||
|
if process(*args).failed():
|
||
|
sleep(2)
|
||
|
return process(*args).failed()
|
||
|
return False
|
||
|
|
||
13 years ago
|
def clearRaid(self,devices,dv):
|
||
13 years ago
|
"""
|
||
13 years ago
|
Remove raid from devices
|
||
13 years ago
|
"""
|
||
13 years ago
|
mdAdmProg = getProgPath('/sbin/mdadm')
|
||
|
failed = False
|
||
|
for disktype,grouped in groupby(
|
||
|
dv.Select(['os_disk_type','os_disk_dev'],
|
||
|
where='os_disk_parent',
|
||
|
_in=['/dev/sda','/dev/sdb'],
|
||
|
sort="ASC/1"),
|
||
|
operator.itemgetter(0)):
|
||
|
if disktype.endswith('-raid'):
|
||
|
for disk_type, disk_dev in grouped:
|
||
13 years ago
|
failed |= self.doubleExec(mdAdmProg,'-S',disk_dev)
|
||
13 years ago
|
if "raidmember" in disktype:
|
||
|
for disk_type, disk_dev in grouped:
|
||
13 years ago
|
failed |= self.doubleExec(mdAdmProg,
|
||
|
'--zero-superblock',disk_dev)
|
||
13 years ago
|
return not failed
|
||
13 years ago
|
|
||
11 years ago
|
def recreateLvm(self,table,devices,data,vgname,bios_grub,bios_grub_size):
|
||
13 years ago
|
"""
|
||
|
Create GPT partition table by /sbin/gdisk
|
||
|
"""
|
||
12 years ago
|
for i,device in enumerate(devices):
|
||
|
if i == 0:
|
||
|
DEV,MP,FS,SIZE,TABLE=0,1,2,3,4
|
||
|
notInLvm = filter(lambda x:"boot" in x[MP],data)
|
||
12 years ago
|
self.recreatePartitionTable(table,
|
||
11 years ago
|
[device],notInLvm+[['','','','allfree']],bios_grub,
|
||
|
bios_grub_size)
|
||
12 years ago
|
else:
|
||
12 years ago
|
self.recreatePartitionTable(table,
|
||
11 years ago
|
[device],[['','','','allfree']],bios_grub,
|
||
|
bios_grub_size)
|
||
13 years ago
|
|
||
12 years ago
|
lvmPartOffset = 1 + len(notInLvm)
|
||
|
iPart = [lvmPartOffset]+[1]*(len(devices)-1)
|
||
|
disks = map(lambda x:"%s%d"%x,zip(devices,iPart))
|
||
13 years ago
|
if not self._createPhisicalVolumes(disks):
|
||
|
raise AutopartitionError(
|
||
12 years ago
|
_("Failed to create physical volumes from %s")
|
||
13 years ago
|
%",".join(devices))
|
||
|
|
||
|
if not self._createVolumesGroup(vgname,disks):
|
||
|
raise AutopartitionError(
|
||
12 years ago
|
_("Failed to create volume group {groupname} from {disks}")
|
||
13 years ago
|
.format(groupname=vgname,
|
||
|
disks=",".join(devices)))
|
||
|
|
||
|
lvCreateProg = getProgPath('/sbin/lvcreate')
|
||
12 years ago
|
for disk,size in map(operator.itemgetter(0,3),
|
||
|
filter(lambda x:not "boot" in x[MP],data)):
|
||
13 years ago
|
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)
|
||
13 years ago
|
|
||
13 years ago
|
class AutopartitionHelper:
|
||
|
"""
|
||
|
Helper for autopartiton device and mount point creating
|
||
|
"""
|
||
|
def deviceOpts(self,listvalue):
|
||
|
for i in ("root","data"):
|
||
|
if i in listvalue:
|
||
|
beforeVal = i
|
||
|
break
|
||
|
else:
|
||
|
beforeVal = ""
|
||
|
for line in listvalue:
|
||
12 years ago
|
if line in ("home","lvm","raid","grub"):
|
||
13 years ago
|
continue
|
||
|
if line == beforeVal:
|
||
|
yield "root2"
|
||
|
yield line
|
||
|
if not beforeVal:
|
||
|
yield "root2"
|
||
|
|
||
|
def bindOpts(self,listvalue):
|
||
|
return filter(lambda x:x in ("home",),
|
||
|
listvalue)
|
||
|
|
||
|
def mpByOpts(self,value):
|
||
|
mapMp = {'swap':'swap',
|
||
|
'boot':'/boot',
|
||
|
'root2':'/',
|
||
|
'root':'',
|
||
12 years ago
|
'uefi':'/boot/efi',
|
||
13 years ago
|
'data':'/var/calculate'}
|
||
|
return mapMp.get(value,'')
|
||
|
|
||
|
def sourceMpByOpts(self,value):
|
||
|
mapMp = {'home':'/var/calculate/home'}
|
||
|
return mapMp.get(value,'')
|
||
|
|
||
|
def targetMpByOpts(self,value):
|
||
|
mapMp = {'home':'/home'}
|
||
|
return mapMp.get(value,'')
|
||
|
|
||
|
def getAutopartitionScheme(self):
|
||
12 years ago
|
optOrder = {'uefi':0,
|
||
|
'boot':1,
|
||
|
'swap':2,
|
||
|
'root':3,
|
||
|
'data':4,
|
||
|
'home':5}
|
||
13 years ago
|
return sorted(self.Get('cl_autopartition_scheme'),key=optOrder.get)
|
||
|
|
||
|
def uncompatible(self):
|
||
13 years ago
|
if self.Get('cl_autopartition_set') == "off":
|
||
13 years ago
|
return \
|
||
12 years ago
|
_("Autopartition options are not available with manual "
|
||
|
"partitioning")
|
||
13 years ago
|
return ""
|
||
|
|
||
13 years ago
|
class VariableHrMemorySize(ReadonlyVariable):
|
||
|
"""
|
||
13 years ago
|
Memory size in bytes
|
||
13 years ago
|
"""
|
||
|
type = "int"
|
||
|
|
||
|
def get(self):
|
||
|
reMemTotal = re.compile(r'^MemTotal:\s*(\d+)\s*kB$')
|
||
|
totalMemList = filter(lambda x:x,
|
||
|
map(reMemTotal.search,
|
||
|
readLinesFile('/proc/meminfo')))
|
||
|
if totalMemList:
|
||
13 years ago
|
size = int(totalMemList[0].group(1))*Sizes.K
|
||
13 years ago
|
return str(size)
|
||
13 years ago
|
return "0"
|
||
|
|
||
|
def humanReadable(self):
|
||
12 years ago
|
return humanreadableSize(self.Get())
|
||
13 years ago
|
|
||
11 years ago
|
class VariableClAutopartitionSwapSize(SizeHelper,AutopartitionHelper,Variable):
|
||
13 years ago
|
"""
|
||
|
Swap size
|
||
|
"""
|
||
11 years ago
|
opt = ["--swap-size"]
|
||
|
metavalue = "SIZE"
|
||
|
untrusted = True
|
||
|
|
||
|
def init(self):
|
||
|
self.label = _("Swap partition size")+ " (MB)"
|
||
|
self.help = _("set the swap partition size for autopartition")
|
||
13 years ago
|
|
||
13 years ago
|
def get(self):
|
||
11 years ago
|
size = int(self.Get('hr_memory_size')) / Sizes.M
|
||
|
if size < Sizes.K:
|
||
|
size = Sizes.K
|
||
13 years ago
|
return str(size)
|
||
|
|
||
11 years ago
|
def humanReadable(self):
|
||
11 years ago
|
return humanreadableSize(int(self.Get())*Sizes.M)
|
||
11 years ago
|
|
||
13 years ago
|
class VariableClAutopartitionDevice(AutopartitionHelper,Variable):
|
||
13 years ago
|
"""
|
||
|
Device for autopartition
|
||
|
"""
|
||
13 years ago
|
type = "choice-list"
|
||
|
element = "selecttable"
|
||
13 years ago
|
opt = ["-D"]
|
||
|
metavalue = "DEVICE"
|
||
13 years ago
|
untrusted = True
|
||
13 years ago
|
|
||
|
def init(self):
|
||
12 years ago
|
self.help = _("set the device for autopartition")
|
||
13 years ago
|
self.label = _("Devices for install")
|
||
|
|
||
|
def get(self):
|
||
|
choiceVal = map(lambda x:x[0],self.choice())
|
||
|
if len(choiceVal) == 1:
|
||
|
return [choiceVal[0]]
|
||
|
return []
|
||
13 years ago
|
|
||
|
def choice(self):
|
||
13 years ago
|
deviceParentMap = dict(self.ZipVars('os_device_dev','os_device_name'))
|
||
|
return map(lambda x:(x,"%s (%s)"%(x,
|
||
|
deviceParentMap.get(x,_("Unknown")))),
|
||
13 years ago
|
self.Get('os_device_dev'))
|
||
13 years ago
|
|
||
13 years ago
|
def checkNeeded(self,valuelist,usedDevices,agregationType):
|
||
|
needDevices = list(set(usedDevices) - set(valuelist))
|
||
|
if needDevices:
|
||
12 years ago
|
raise VariableError(_("Disks {selecteddisk} are part of "
|
||
|
"{agrtype}\nYou need to use {needdisk} as well or "
|
||
|
"clear {agrtype} manually")
|
||
13 years ago
|
.format(selecteddisk=",".join(
|
||
|
list(set(usedDevices)&set(valuelist))),
|
||
|
needdisk=",".join(needDevices),
|
||
|
agrtype=agregationType))
|
||
|
|
||
|
|
||
|
def checkOnLvm(self,valuelist):
|
||
|
disks = self.Select('os_disk_dev',
|
||
|
where='os_disk_parent',_in=valuelist)
|
||
|
vgroups = self.Select('os_lvm_vgname',
|
||
|
where='os_lvm_pvname',_in=disks)
|
||
|
lvmDisks = self.Select('os_lvm_pvname',
|
||
|
where='os_lvm_vgname',_in=vgroups)
|
||
|
lvmDevices = self.Select('os_disk_parent',where='os_disk_dev',
|
||
|
_in=lvmDisks)
|
||
|
self.checkNeeded(valuelist,lvmDevices,"LVM")
|
||
|
|
||
|
def checkOnRaid(self,valuelist):
|
||
|
disks = self.Select('os_disk_dev',
|
||
|
where='os_disk_parent',_in=valuelist)
|
||
|
raids = filter(None,self.Select('os_disk_raid',
|
||
|
where='os_disk_dev',_in=disks))
|
||
|
raidDisks = self.Select('os_disk_dev',where='os_disk_raid',_in=raids)
|
||
|
raidDevices = self.Select('os_disk_parent',
|
||
|
where='os_disk_dev',
|
||
|
_in=raidDisks)
|
||
|
self.checkNeeded(valuelist,raidDevices,"RAID")
|
||
|
|
||
13 years ago
|
def check(self,valuelist):
|
||
13 years ago
|
if self.Get('cl_autopartition_set') == "on":
|
||
13 years ago
|
if not valuelist:
|
||
12 years ago
|
raise VariableError(_("For autopartition, please select the device"))
|
||
13 years ago
|
useDisks = self.Select('os_disk_parent',
|
||
13 years ago
|
where='os_disk_mount',ne='')
|
||
13 years ago
|
for value in valuelist:
|
||
|
if value in useDisks:
|
||
|
raise VariableError(
|
||
12 years ago
|
_("Device %s is already in use by the current "
|
||
|
"system")%value)
|
||
13 years ago
|
self.checkOnLvm(valuelist)
|
||
|
self.checkOnRaid(valuelist)
|
||
13 years ago
|
if len(valuelist) > 1 and \
|
||
|
self.Get('cl_autopartition_lvm_set') == 'off':
|
||
|
raise VariableError(
|
||
12 years ago
|
_("You should use LVM to install on more that one device"))
|
||
13 years ago
|
freeSize = int(self.Get('cl_autopartition_free_size'))
|
||
13 years ago
|
if freeSize < 0 and (abs(freeSize))/(Sizes.M*100) > 0:
|
||
13 years ago
|
availSize = int(self.Get('cl_autopartition_device_size'))
|
||
13 years ago
|
raise VariableError(
|
||
12 years ago
|
_("There is not enough space on this device")+"\n"+
|
||
|
_("{avail} available, {need} needed").format(
|
||
13 years ago
|
avail=humanreadableSize(availSize),
|
||
|
need=humanreadableSize(availSize-freeSize)))
|
||
|
|
||
|
class VariableClAutopartitionSet(Variable):
|
||
|
"""
|
||
|
Using autopartition
|
||
|
"""
|
||
13 years ago
|
type = "bool"
|
||
|
value = "off"
|
||
13 years ago
|
element = "radio"
|
||
13 years ago
|
opt = ["--autopartition"]
|
||
13 years ago
|
|
||
13 years ago
|
def init(self):
|
||
|
self.label = _("Partitions")
|
||
12 years ago
|
self.help = _("autopartition")
|
||
13 years ago
|
|
||
|
def choice(self):
|
||
12 years ago
|
return [("off",_("Use the current partitions")),
|
||
13 years ago
|
("on",_("Autopartition"))]
|
||
13 years ago
|
|
||
13 years ago
|
class VariableClAutopartitionScheme(AutopartitionHelper,Variable,AutoPartition):
|
||
13 years ago
|
"""
|
||
|
Autopartition scheme
|
||
|
"""
|
||
13 years ago
|
type = "choice-list"
|
||
|
element = "selecttable"
|
||
13 years ago
|
opt = ["--auto-scheme"]
|
||
13 years ago
|
metavalue = "AUTOPARTOPTS"
|
||
12 years ago
|
check_after = ["cl_autopartition_table"]
|
||
13 years ago
|
|
||
|
def init(self):
|
||
13 years ago
|
self.help = _("autopartition options")
|
||
12 years ago
|
self.label = _("Autopartition options")
|
||
13 years ago
|
|
||
12 years ago
|
def get(self):
|
||
|
if self.Get('os_uefi_set') == 'on':
|
||
12 years ago
|
return ["uefi","swap","root","data","home"]
|
||
|
elif self.Get('cl_autopartition_table') == 'gpt':
|
||
12 years ago
|
return ["swap","root","data","home","grub"]
|
||
12 years ago
|
else:
|
||
12 years ago
|
return ["swap","root","data","home"]
|
||
12 years ago
|
|
||
13 years ago
|
def choice(self):
|
||
13 years ago
|
return [
|
||
|
("swap",_("Swap partition")),
|
||
|
("root",_("Additional root partition")),
|
||
|
("data",_("/var/calculate partition")),
|
||
|
("home",_("Mount /var/calculate/home to /home")),
|
||
|
("boot",_("Separate boot partition")),
|
||
11 years ago
|
("uefi",_("Use the UEFI bootloader")),
|
||
12 years ago
|
("lvm",_("Use LVM")),
|
||
11 years ago
|
("grub",_("Create the bios_grub partition")),
|
||
13 years ago
|
]
|
||
13 years ago
|
|
||
12 years ago
|
def check(self,value):
|
||
|
if "uefi" in value:
|
||
|
if self.Get('os_uefi_set') == 'off':
|
||
|
raise VariableError(
|
||
11 years ago
|
_("Your system must be loaded in UEFI for using this "
|
||
|
"bootloader"))
|
||
12 years ago
|
if self.Get('os_install_arch_machine') != 'x86_64':
|
||
|
raise VariableError(
|
||
|
_("Architecture of the target system must be x86_64 "
|
||
11 years ago
|
"for using the UEFI bootloader"))
|
||
12 years ago
|
if self.Get('cl_autopartition_table') != 'gpt':
|
||
|
raise VariableError(
|
||
11 years ago
|
_("The partition table must be GPT for using "
|
||
|
"UEFI bootloader"))
|
||
12 years ago
|
else:
|
||
|
if self.Get('cl_autopartition_table') == 'gpt' and not "grub" in value:
|
||
|
raise VariableError(
|
||
11 years ago
|
_("A 'bios_grub' partition is needed to install grub"))
|
||
12 years ago
|
if "grub" in value:
|
||
|
if self.Get('cl_autopartition_table') != 'gpt':
|
||
|
raise VariableError(
|
||
11 years ago
|
_("The bios_grub partition need the partition table to be GPT"))
|
||
12 years ago
|
|
||
11 years ago
|
class VariableClAutopartitionRootSize(SizeHelper,AutopartitionHelper,Variable):
|
||
13 years ago
|
"""
|
||
|
Root partition size for autopartition
|
||
|
"""
|
||
13 years ago
|
opt = ["--root-size"]
|
||
|
metavalue = "SIZE"
|
||
13 years ago
|
untrusted = True
|
||
13 years ago
|
|
||
|
def init(self):
|
||
13 years ago
|
self.label = _("Root partition size")+ " (MB)"
|
||
12 years ago
|
self.help = _("set the root partition size for autopartition")
|
||
13 years ago
|
|
||
|
def get(self):
|
||
|
if self.Get('os_install_linux_system') == 'server':
|
||
13 years ago
|
size = 1024*20 # in M
|
||
13 years ago
|
else:
|
||
13 years ago
|
size = 1024*10 # in M
|
||
13 years ago
|
deviceSize = self.Get('cl_autopartition_device_size')
|
||
13 years ago
|
if Sizes().from_M(size) >= deviceSize:
|
||
|
size = max(Sizes().to_M(deviceSize),Sizes().to_M(MINROOTSIZE))
|
||
13 years ago
|
return str(size)
|
||
13 years ago
|
|
||
13 years ago
|
def check(self,value):
|
||
|
if self.Get('cl_autopartition_device') and \
|
||
13 years ago
|
self.Get('cl_autopartition_set') == "on":
|
||
13 years ago
|
if int(value) < Sizes().to_M(MINROOTSIZE):
|
||
13 years ago
|
raise VariableError(
|
||
12 years ago
|
_("The root partition should be at least {size}").format(
|
||
13 years ago
|
size="7 Gb"))
|
||
13 years ago
|
|
||
11 years ago
|
def humanReadable(self):
|
||
11 years ago
|
return humanreadableSize(int(self.Get())*Sizes.M)
|
||
11 years ago
|
|
||
13 years ago
|
class VariableClAutopartitionTable(AutopartitionHelper,Variable):
|
||
13 years ago
|
"""
|
||
|
Partition table for autopartition
|
||
|
"""
|
||
13 years ago
|
type = "choice"
|
||
13 years ago
|
value = "gpt"
|
||
13 years ago
|
opt = ["--partition-table"]
|
||
|
metavalue = "TABLE"
|
||
|
|
||
|
def init(self):
|
||
|
self.label = _("Partition table")
|
||
12 years ago
|
self.help = _("set the partition table for autopartition")
|
||
13 years ago
|
|
||
|
def choice(self):
|
||
13 years ago
|
return [("dos","DOS-type Partition Table"),
|
||
|
("gpt","GUID Partition Table (GPT)")]
|
||
13 years ago
|
|
||
13 years ago
|
class VariableClAutopartitionDiskData(ReadonlyTableVariable):
|
||
13 years ago
|
"""
|
||
|
New partition data for autopart device
|
||
|
"""
|
||
|
source = ['cl_autopartition_disk_dev',
|
||
|
'cl_autopartition_disk_mount',
|
||
|
'cl_autopartition_disk_format',
|
||
|
'cl_autopartition_disk_size',
|
||
11 years ago
|
'cl_autopartition_disk_part',
|
||
|
'cl_autopartition_disk_scheme']
|
||
13 years ago
|
|
||
12 years ago
|
class VariableClAutopartitionBiosGrubSet(ReadonlyVariable):
|
||
|
"""
|
||
|
Create bios_grub partition
|
||
|
"""
|
||
|
type = "bool"
|
||
|
|
||
|
def get(self):
|
||
|
return "on" if "grub" in self.Get('cl_autopartition_scheme') else "off"
|
||
|
|
||
|
|
||
13 years ago
|
class VariableClAutopartitionLvmSet(ReadonlyVariable):
|
||
|
"""
|
||
|
Using LVM for autopartition
|
||
|
"""
|
||
|
type = "bool"
|
||
13 years ago
|
|
||
13 years ago
|
def get(self):
|
||
|
return "on" if "lvm" in self.Get('cl_autopartition_scheme') else "off"
|
||
13 years ago
|
|
||
12 years ago
|
class VariableClAutopartitionUefiSet(ReadonlyVariable):
|
||
|
"""
|
||
|
Using UEFI bootloader
|
||
|
"""
|
||
|
type = "bool"
|
||
|
|
||
|
def get(self):
|
||
|
return "on" if "uefi" in self.Get('cl_autopartition_scheme') else "off"
|
||
|
|
||
|
|
||
13 years ago
|
class VariableClAutopartitionLvmVgname(Variable):
|
||
|
"""
|
||
|
Volume group name for LVM autopartition
|
||
|
"""
|
||
|
|
||
|
def get(self):
|
||
|
def generateName(startName):
|
||
|
yield startName
|
||
|
for i in count(2):
|
||
|
yield "%s%d"%(startName,i)
|
||
|
for name in generateName("calculate"):
|
||
|
disks = self.Select('os_lvm_pvname',where='os_lvm_vgname',eq=name)
|
||
|
devices = self.Select('os_disk_parent',
|
||
|
where='os_disk_dev',_in=disks)
|
||
|
if set(devices) <= set(self.Get('cl_autopartition_device')):
|
||
|
return name
|
||
|
|
||
13 years ago
|
class VariableClAutopartitionDiskDev(ReadonlyVariable,AutopartitionHelper):
|
||
13 years ago
|
"""
|
||
|
Autopartition virtual disk on device
|
||
|
"""
|
||
|
type = "list"
|
||
|
|
||
13 years ago
|
def generateDisks(self,dos=False,devices=[],scheme=[],number=0):
|
||
13 years ago
|
"""
|
||
|
Generate disks for automount scheme
|
||
|
"""
|
||
|
number = 1
|
||
13 years ago
|
for line in self.deviceOpts(scheme):
|
||
|
# for dos 4 - extension
|
||
|
# for gpt 4 - for bios_boot
|
||
12 years ago
|
if number == 4 and (
|
||
|
self.Get('cl_autopartition_bios_grub_set')=='on' or
|
||
|
dos):
|
||
13 years ago
|
number += 1
|
||
13 years ago
|
yield "%s%d"%(devices[0],number)
|
||
13 years ago
|
number += 1
|
||
13 years ago
|
|
||
13 years ago
|
def generateLvm(self,scheme=[],devices=[],**kwargs):
|
||
13 years ago
|
vgname = self.Get('cl_autopartition_lvm_vgname')
|
||
12 years ago
|
number = 1
|
||
13 years ago
|
for line in map(lambda x:{'root':'root2',
|
||
|
'root2':'root'}.get(x,x),
|
||
|
self.deviceOpts(scheme)):
|
||
12 years ago
|
if line in ("boot","uefi"):
|
||
12 years ago
|
if number == 4 and \
|
||
|
self.Get('cl_autopartition_bios_grub_set')=='on':
|
||
12 years ago
|
number += 1
|
||
|
yield "%s%d"%(devices[0],number)
|
||
|
number += 1
|
||
|
else:
|
||
|
yield "/dev/%s/%s"%(vgname,line)
|
||
13 years ago
|
|
||
|
def diskGenerator(self):
|
||
|
if self.Get('cl_autopartition_lvm_set') == 'on':
|
||
|
return self.generateLvm
|
||
|
else:
|
||
|
return self.generateDisks
|
||
|
|
||
13 years ago
|
def get(self):
|
||
13 years ago
|
if self.Get('cl_autopartition_set') == "on":
|
||
13 years ago
|
scheme = self.getAutopartitionScheme()
|
||
13 years ago
|
devices = self.Get('cl_autopartition_device')
|
||
|
if devices:
|
||
|
res = list(self.diskGenerator()(
|
||
|
devices=devices,
|
||
|
scheme=scheme,
|
||
|
dos=self.Get('cl_autopartition_table')=='dos'))
|
||
13 years ago
|
return res
|
||
13 years ago
|
return []
|
||
|
|
||
11 years ago
|
class VariableClAutopartitionDiskScheme(ReadonlyVariable,AutopartitionHelper):
|
||
|
"""
|
||
|
Назначение раздела относительно схемы авторазметки
|
||
|
"""
|
||
|
type = "list"
|
||
|
|
||
|
def generateScheme(self,scheme):
|
||
|
"""
|
||
|
Generate mount points for automount scheme
|
||
|
"""
|
||
|
for line in self.deviceOpts(scheme):
|
||
|
yield line
|
||
|
|
||
|
def get(self):
|
||
|
if self.Get('cl_autopartition_set') == "on":
|
||
|
scheme = self.getAutopartitionScheme()
|
||
|
device = self.Get('cl_autopartition_device')
|
||
|
if device:
|
||
|
return list(self.generateScheme(scheme))
|
||
|
return []
|
||
|
|
||
13 years ago
|
class VariableClAutopartitionDiskMount(ReadonlyVariable,AutopartitionHelper):
|
||
13 years ago
|
"""
|
||
|
Autopartition mount points
|
||
|
"""
|
||
|
type = "list"
|
||
|
|
||
|
def generateMounts(self,scheme):
|
||
|
"""
|
||
|
Generate mount points for automount scheme
|
||
|
"""
|
||
13 years ago
|
for line in self.deviceOpts(scheme):
|
||
|
yield self.mpByOpts(line)
|
||
13 years ago
|
|
||
|
def get(self):
|
||
13 years ago
|
if self.Get('cl_autopartition_set') == "on":
|
||
13 years ago
|
scheme = self.getAutopartitionScheme()
|
||
|
device = self.Get('cl_autopartition_device')
|
||
|
if device:
|
||
|
return list(self.generateMounts(scheme))
|
||
13 years ago
|
return []
|
||
|
|
||
13 years ago
|
class VariableClAutopartitionDiskFormat(ReadonlyVariable,AutopartitionHelper):
|
||
13 years ago
|
"""
|
||
12 years ago
|
Autopartition disk filesystem
|
||
13 years ago
|
"""
|
||
|
type = "list"
|
||
|
|
||
|
def generateFormat(self,scheme):
|
||
|
"""
|
||
|
Generate filesystems for automount scheme
|
||
|
"""
|
||
13 years ago
|
for line in self.deviceOpts(scheme):
|
||
|
if line == "swap": yield "swap"
|
||
12 years ago
|
elif line == "uefi": yield "vfat"
|
||
13 years ago
|
else: yield FileSystemManager.defaultFS['hdd']
|
||
13 years ago
|
|
||
|
def get(self):
|
||
13 years ago
|
if self.Get('cl_autopartition_set') == "on":
|
||
13 years ago
|
scheme = self.getAutopartitionScheme()
|
||
|
device = self.Get('cl_autopartition_device')
|
||
|
if device:
|
||
|
return list(self.generateFormat(scheme))
|
||
13 years ago
|
return []
|
||
|
|
||
13 years ago
|
class VariableClAutopartitionDiskPart(ReadonlyVariable,AutopartitionHelper):
|
||
13 years ago
|
"""
|
||
|
Autopartition partition type (primary,extended,logical,gpt)
|
||
|
"""
|
||
|
type = "list"
|
||
|
|
||
|
def generatePart(self,scheme,dos):
|
||
|
"""
|
||
|
Generate part type for automount scheme
|
||
|
"""
|
||
|
number = 1
|
||
13 years ago
|
for line in self.deviceOpts(scheme):
|
||
|
if dos:
|
||
|
if number < 4: yield "primary"
|
||
|
else: yield "logical"
|
||
|
number += 1
|
||
|
else:
|
||
|
yield "gpt"
|
||
13 years ago
|
|
||
|
def get(self):
|
||
13 years ago
|
if self.Get('cl_autopartition_set') == "on":
|
||
13 years ago
|
scheme = self.getAutopartitionScheme()
|
||
|
table = self.Get('cl_autopartition_table')
|
||
|
if scheme:
|
||
|
return list(self.generatePart(scheme,
|
||
|
self.Get('cl_autopartition_table')=='dos'))
|
||
13 years ago
|
return []
|
||
|
|
||
13 years ago
|
class VariableClAutopartitionDiskType(ReadonlyVariable,AutopartitionHelper):
|
||
13 years ago
|
"""
|
||
|
Autopartition partition scheme (simple - disk-partition)
|
||
|
"""
|
||
|
type = "list"
|
||
|
|
||
|
def get(self):
|
||
13 years ago
|
if self.Get('cl_autopartition_set') == "on":
|
||
13 years ago
|
if self.Get('cl_autopartition_lvm_set')=="on":
|
||
|
diskType = "LVM"
|
||
|
else:
|
||
|
diskType = "disk-partition"
|
||
|
return [diskType]*len(self.Get('cl_autopartition_disk_dev'))
|
||
13 years ago
|
return []
|
||
13 years ago
|
|
||
13 years ago
|
class VariableClAutopartitionDiskSize(ReadonlyVariable,AutopartitionHelper):
|
||
13 years ago
|
"""
|
||
|
Autopartition disk size
|
||
|
"""
|
||
|
type = "list"
|
||
|
|
||
12 years ago
|
def generateSize(self,scheme,memory,bootsize,uefisize,rootsize,availsize):
|
||
13 years ago
|
args = {'swap':memory,
|
||
|
'root': rootsize,
|
||
|
'root2': rootsize,
|
||
13 years ago
|
'boot': bootsize,
|
||
12 years ago
|
'uefi': uefisize,
|
||
13 years ago
|
}
|
||
|
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:
|
||
|
yield str(MINROOTSIZE)
|
||
13 years ago
|
elif availsize < 1*Sizes.G:
|
||
|
yield str(1*Sizes.G)
|
||
13 years ago
|
else:
|
||
|
yield "allfree"
|
||
13 years ago
|
|
||
|
def get(self):
|
||
13 years ago
|
if self.Get('cl_autopartition_set') == "on":
|
||
13 years ago
|
scheme = self.getAutopartitionScheme()
|
||
|
device = self.Get('cl_autopartition_device')
|
||
|
availSize = self.Get('cl_autopartition_device_size')
|
||
|
if device:
|
||
13 years ago
|
return list(self.generateSize(scheme,
|
||
11 years ago
|
str(int(self.Get('cl_autopartition_swap_size'))
|
||
|
*Sizes.M),
|
||
13 years ago
|
self.Get('cl_autopartition_boot_size'),
|
||
12 years ago
|
self.Get('cl_autopartition_uefi_size'),
|
||
13 years ago
|
str(int(self.Get('cl_autopartition_root_size'))
|
||
13 years ago
|
*Sizes.M),int(availSize)))
|
||
13 years ago
|
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()))
|
||
|
|
||
12 years ago
|
class VariableClAutopartitionUefiSize(Variable):
|
||
|
"""
|
||
|
Size of EF00 partition
|
||
|
"""
|
||
|
value = str(200*Sizes.M)
|
||
|
|
||
13 years ago
|
class VariableClAutopartitionBootSize(Variable):
|
||
|
"""
|
||
|
Size of boot partition
|
||
|
"""
|
||
|
value = str(512*Sizes.M)
|
||
|
|
||
11 years ago
|
class VariableClAutopartitionBiosGrubSize(Variable):
|
||
|
"""
|
||
|
Размер раздела bios_grub для авторазметки
|
||
|
"""
|
||
|
value = str(10*Sizes.M)
|
||
|
|
||
13 years ago
|
class VariableClAutopartitionDeviceSize(ReadonlyVariable):
|
||
|
"""
|
||
|
Available devices size
|
||
|
"""
|
||
|
def get(self):
|
||
|
devices = self.Get('cl_autopartition_device')
|
||
|
if not devices:
|
||
|
return '0'
|
||
|
sizeDevice = map(int,self.Select('os_device_size',
|
||
|
where='os_device_dev',
|
||
|
_in=devices))
|
||
|
# TODO: remove set 10G
|
||
13 years ago
|
#return str(1024*1024*1024*10)
|
||
12 years ago
|
return str(reduce(operator.add,sizeDevice,0))
|
||
13 years ago
|
|
||
13 years ago
|
class VariableClAutopartitionFreeSize(ReadonlyVariable):
|
||
|
"""
|
||
|
Freesize of device with current root_size and memory
|
||
|
"""
|
||
|
type = "int"
|
||
|
|
||
|
def get(self):
|
||
13 years ago
|
sizeDevice = int(self.Get('cl_autopartition_device_size'))
|
||
13 years ago
|
sizes = self.Get('cl_autopartition_disk_size')
|
||
13 years ago
|
return str(reduce(lambda x,y: (x - int(y)) if y.isdigit() else x,
|
||
|
sizes,int(sizeDevice)))
|
||
13 years ago
|
|
||
13 years ago
|
class VariableClAutopartitionBindData(ReadonlyTableVariable):
|
||
13 years ago
|
"""
|
||
|
Autopartition bind data
|
||
|
"""
|
||
|
source = ['cl_autopartition_bind_path',
|
||
|
'cl_autopartition_bind_mountpoint']
|
||
|
|
||
13 years ago
|
class VariableClAutopartitionBindPath(ReadonlyVariable,AutopartitionHelper):
|
||
13 years ago
|
"""
|
||
|
Autopartition bind points
|
||
|
"""
|
||
|
type = "list"
|
||
|
|
||
|
def generatePath(self,scheme):
|
||
13 years ago
|
for line in self.bindOpts(scheme):
|
||
|
yield self.sourceMpByOpts(line)
|
||
13 years ago
|
|
||
|
def get(self):
|
||
13 years ago
|
if self.Get('cl_autopartition_set') == "on":
|
||
13 years ago
|
scheme = self.getAutopartitionScheme()
|
||
|
device = self.Get('cl_autopartition_device')
|
||
|
return list(self.generatePath(scheme))
|
||
|
return []
|
||
13 years ago
|
|
||
13 years ago
|
class VariableClAutopartitionBindMountpoint(ReadonlyVariable,
|
||
|
AutopartitionHelper):
|
||
13 years ago
|
"""
|
||
|
Autopartition bind points
|
||
|
"""
|
||
|
type = "list"
|
||
|
|
||
|
def generateMountPoint(self,scheme):
|
||
13 years ago
|
for line in self.bindOpts(scheme):
|
||
|
yield self.targetMpByOpts(line)
|
||
13 years ago
|
|
||
|
def get(self):
|
||
13 years ago
|
if self.Get('cl_autopartition_set') == "on":
|
||
13 years ago
|
scheme = self.getAutopartitionScheme()
|
||
|
device = self.Get('cl_autopartition_device')
|
||
|
return list(self.generateMountPoint(scheme))
|
||
|
return []
|