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.
1030 lines
41 KiB
1030 lines
41 KiB
#-*- coding: utf-8 -*-
|
|
|
|
# Copyright 2008-2012 Calculate Ltd. http://www.calculate-linux.org
|
|
#
|
|
# 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
|
|
from calculate.lib.cl_datavars import Variables,VariableError
|
|
#from calculate.lib.utils import ../calculate-lib3/calculate/lib/utils/device.py
|
|
from calculate.lib.utils.device import (getUdevDeviceInfo,getDeviceType,
|
|
getPartitionType,getPartitionDevice,getRaidPartitions,
|
|
getLvmPartitions,getPartitionSize,getUUIDDict)
|
|
from calculate.lib.utils.files import listDirectory,pathJoin,readFile,FStab
|
|
from calculate.install.cl_distr import PartitionDistributive
|
|
from calculate.install.cl_install import FileSystemManager
|
|
|
|
from calculate.lib.cl_lang import setLocalTranslate
|
|
setLocalTranslate('cl_install',sys.modules[__name__])
|
|
|
|
class InstallDisk(Variables):
|
|
vars = ["os_device_data","os_disk_data","os_disk_dev",
|
|
"os_install_root_type", "os_install_root_dev",
|
|
"os_install_disk_mount","os_disk_mount","os_disk_content",
|
|
"os_disk_format","os_disk_type","os_disk_parent",
|
|
"os_install_disk_format","os_install_disk_data",
|
|
"os_install_disk_perform_format","os_install_disk_uuid",
|
|
"os_install_disk_use","cl_uuid_set","os_install_disk_id",
|
|
"os_disk_uuid","os_disk_id","os_install_mbr","os_disk_grub",
|
|
"os_disk_part",
|
|
"os_disk_size","os_disk_name","os_disk_options","os_device_dev",
|
|
"os_device_type","os_device_map","os_device_table","os_device_name",
|
|
"os_install_disk_options","os_bind_data","os_bind_path",
|
|
"os_bind_mountpoint",
|
|
"os_install_bind_data","os_install_bind_path",
|
|
"os_install_bind_mountpoint",
|
|
"os_install_fstab_mount_conf","os_install_fstab_swap_conf",
|
|
"os_location_source", "os_location_dest", "os_location_format",
|
|
"os_location_perform_format", "os_location_data",
|
|
"os_install_disk_name", "os_install_disk_size",
|
|
"os_install_disk_type", "os_install_disk_dev",
|
|
"os_install_disk_part", "os_install_disk_parent"]
|
|
|
|
# infomation about disk in hash
|
|
os_disk_data = {'type':'table',
|
|
'source':['os_disk_dev',
|
|
'os_disk_uuid',
|
|
'os_disk_name',
|
|
'os_disk_size',
|
|
'os_disk_part',
|
|
'os_disk_format',
|
|
'os_disk_type',
|
|
'os_disk_parent',
|
|
'os_disk_id',
|
|
'os_disk_grub']}
|
|
|
|
# list of available partition devices
|
|
os_disk_dev = {'type':"list"}
|
|
|
|
# list mounted points for current operation system
|
|
os_disk_mount = {'type':"list"}
|
|
|
|
# partition content
|
|
os_disk_content = {'type':"list"}
|
|
|
|
# list filesystem for partition devices
|
|
os_disk_format = {'type':"list"}
|
|
|
|
# list type (lvm,raid,partition,disk)
|
|
os_disk_type = {'type':"list"}
|
|
|
|
# list uudi for partition devices
|
|
os_disk_uuid = {'type':"list"}
|
|
|
|
# list parent deivces for partition
|
|
os_disk_parent = {'type':"list"}
|
|
|
|
# partition's system id
|
|
os_disk_id = {'type':"list"}
|
|
|
|
# list grub id for partition devices
|
|
os_disk_grub = {'type':"list"}
|
|
|
|
# type of partition devices
|
|
# if msdos then(primary, extended or logical)
|
|
# if gpt then gpt
|
|
os_disk_part = {'type':"list"}
|
|
|
|
# partition size
|
|
os_disk_size = {'type':"list"}
|
|
|
|
# label of partitions
|
|
os_disk_name = {'type':"list"}
|
|
|
|
# list mount options
|
|
os_disk_options = {'type':"list"}
|
|
|
|
# disk variable
|
|
os_location_data = {
|
|
'type':"table",
|
|
'opt':["--disk","-d"],
|
|
'metavalue':'DISKS',
|
|
'help':_("DISK for installation, will be mounted to DIR. "
|
|
"DIR set to 'none' will cancel the mount point "
|
|
"transfer. For creating bind mount point you have "
|
|
"to specify the source directory as DISK"),
|
|
'label':_("Locations"),
|
|
'mode':"w",
|
|
'source':["os_location_source",
|
|
"os_location_dest",
|
|
"os_location_format",
|
|
"os_location_perform_format"]}
|
|
|
|
os_location_source = {'type':"choiceedit-list",
|
|
'label':_("Disk or directory"),
|
|
'mode':"w"}
|
|
|
|
os_location_dest = {'type':"choiceedit-list",
|
|
'label':_("Mount point"),
|
|
'mode':"w"}
|
|
|
|
os_location_format = {'type':"choice-list",
|
|
'label':_("File system"),
|
|
'mode':"w"}
|
|
|
|
os_location_perform_format = {'type':"bool-list",
|
|
'label':_("Format"),
|
|
'mode':"w"}
|
|
|
|
cl_uuid_set = {'value':'on',
|
|
'type':'bool',
|
|
'label':_("Use UUID"),
|
|
'opt':["--uuid"],
|
|
'help':_("use UUID"),
|
|
'mode':'w'}
|
|
|
|
os_install_disk_data = {'type':"table",
|
|
'source':['os_install_disk_dev',
|
|
'os_install_disk_mount',
|
|
'os_install_disk_format',
|
|
'os_install_disk_perform_format',
|
|
'os_install_disk_options',
|
|
'os_install_disk_id',
|
|
'os_install_disk_uuid',
|
|
'os_install_disk_use',
|
|
"os_install_disk_name",
|
|
"os_install_disk_size",
|
|
"os_install_disk_type",
|
|
"os_install_disk_part",
|
|
"os_install_disk_parent"
|
|
]}
|
|
|
|
# disks for installation
|
|
os_install_disk_dev = {'type':"list"}
|
|
|
|
# uudi for install
|
|
os_install_disk_uuid = {'type':"list"}
|
|
|
|
# list mounted points for installed system
|
|
os_install_disk_mount = {'type':"list"}
|
|
|
|
# /dev/sd or UUID= list (by cl_uuid_set)
|
|
os_install_disk_use = {'type':"list"}
|
|
|
|
# list mount options of installed os
|
|
os_install_disk_options = {'type':"list"}
|
|
|
|
# install list filesystem for partition devices
|
|
os_install_disk_format = {'type':"choice-list"}
|
|
|
|
# need format
|
|
os_install_disk_perform_format = {'type':"bool-list"}
|
|
|
|
# install partition's system id
|
|
os_install_disk_id = {'type':"list"}
|
|
|
|
# new labels for disk
|
|
os_install_disk_name = {'type':"list",
|
|
'mode':"w"}
|
|
|
|
# new partition sizes (for feature change partition)
|
|
os_install_disk_size = {'type':"list"}
|
|
|
|
# new partition scheme (for feature change partition)
|
|
os_install_disk_type = {'type':"list"}
|
|
|
|
# new partition type
|
|
os_install_disk_part = {'type':"list"}
|
|
|
|
# partition parent
|
|
os_install_disk_parent = {'type':"list"}
|
|
# disk for boot mbr
|
|
os_install_mbr = {'type':"list",
|
|
'opt':['--mbr'],
|
|
'metavalue':'MBR',
|
|
'label':"Disk for install",
|
|
'mode':"w"}
|
|
|
|
# devices
|
|
os_device_data = {'type':'table',
|
|
'source':['os_device_dev',
|
|
'os_device_table',
|
|
'os_device_type',
|
|
'os_device_map',
|
|
'os_device_name']}
|
|
|
|
os_device_dev = {'type':'list'}
|
|
|
|
# device type (hdd,cdrom,usb-flash)
|
|
os_device_type = {'type':'list'}
|
|
|
|
# map number for grub
|
|
os_device_map = {'type':'list'}
|
|
|
|
# table for device
|
|
os_device_table = {'type':'list'}
|
|
|
|
# name of device
|
|
os_device_name = {'type':'list'}
|
|
|
|
os_bind_data = {'type':'table',
|
|
'source':['os_bind_path',
|
|
'os_bind_mountpoint']}
|
|
|
|
# directories for bind
|
|
os_bind_path = {'type':"list"}
|
|
|
|
# mountpoint for directories bind
|
|
os_bind_mountpoint = {'type':"list"}
|
|
|
|
os_install_bind_data = {'type':"table",
|
|
'source':['os_install_bind_path',
|
|
'os_install_bind_mountpoint']}
|
|
|
|
# install directories for bind
|
|
os_install_bind_path = {'type':"list"}
|
|
|
|
# mountpoint for install directories bind
|
|
os_install_bind_mountpoint = {'type':"list"}
|
|
|
|
# information about mount points for fstab
|
|
os_install_fstab_mount_conf = {}
|
|
|
|
# information about swap for fstab
|
|
os_install_fstab_swap_conf = {}
|
|
|
|
sysBlockPath = '/sys/block'
|
|
rePassDevice = re.compile("^(?!%s)"%"|".join(['fd','ram','loop']))
|
|
|
|
def getTableByChild(self,device):
|
|
"""Get table by child partitions"""
|
|
syspath = getUdevDeviceInfo(name=device).get('DEVPATH','')
|
|
if not syspath.startswith('/sys'):
|
|
syspath = pathJoin('/sys',syspath)
|
|
shortnameDevice = path.basename(device)
|
|
childs = filter(lambda x:x.startswith(shortnameDevice),
|
|
listDirectory(syspath))
|
|
if childs:
|
|
child = pathJoin(syspath,childs[0])
|
|
return getUdevDeviceInfo(path=child).get('ID_PART_ENTRY_SCHEME','')
|
|
return ""
|
|
|
|
def separateDevice(self,device):
|
|
return map(lambda x: int(x) if x.isdigit() else x,
|
|
re.findall('\d+|\D+',device))
|
|
|
|
def get_os_device_dev(self):
|
|
"""Get device /dev name"""
|
|
def getDiskName(devpath):
|
|
"""Get devname only for by udevadm that devpath is device (disk)"""
|
|
prop = getUdevDeviceInfo(devpath)
|
|
if prop.get("ID_TYPE","")=="disk" and \
|
|
prop.get("DEVTYPE","")=="disk":
|
|
return prop.get('DEVNAME','')
|
|
|
|
# get devices from /sys/block directories(discard mem,sr,loop and other)
|
|
return sorted(
|
|
filter(lambda x:x,
|
|
map(getDiskName,
|
|
map(lambda x:path.join(self.sysBlockPath,x),
|
|
filter(self.rePassDevice.search,
|
|
listDirectory(self.sysBlockPath))))),
|
|
key=self.separateDevice)
|
|
|
|
def get_os_device_table(self):
|
|
"""Get device partition table"""
|
|
def getTable(device):
|
|
prop = getUdevDeviceInfo(name=device)
|
|
return prop.get('ID_PART_TABLE_TYPE',
|
|
self.getTableByChild(device))
|
|
return map(getTable,
|
|
self.Get('os_device_dev'))
|
|
|
|
def get_os_device_type(self):
|
|
"""Get device type (hdd,usb-hdd,flash)"""
|
|
# get usb device by '/dev/disk/by-id'(usb devices contain 'usb' in name)
|
|
diskIdPath = '/dev/disk/by-id'
|
|
if path.exists(diskIdPath):
|
|
usbdevices = \
|
|
map(lambda x: \
|
|
os.readlink(path.join(diskIdPath,x)).rpartition('/')[2],
|
|
filter(lambda x: x.startswith('usb-'),listDirectory(diskIdPath)))
|
|
else:
|
|
usbdevices = []
|
|
def getType(device):
|
|
if path.basename(device) in usbdevices:
|
|
# check for usb flash (removeable fiel in sysfs contains "1")
|
|
removablePath = '/sys/block/%s/removable'%path.basename(device)
|
|
if readFile(removablePath).strip() == "1":
|
|
return "flash"
|
|
else:
|
|
return "usb-hdd"
|
|
else:
|
|
return "hdd"
|
|
return map(getType,
|
|
self.Get('os_device_dev'))
|
|
|
|
def get_os_device_map(self):
|
|
"""Get device map for legecy grub"""
|
|
return map(lambda x:x[0],
|
|
enumerate(self.Get('os_device_dev')))
|
|
|
|
def get_os_device_name(self):
|
|
"""Get device name"""
|
|
def getName(device):
|
|
prop = getUdevDeviceInfo(name=device)
|
|
devicepath = prop.get("DEVPATH","")
|
|
if devicepath:
|
|
if not devicepath.startswith("/sys"):
|
|
devicepath = pathJoin("/sys",devicepath)
|
|
pathVendor = "%s/device/vendor"%devicepath
|
|
pathModel = "%s/device/model"%devicepath
|
|
return ("%s %s"% \
|
|
(readFile(pathVendor).strip(),
|
|
readFile(pathModel).strip())).strip()
|
|
else:
|
|
return ""
|
|
return map(getName,
|
|
self.Get('os_device_dev'))
|
|
|
|
def get_os_disk_dev(self):
|
|
"""Get list of partition devices"""
|
|
def selfOrPartition(devpath):
|
|
"""Return self device or partitions if it has them"""
|
|
# search partition in device
|
|
# get devices in sysfs which startswith devname
|
|
partitions = \
|
|
filter(lambda x:x.startswith(path.basename(devpath)),
|
|
listDirectory(devpath))
|
|
# if partition found then return them or partition on them
|
|
if partitions:
|
|
return filter(lambda x:x,
|
|
map(lambda x:selfOrPartition(path.join(devpath,x)),
|
|
partitions))
|
|
else:
|
|
return devpath
|
|
|
|
# get disks from sys block which not contains partitions
|
|
return list(sorted(
|
|
filter(lambda x:x,
|
|
map(lambda x:getUdevDeviceInfo(x).get('DEVNAME',''),
|
|
reduce(lambda x,y:x+ ([y] if type(y) == str else y),
|
|
map(lambda x:selfOrPartition(
|
|
path.join(self.sysBlockPath,x)),
|
|
filter(self.rePassDevice.search,
|
|
listDirectory(self.sysBlockPath))),[])))))
|
|
|
|
def mapUdevProperty(self,var,prop,default):
|
|
"""Get each element from var through udev [prop]"""
|
|
return map(lambda x:getUdevDeviceInfo(name=x).get(prop,default),
|
|
self.Get(var))
|
|
|
|
def get_os_disk_uuid(self):
|
|
"""Get disk uuid"""
|
|
return self.mapUdevProperty('os_disk_dev','ID_FS_UUID','')
|
|
|
|
def get_os_disk_name(self):
|
|
"""Get disk label"""
|
|
return self.mapUdevProperty('os_disk_dev','ID_FS_LABEL','')
|
|
|
|
def get_os_disk_part(self):
|
|
"""Get type of partition"""
|
|
return map(lambda x:getPartitionType(getUdevDeviceInfo(name=x)),
|
|
self.Get('os_disk_dev'))
|
|
|
|
def get_os_disk_id(self):
|
|
"""Get disk id"""
|
|
mapTypeUUID = {'ebd0a0a2-b9e5-4433-87c0-68b6b72699c7':'0700',
|
|
'0657fd6d-a4ab-43c4-84e5-0933c84b4f4f':'8200',
|
|
'a19d880f-05fc-4d3b-a006-743f0f84911e':'FD00',
|
|
'21686148-6449-6e6f-744e-656564454649':'EF02'}
|
|
return map(lambda x:mapTypeUUID.get(x,x),
|
|
map(lambda x:x.rpartition("x")[2],
|
|
self.mapUdevProperty('os_disk_dev','ID_PART_ENTRY_TYPE','')))
|
|
|
|
def get_os_disk_format(self):
|
|
"""Get current disk file system"""
|
|
fstab = FStab('/etc/fstab')
|
|
def getFormat(device):
|
|
prop = getUdevDeviceInfo(name=device)
|
|
return prop.get('FSTAB_TYPE') or \
|
|
fstab.getBy(what=fstab.TYPE,eq=device) or \
|
|
prop.get('ID_FS_TYPE','')
|
|
return map(getFormat,
|
|
self.Get('os_disk_dev'))
|
|
|
|
def get_os_disk_options(self):
|
|
"""Get current disk file system"""
|
|
fstab = FStab('/etc/fstab')
|
|
def getFormat(device):
|
|
return fstab.getBy(what=fstab.OPTS,eq=device)
|
|
return map(getFormat,
|
|
self.Get('os_disk_dev'))
|
|
|
|
def get_os_disk_type(self):
|
|
"""Get partition scheme"""
|
|
types = map(lambda x:(x,getDeviceType(name=x)),
|
|
self.Get('os_disk_dev'))
|
|
lvmUsedDisks = {}
|
|
raidUsedDisks = {}
|
|
def forMember(typeInfo):
|
|
diskName,diskType = typeInfo
|
|
if diskName in raidUsedDisks:
|
|
diskType = "%s-raidmember(%s)"%(diskType,
|
|
raidUsedDisks[diskName])
|
|
if diskName in lvmUsedDisks:
|
|
diskType = "%s-lvmmember(%s)"%(diskType,
|
|
",".join(lvmUsedDisks[diskName]))
|
|
return diskName,diskType
|
|
|
|
for device,diskType in types:
|
|
prop = getUdevDeviceInfo(name=device)
|
|
if "raid" in diskType:
|
|
for x in getRaidPartitions(prop.get('DEVPATH','')):
|
|
raidUsedDisks[x]=device
|
|
if diskType.endswith("lvm"):
|
|
for x in getLvmPartitions(prop.get('DM_VG_NAME',''),
|
|
prop.get('DM_LV_NAME','')):
|
|
if x in lvmUsedDisks:
|
|
lvmUsedDisks[x].append(device)
|
|
else:
|
|
lvmUsedDisks[x] = [device]
|
|
return map(lambda x:x[1],
|
|
map(forMember,
|
|
types))
|
|
|
|
def get_os_disk_parent(self):
|
|
"""Get disk parent"""
|
|
return map(getPartitionDevice,
|
|
map(lambda x:getUdevDeviceInfo(name=x).get('DEVPATH',''),
|
|
self.Get('os_disk_dev')))
|
|
|
|
def get_os_disk_grub(self):
|
|
"""Get disk grub map"""
|
|
devicesMap = dict(zip(self.Get('os_device_dev'),
|
|
self.Get('os_device_map')))
|
|
def getGrubMap(devParent):
|
|
device,parent = devParent
|
|
prop = getUdevDeviceInfo(name=device)
|
|
partnum = int(prop.get('ID_PART_ENTRY_NUMBER',0))
|
|
if parent in devicesMap.keys() and partnum:
|
|
return "%s,%d"%(devicesMap[parent],partnum-1)
|
|
else:
|
|
return ""
|
|
return map(getGrubMap,
|
|
zip(self.Get('os_disk_dev'),
|
|
self.Get('os_disk_parent')))
|
|
|
|
def get_os_disk_size(self):
|
|
"""Get disk size"""
|
|
def debug(x):
|
|
print x
|
|
return x
|
|
return map(lambda x:getPartitionSize(name=x),
|
|
self.Get('os_disk_dev'))
|
|
|
|
def get_os_disk_mount(self):
|
|
"""List mounted points for current operation system"""
|
|
disk_hash = self.Get('os_disk_dev')
|
|
fstab = FStab('/etc/fstab')
|
|
rootdev = self.Get('os_root_dev')
|
|
return map(lambda x: '/' if x == rootdev else fstab.getBy(eq=x) or "",
|
|
sorted(self.Get('os_disk_dev'),
|
|
key=self.separateDevice))
|
|
|
|
def get_os_bind_path(self):
|
|
"""Get source bind path"""
|
|
fstab = FStab('/etc/fstab')
|
|
return fstab.getBy(what=fstab.NAME,where=fstab.OPTS,
|
|
_in="bind",allentry=True)
|
|
|
|
def get_os_bind_mountpoint(self):
|
|
"""Get destination bind path"""
|
|
fstab = FStab('/etc/fstab')
|
|
return fstab.getBy(what=fstab.DIR,where=fstab.OPTS,
|
|
_in="bind",allentry=True)
|
|
|
|
def get_os_location_source(self):
|
|
return self.Get('os_disk_dev')+self.Get('os_bind_path')
|
|
|
|
def get_os_location_dest(self):
|
|
installFrom = self.Get('os_install_dev_from')
|
|
def installMountPoint(info):
|
|
dev,mount = info
|
|
if self.Get('cl_action') == 'system':
|
|
if dev == installFrom:
|
|
return "/"
|
|
elif mount == "/":
|
|
return ""
|
|
return mount
|
|
return map(installMountPoint,
|
|
zip(self.Get('os_disk_dev'),
|
|
self.Get('os_disk_mount')))+\
|
|
self.Get('os_bind_mountpoint')
|
|
|
|
def get_os_location_format(self):
|
|
mount = self.Get("os_location_dest")
|
|
source = self.Get("os_location_source")
|
|
value = [""]*len(source)
|
|
return map(self.default_os_location_format(),
|
|
zip(source,mount,value))
|
|
|
|
def get_os_location_perform_format(self):
|
|
mount = self.Get("os_location_dest")
|
|
source = self.Get("os_location_source")
|
|
fs = self.Get("os_location_format")
|
|
value = [""]*len(source)
|
|
return map(self.default_os_location_perform_format(),
|
|
zip(source,mount,fs,value))
|
|
|
|
def get_os_install_bind_mountpoint(self):
|
|
"""Get install bind destination"""
|
|
return map(lambda x:x[1],
|
|
filter(lambda x:not x[0].startswith('/dev/') and x[1],
|
|
zip(self.Get('os_location_source'),
|
|
self.Get('os_location_dest'))))
|
|
|
|
def get_os_install_bind_path(self):
|
|
"""Get install bind source"""
|
|
return map(lambda x:x[0],
|
|
filter(lambda x:not x[0].startswith('/dev/') and x[1],
|
|
zip(self.Get('os_location_source'),
|
|
self.Get('os_location_dest'))))
|
|
|
|
def get_os_install_disk_dev(self):
|
|
"""Get installation disks"""
|
|
return map(lambda x:x[0],
|
|
filter(lambda x:x[0].startswith('/dev/') and x[1],
|
|
zip(self.Get('os_location_source'),
|
|
self.Get('os_location_dest'))))
|
|
|
|
def get_os_install_disk_mount(self):
|
|
"""Get install disk dest"""
|
|
return map(lambda x:x[1],
|
|
filter(lambda x:x[0].startswith('/dev/') and x[1],
|
|
zip(self.Get('os_location_source'),
|
|
self.Get('os_location_dest'))))
|
|
|
|
def get_os_install_disk_format(self):
|
|
"""Get install disk filesystem"""
|
|
return map(lambda x:x[2],
|
|
filter(lambda x:x[0].startswith('/dev/') and x[1],
|
|
zip(self.Get('os_location_source'),
|
|
self.Get('os_location_dest'),
|
|
self.Get('os_location_format'))))
|
|
|
|
def get_os_install_disk_perform_format(self):
|
|
"""Get install disk perform format"""
|
|
return map(lambda x:x[2],
|
|
filter(lambda x:x[0].startswith('/dev/') and x[1],
|
|
zip(self.Get('os_location_source'),
|
|
self.Get('os_location_dest'),
|
|
self.Get('os_location_perform_format'))))
|
|
|
|
def get_os_install_disk_id(self):
|
|
"""List id for partition after installation"""
|
|
diskId = dict(zip(self.Get('os_disk_dev'),
|
|
self.Get('os_disk_id')))
|
|
def getIdByFS(fs,parttable,oldid):
|
|
if parttable == "gpt":
|
|
return PartitionDistributive.formatIdGpt.get(fs,oldid)
|
|
elif parttable in ("primary","extended","logical"):
|
|
return PartitionDistributive.formatId.get(fs,oldid)
|
|
return oldid
|
|
return map(lambda x:getIdByFS(x[0],
|
|
x[1], diskId.get(x[2],'')),
|
|
zip(self.Get('os_install_disk_format'),
|
|
self.Get('os_install_disk_part'),
|
|
self.Get('os_install_disk_dev')))
|
|
|
|
def get_os_install_disk_uuid(self):
|
|
"""Install disk UUID"""
|
|
diskDev = self.Get('os_install_disk_dev')
|
|
hashUUID = getUUIDDict(revers=True)
|
|
return map(lambda x:hashUUID.get(x,"")[5:],diskDev)
|
|
|
|
def get_os_install_disk_use(self):
|
|
"""Get real id (by cl_uuid_set) device"""
|
|
if self.Get('cl_uuid_set') == "on":
|
|
return map(lambda x:"UUID=%s"%x[0] if x[0] else x[1],
|
|
zip(self.Get('os_install_disk_uuid'),
|
|
self.Get('os_install_disk_dev')))
|
|
else:
|
|
return self.Get('os_install_disk_dev')
|
|
|
|
def get_os_install_disk_name(self):
|
|
"""Get new labels for disks"""
|
|
diskLabel = dict(zip(self.Get('os_disk_dev'),
|
|
self.Get('os_disk_name')))
|
|
def changeLabel(info):
|
|
dev,mount = info
|
|
if mount == '/':
|
|
return "%s-%s"%(self.Get('os_install_linux_shortname'),
|
|
self.Get('os_install_linux_ver'))
|
|
else:
|
|
return diskLabel.get(dev,'')
|
|
return map(changeLabel,
|
|
zip(self.Get('os_install_disk_dev'),
|
|
self.Get('os_install_disk_mount')))
|
|
|
|
def get_os_install_disk_size(self):
|
|
"""Get new size for disks"""
|
|
diskSize = dict(zip(self.Get('os_disk_dev'),
|
|
self.Get('os_disk_size')))
|
|
return map(lambda x:diskSize.get(x,''),
|
|
self.Get('os_install_disk_dev'))
|
|
|
|
def get_os_install_disk_type(self):
|
|
"""Get new disks sceheme"""
|
|
diskType = dict(zip(self.Get('os_disk_dev'),
|
|
self.Get('os_disk_type')))
|
|
return map(lambda x:diskType.get(x,''),
|
|
self.Get('os_install_disk_dev'))
|
|
|
|
def get_os_install_disk_part(self):
|
|
"""Get new type partitions"""
|
|
diskPart = dict(zip(self.Get('os_disk_dev'),
|
|
self.Get('os_disk_part')))
|
|
return map(lambda x:diskPart.get(x,''),
|
|
self.Get('os_install_disk_dev'))
|
|
|
|
def get_os_install_disk_parent(self):
|
|
"""Get parent for install disk"""
|
|
diskParent = dict(zip(self.Get('os_disk_dev'),
|
|
self.Get('os_disk_parent')))
|
|
return map(lambda x:diskParent.get(x,''),
|
|
self.Get('os_install_disk_dev'))
|
|
|
|
def get_os_install_disk_options(self):
|
|
"""TODO: get real options"""
|
|
diskOpts = dict(zip(self.Get('os_disk_dev'),
|
|
self.Get('os_disk_options')))
|
|
return map(lambda x:diskOpts.get(x,''),
|
|
self.Get('os_install_disk_dev'))
|
|
|
|
def get_os_install_root_type(self):
|
|
"""Type of device for install"""
|
|
rootdev = self.Get('os_install_root_dev')
|
|
devicetype = getPartitionDevice(
|
|
getUdevDeviceInfo(name=rootdev).get('DEVPATH',''))
|
|
devicetype = map(lambda x: x[1],
|
|
filter(lambda x:x[0] == devicetype,
|
|
zip(self.Get('os_device_dev'),
|
|
self.Get('os_device_type'))))
|
|
if devicetype:
|
|
return devicetype[0]
|
|
else:
|
|
return self.Get('os_root_type')
|
|
|
|
def get_os_install_root_dev(self):
|
|
"""Get install root device"""
|
|
rootDevs = dict(zip(self.Get('os_install_disk_mount'),
|
|
self.Get('os_install_disk_dev')))
|
|
return rootDevs.get('/','')
|
|
|
|
def choice_os_location_source(self):
|
|
return self.Get('os_disk_dev')
|
|
|
|
def choice_os_location_dest(self):
|
|
return ['/','/boot','/var/calculate','/home','/usr','/var','/tmp','swap']
|
|
|
|
def check_os_location_source(self,value):
|
|
"""Check set location source"""
|
|
disks = filter(lambda x:x.startswith('/dev/'),value)
|
|
###########################
|
|
# check wrong dev
|
|
###########################
|
|
wrongDevices = list(set(disks) - \
|
|
set(self.Get('os_disk_dev')))
|
|
if wrongDevices:
|
|
raise VariableError(_("Incorrect device '%s'")%wrongDevices[0])
|
|
wrongSource = filter(lambda x:x and not x.startswith('/'),value)
|
|
if wrongSource:
|
|
raise VariableError(
|
|
_("Incorrect bind mount point '%s'")%wrongSource[0])
|
|
##########################
|
|
# detect duplicate devices
|
|
##########################
|
|
dupDevices = list(set(filter(lambda x:disks.count(x)>1,
|
|
disks)))
|
|
if dupDevices:
|
|
raise VariableError(_("Device '%s' is used twice")%dupDevices[0])
|
|
|
|
def check_os_location_dest(self,value):
|
|
"""Check set location source"""
|
|
################################
|
|
# check of root device specifing
|
|
################################
|
|
if not filter(lambda x:x == "/",value):
|
|
raise VariableError(_("For installation need specify root device"))
|
|
################################
|
|
source = self.Get("os_location_source")
|
|
disks = filter(lambda x:x[0].startswith('/dev/') and x[1],
|
|
zip(source,value))
|
|
disksDevs = map(lambda x:x[0],disks)
|
|
binds = filter(lambda x:not x[0].startswith('/dev/') and x[1],
|
|
zip(source,value))
|
|
##########################
|
|
# detect duplicate mps
|
|
##########################
|
|
dupMP = list(set(filter(lambda x:value.count(x)>1,
|
|
filter(lambda x:x,
|
|
value))))
|
|
if dupMP:
|
|
raise VariableError(_("Mount point '%s' is used twice")%dupMP[0])
|
|
#########################
|
|
# detect wrong bind
|
|
#########################
|
|
wrongBind = filter(lambda x:not x[0].startswith("/") or
|
|
not x[1].startswith("/"),
|
|
binds)
|
|
if wrongBind:
|
|
raise VariableError(
|
|
_("Incorrect mount point (bind '%(bindSrc)s' to "\
|
|
"'%(bindDst)s')")\
|
|
%{'bindSrc':wrongBind[0][0],
|
|
'bindDst':wrongBind[0][1]})
|
|
#########################################
|
|
# Check '/' in start path of dest pointst
|
|
#########################################
|
|
wrongMP = filter(lambda x:x and not x.startswith("/") and x != "swap",
|
|
value)
|
|
if wrongMP:
|
|
raise VariableError(_("Incorrect mount point '%s'")%wrongMP[0])
|
|
#########################################
|
|
# Check using current root
|
|
#########################################
|
|
rootDev = self.Get('os_root_dev')
|
|
if rootDev in self.Get('os_install_disk_dev'):
|
|
raise VariableError(
|
|
_("The current root partition %s can not be "
|
|
"used for installation")%rootDev)
|
|
#################################
|
|
# detect using extended partition
|
|
#################################
|
|
extendedPartitions = filter(lambda x: x[1]=="extended",
|
|
zip(self.Get('os_install_disk_dev'),
|
|
self.Get('os_install_disk_part')))
|
|
if extendedPartitions:
|
|
raise VariableError(
|
|
_("Unable to use the extended partition %s for installation")%
|
|
extendedPartitions[0][0])
|
|
##########################
|
|
# detect using CDROM disks
|
|
##########################
|
|
cdromPartitions = filter(lambda x: "cdrom" in x[1],
|
|
zip(self.Get('os_install_disk_dev'),
|
|
self.Get('os_install_disk_type')))
|
|
if cdromPartitions:
|
|
raise VariableError(_("Unable to use CDROM %s for installation")%
|
|
cdromPartitions[0][0])
|
|
###############################
|
|
# check cross bind mount points
|
|
###############################
|
|
DEVICE,MP = 0,1
|
|
srcMountPoints = map(lambda x:x[DEVICE],binds)
|
|
destMountPoints = map(lambda x:x[MP],binds)
|
|
wrongBind = filter(lambda x:x in destMountPoints,srcMountPoints)
|
|
if wrongBind:
|
|
incompBind = filter(lambda x:x[1]==wrongBind[0],
|
|
zip(srcMountPoints,destMountPoints))
|
|
raise VariableError(
|
|
_("Source directory %(src)s already used "
|
|
"for binding '%(bindSrc)s' to '%(bindDst)s'")\
|
|
%{'src':wrongBind[0],
|
|
'bindSrc':incompBind[0][0],
|
|
'bindDst':incompBind[0][1]})
|
|
#######################################
|
|
# check multipart for flash and builder
|
|
#######################################
|
|
osInstallRootType = self.Get('os_install_root_type')
|
|
if osInstallRootType == "flash":
|
|
if filter(lambda x: x != '/', value):
|
|
raise VariableError(_("Installation to flash disk is not supported for "
|
|
"multipartition install"))
|
|
if filter(lambda x: x == "swap",value):
|
|
raise VariableError(_("Installation to flash disk is not "
|
|
"supported for swap disks"))
|
|
########################################
|
|
# check install on member of RAID or LVM
|
|
########################################
|
|
installTypes = zip(self.Get('os_install_disk_dev'),
|
|
self.Get('os_install_disk_type'))
|
|
for checkType in ("raid","lvm"):
|
|
memberData = filter(lambda x:checkType in x[1],
|
|
installTypes)
|
|
if memberData:
|
|
raise VariableError(
|
|
_("Unable to use active {typepart} member {part} "
|
|
"for installation").format(
|
|
typepart=checkType.upper(),
|
|
part=memberData[0][0]))
|
|
|
|
def choice_os_location_format(self):
|
|
return self.Get('os_format_type')
|
|
|
|
def default_os_location_format(self):
|
|
"""Describe default value for filesystem"""
|
|
diskFormat = dict(zip(self.Get('os_disk_dev'),
|
|
(self.Get('os_disk_format'))))
|
|
osInstallRootType = self.Get('os_install_root_type')
|
|
availFS = set(map(lambda x:x[0],
|
|
filter(lambda x:x[1] == 'yes',
|
|
zip(self.Get('os_format_type'),
|
|
self.Get('os_format_use')))))
|
|
def wrap(info):
|
|
dev,mount,fs = info
|
|
if mount and not fs and dev.startswith('/dev/'):
|
|
if mount == "swap":
|
|
return "swap"
|
|
if dev in diskFormat and diskFormat[dev] in availFS:
|
|
if mount.count('/') == 1:
|
|
if FileSystemManager.checkFSForType(diskFormat[dev],
|
|
osInstallRootType):
|
|
return diskFormat[dev]
|
|
else:
|
|
return diskFormat[dev]
|
|
return FileSystemManager.defaultFS.get(osInstallRootType,
|
|
"ext4")
|
|
return fs
|
|
return wrap
|
|
|
|
def set_os_location_format(self,value):
|
|
mount = self.Get("os_location_dest")
|
|
source = self.Get("os_location_source")
|
|
return map(self.default_os_location_format(),
|
|
zip(source,mount,value))
|
|
|
|
def set_os_location_dest(self,value):
|
|
"""Add abilitiy not specify root"""
|
|
if len(value) == 1 and value[0] == "":
|
|
return ["/"]
|
|
else:
|
|
return value
|
|
|
|
def check_os_location_perform_format(self,value):
|
|
"""Check perform format
|
|
|
|
Check what format will perform for need partition.
|
|
At example on change file system on partition.
|
|
"""
|
|
DEV,MP,FS,FORMAT = 0,1,2,3
|
|
info = zip(self.Get('os_location_source'),
|
|
self.Get('os_location_dest'),
|
|
self.Get('os_location_format'),
|
|
value)
|
|
diskFormat = dict(zip(self.Get('os_disk_dev'),
|
|
(self.Get('os_disk_format'))))
|
|
diskMount = dict(zip(self.Get('os_disk_dev'),
|
|
(self.Get('os_disk_mount'))))
|
|
unavailFS = set(map(lambda x:x[0],
|
|
filter(lambda x:x[1] == 'no',
|
|
zip(self.Get('os_format_type'),
|
|
self.Get('os_format_use')))))
|
|
for dev,mp,fs,isformat in info:
|
|
if mp and diskFormat.get(dev,fs) != fs and diskMount.get(dev,''):
|
|
raise VariableError(
|
|
_("Disk {device} should be formatted, but can "
|
|
"not be formatted because mounted to "
|
|
"{mountpoint} in the current system").format(
|
|
device=dev,mountpoint=diskMount.get(dev,'')))
|
|
# has fs changed
|
|
if mp and diskFormat.get(dev,fs) != fs and not self.isTrue(isformat):
|
|
raise VariableError(
|
|
_("Disk {device} should be formatted").format(device=dev))
|
|
if self.isTrue(isformat):
|
|
if not mp:
|
|
raise VariableError(
|
|
_("No need to format the unused {dev} disk").format(
|
|
dev=dev))
|
|
if fs in unavailFS:
|
|
raise VariableError(
|
|
_("File system '%s' is not available")%fs)
|
|
if not dev.startswith('/dev/'):
|
|
raise VariableError(
|
|
_("Bind mount points should not be formatted"))
|
|
|
|
def default_os_location_perform_format(self):
|
|
diskFormat = dict(zip(self.Get('os_disk_dev'),
|
|
(self.Get('os_disk_format'))))
|
|
def wrap(info):
|
|
source,dest,fs,isformat = info
|
|
if not isformat and source.startswith('/dev/'):
|
|
if dest == '/':
|
|
return "yes"
|
|
if dest and diskFormat.get(source,fs) != fs:
|
|
return "yes"
|
|
return isformat
|
|
return wrap
|
|
|
|
def set_os_location_perform_format(self,value):
|
|
"""Default values for perform format"""
|
|
DEV,MP,FS,FORMAT = 0,1,2,3
|
|
info = zip(self.Get('os_location_source'),
|
|
self.Get('os_location_dest'),
|
|
self.Get('os_location_format'),
|
|
value)
|
|
test = map(self.default_os_location_perform_format(),
|
|
info)
|
|
return test
|
|
|
|
def check_os_location_format(self,value):
|
|
osInstallRootType = self.Get('os_install_root_type')
|
|
devMpFs = zip(self.Get('os_location_source'),
|
|
self.Get('os_location_dest'),value)
|
|
for dev,mp,fs in devMpFs:
|
|
# check compatible fs for mount point only root dirs
|
|
if dev.startswith('/dev/') and mp and (mp.count('/') == 1 or
|
|
mp == '/var/calculate'):
|
|
if not FileSystemManager.checkFSForType(fs,
|
|
osInstallRootType):
|
|
raise VariableError(
|
|
_("File system for '%(mp)s' should not be '%(opt)s'")
|
|
%{'mp':mp, 'opt':fs}+" "+
|
|
_("for {typedisk} installation").format(
|
|
typedisk=osInstallRootType))
|
|
if mp == "swap" and fs != "swap":
|
|
raise VariableError(
|
|
_("Swap partition {dev} must be formatted as swap").format(
|
|
dev=dev))
|
|
|
|
def get_os_install_mbr(self):
|
|
"""Get default Master boot record install
|
|
|
|
TODO: add get list of devices if install on RAID
|
|
"""
|
|
if self.Get('os_install_root_type') in ("flash","usb-hdd"):
|
|
rootdev = self.Get('os_install_root_dev')
|
|
device = filter(lambda x:x in rootdev,
|
|
self.Get('os_device_dev'))
|
|
if device:
|
|
return [device[0]]
|
|
else:
|
|
return []
|
|
# if loaded system livecd
|
|
if self.Get('os_root_type') == "livecd":
|
|
# search /boot device or / device, by priority /boot,/
|
|
bootDev=sorted(
|
|
filter(lambda x:x[0] in ('/','/boot'),
|
|
zip(self.Get('os_install_disk_mount'),
|
|
self.Get('os_disk_dev'))),
|
|
key=lambda x:x[0],reverse=True)
|
|
if bootDev:
|
|
bootdev = bootDev[0][1]
|
|
# search device for partition
|
|
device = filter(lambda x:x in bootdev,
|
|
self.Get('os_device_dev'))
|
|
# set it by default
|
|
if device:
|
|
return [device[0]]
|
|
if self.Get('os_device_dev'):
|
|
return [self.Get('os_device_dev')[0]]
|
|
return []
|
|
|
|
def _commentFstab(self,s,mp,dev):
|
|
"""Generate comment for /etc/fstab each line"""
|
|
if s.startswith("UUID"):
|
|
return "# %s was on %s during installation\n%s" % (mp,dev,s)
|
|
else:
|
|
return s
|
|
|
|
def get_os_install_fstab_mount_conf(self):
|
|
"""Information about mount points for fstab"""
|
|
devicesForFstab = sorted(filter(lambda x:x[1] != "" and x[1] != "swap",
|
|
zip(self.Get('os_install_disk_use'),
|
|
self.Get('os_install_disk_mount'),
|
|
self.Get('os_install_disk_format'),
|
|
self.Get('os_install_disk_options'),
|
|
self.Get('os_disk_dev'))),
|
|
lambda x,y: cmp(self.separateDevice(x[1]),
|
|
self.separateDevice(y[1])))
|
|
if self.Get('os_install_scratch') == "on":
|
|
devicesForFstab = filter(lambda x:x[1] != "/", devicesForFstab)
|
|
|
|
# rootLine one string, but it correct work if devicesForFstab is empty
|
|
rootLine = "\n".join(map(lambda x: "%s\t%s\t%s\t%s\t0 2" %
|
|
(self._commentFstab(x[0],x[1],x[4]),x[1],x[2],x[3]),
|
|
devicesForFstab[:1]))
|
|
otherLines = "\n".join(map(lambda x: "%s\t%s\t%s\t%s\t0 0" %
|
|
(self._commentFstab(x[0],x[1],x[4]),x[1],x[2],x[3]),
|
|
devicesForFstab[1:]))
|
|
|
|
bindData = zip(self.Get('os_install_bind_path'),
|
|
self.Get('os_install_bind_mountpoint'))
|
|
|
|
bindLines = "\n".join(map(lambda x: "%s\t%s\tnone\tbind\t0 0"\
|
|
%(x[0],x[1]), bindData))
|
|
return "\n".join(filter(lambda x: x, [rootLine,otherLines,bindLines]))
|
|
|
|
def get_os_install_fstab_swap_conf(self):
|
|
"""Information about swap for fstab"""
|
|
return "\n".join(map(lambda x: "%s\tnone\tswap\tsw\t0 0"%\
|
|
self._commentFstab(x[0],"swap",x[2]),
|
|
filter(lambda x: x[1] == "swap",
|
|
zip(self.Get('os_install_disk_use'),
|
|
self.Get('os_install_disk_mount'),
|
|
self.Get('os_disk_dev')))))
|