Fix multipartition for match of rules. Add bind table.

netsetup
Mike Hiretsky 14 years ago
parent 896961b312
commit b46a65bc9b

@ -181,7 +181,10 @@ class fillVars(object, glob_attr):
def isFstabMount(self,path):
"""Get mount point or device from fstab"""
absPath = os.path.abspath(path)
if path == "swap":
absPath = "swap"
else:
absPath = os.path.abspath(path)
# convert fstab to
# [['/dev/sda3', '/', '', 'reiserfs', 'noatime', '', '', '0', '2\n'],
# ['/dev/sda5', '/var/calculate', 'reiserfs', 'noatime', '0', '0\n']]

@ -78,15 +78,21 @@ class DataVarsInstall(DataVars):
class convertDictOpt:
"""Convert dict install option"""
_diskDefaultMountPoints = {"default":{"fileSystem":"reiserfs",
_defaultFS = "reiserfs"
_diskDefaultMountPoints = { "default":{"fileSystem":_defaultFS,
"isFormat":False,
"options":["noatime"]},
"/":{"fileSystem":_defaultFS,
"isFormat":True,
"options":["noatime"]},
"none":{"fileSystem":"",
"isFormat":False,
"options":[""]},
"/boot":{"fileSystem":"ext2",
"isFormat":True,
"options":["noatime"]}}
"options":[""]},}
#"/boot":{"fileSystem":"ext2",
# "isFormat":True,
# "options":["noatime"]}}
_bindDefaultMountPoint = {"fileSystem":"none",
"isFormat":False,
@ -96,7 +102,9 @@ class convertDictOpt:
"isFormat":False,
"options":["sw"]}
_propertiesFileSystem = {"default":_diskDefaultMountPoints['default'],
_propertiesFileSystem = {"default": {"fileSystem":_defaultFS,
"isFormat":True,
"options":[]},
"noformat":{"fileSystem":"",
"isFormat":False,
"options":[]}}
@ -482,10 +490,10 @@ class convertDictOpt:
def __call__(self, optionsDict={}):
"""Convert dict options (bind options, swap options or disk options)"""
optProperties = optionsDict.copy()
# bind options
if "srcMountPoint" in optProperties:
# bind options
dictOptions = {}
dictOptions.update(self.getDefaultOptBind())
dictOptions = self.getDefaultOptBind().copy()
dictOptions.update(optProperties)
return dictOptions
optDevice = optProperties["dev"]
@ -499,18 +507,26 @@ class convertDictOpt:
dictOptions = {}
optFileSystem = optProperties["fileSystem"]
optMountPoint = optProperties["mountPoint"]
# if specified mount point empty of default - it is /
if not optMountPoint or optMountPoint=="default":
optMountPoint = "/"
dictUpdateProperty["mountPoint"] = optMountPoint
supportedFS = self.getAllSupportFileSystemOpt()
# if fs not specified and current fs not supported
if not optFileSystem and \
not (format and format in supportedFS):
optFileSystem = "default"
# if specified fs
if optFileSystem:
if not optFileSystem in self.getAllSupportFileSystemOpt():
# if specified wrong fs
if not optFileSystem in supportedFS:
raise InstallError(_("Wrong file system options '%s'")\
%optFileSystem)
dictOptions.update(self.getDefaultOptFileSystem(optFileSystem))
if optFileSystem == "noformat":
if not format:
raise InstallError(\
_("Partition %s is not formatted %s")%dev)
_("Partition %s is not formatted")%dev)
if not options:
options = ["noatime"]
dictOptions["fileSystem"] = format
@ -527,9 +543,9 @@ class convertDictOpt:
optProperties = dict(filter(lambda x: x[1], optProperties.items()))
optProperties.update(dictUpdateProperty)
if dictOptions:
dictDefault = dictOptions
dictDefault = dictOptions.copy()
else:
dictDefault = self.getDefaultOptMountPoint(optMountPoint)
dictDefault = self.getDefaultOptMountPoint(optMountPoint).copy()
dictDefault.update(optProperties)
if flagCheckOptOptions:
# Check mount options
@ -544,8 +560,9 @@ class convertDictOpt:
optFileSystem = "swap"
if optFileSystem != format:
dictUpdateProperty["isFormat"] = True
dictOptions.update(self.getDefaultOptSwap())
dictOptions = self.getDefaultOptSwap().copy()
dictOptions.update(optProperties)
dictOptions.update(dictUpdateProperty)
return dictOptions
class cl_install(color_print):
@ -621,9 +638,10 @@ class cl_install(color_print):
#self.defaultPrint("%s\n"%_("Location"))
title, headerList, dataList = self.generateTableData()
tableObj = tableReport(title, headerList, dataList)
#cl_overriding.printSUCCESS("")
tableObj.printReport(False)
#cl_overriding.printSUCCESS("")
title, headerList, dataList = self.generateTableBindData()
tableObj = tableReport(title, headerList, dataList)
tableObj.printReport(False)
self.defaultPrint("%s\n"%_("Network services"))
self.printSUCCESS(_("Authentification")+": %s"%
@ -676,11 +694,55 @@ class cl_install(color_print):
else:
return dirsFiles
def _getTransferedDisksAndSwap(self,skipDev):
"""Get swap and disk info from fstab"""
def seporator(lists,disk):
"""If mountPoint of disk contains swap, then
append it to second list else in firest"""
if disk['mountPoint'] == 'swap':
return (lists[0],lists[1]+[disk])
else:
return (lists[0]+[disk],lists[1])
return reduce(seporator,
map(lambda x:{'isFormat':False,
'dev':x[0],
'options':x[1].split(','),
'mountPoint':x[2],
'fileSystem':x[3]},
filter(lambda x: not x[2] in ('','/') and
not x[0] in skipDev,
zip(self.clVars.Get('os_disk_dev'),
self.clVars.Get('os_disk_options'),
self.clVars.Get('os_install_disk_mount'),
self.clVars.Get('os_disk_format')))),
([],[]))
def _getTransferedBind(self,skipSrc,skipDest):
def list2binddict(l):
return {'srcMountPoint':l[0],
'isFormat':False,
'destMountPoint':l[1],
'options':['bind'],
'fileSystem':'none'}
return map(list2binddict,
filter(lambda x: not x[0] in skipSrc and
not x[1] in skipDest,
zip(self.clVars.Get('os_install_bind_dir'),
self.clVars.Get('os_install_bind_mountpoint'))))
def setInstallOptions(self, listDisks, listBinds, listSwaps):
"""Set data for installation partitions"""
convObj = convertDictOpt(self.clVars)
try:
listDisks = map(convObj, listDisks)
# detect previous system if not specified root partition
if not filter(lambda x: x['mountPoint'] == '/',listDisks):
prevRootDev = self.detectPreviousSystem()
if prevRootDev:
listDisks += map(convObj, [{'mountPoint': '',
'options': [],
'dev': prevRootDev[0],
'fileSystem': ''}])
listBinds = map(convObj, listBinds)
listSwaps = map(convObj, listSwaps)
except InstallError,e:
@ -689,10 +751,19 @@ class cl_install(color_print):
self.printWARNING(_("See 'man mount' for file system") + " "+\
", ".join(convObj.listFileSystemCorrupted))
return False
# cmd options
self.listDisksOptions = listDisks
self.listBindsOptions = listBinds
self.listSwapsOptions = listSwaps
# get current fstab config
fstabDisks,fstabSwap = self._getTransferedDisksAndSwap(
map(lambda x: x['dev'],listDisks+listSwaps))
fstabBinds = self._getTransferedBind(
map(lambda x: x['srcMountPoint'],listBinds),
map(lambda x: x['destMountPoint'],listBinds))
self.listDisksOptions = sorted( fstabDisks + listDisks,
lambda x,y:cmp(x['mountPoint'],y['mountPoint']))
#self.listBindsOptions = sorted( fstabBinds + listBinds,
# lambda x,y:cmp(x['destMountPoint'],
# y['destMountPoint']))
self.listBindsOptions = fstabBinds + listBinds
self.listSwapsOptions = listSwaps or fstabSwap
installAllDevices = map(lambda x: x['dev'],listSwaps) +\
map(lambda x: x['dev'],listDisks)
# detect duplicate partition
@ -738,10 +809,18 @@ class cl_install(color_print):
%dev + " " + _("'%s' in current system")\
%mountPoint)
return False
osDiskDevices = self.clVars.Get('os_disk_dev')
if listDisks:
osDiskDevices = self.clVars.Get('os_disk_dev')
cmdDevices = map(lambda x: x['dev'], listDisks)
cmdMountPoints = map(lambda x: x['mountPoint'], listDisks)
# check for other partition not use current root device
rootdev = self.clVars.Get('os_root_dev')
if filter(lambda x: x == rootdev,cmdDevices):
self.printERROR(
_("Specified disk '%s' mounted to '/' in current system") %
rootdev)
return False
# Check '/' in start path
wrongCmdMountPoints = filter(lambda x: not x[0]=="/" and x!="none",
cmdMountPoints)
@ -803,6 +882,7 @@ class cl_install(color_print):
listInstallMountOptions = []
listInstallFileSystem = []
listInstallPerformFormat = []
for dev, oldFileSystem, mountPoint, oldMountOpt in zip(\
self.clVars.Get('os_disk_dev'),
self.clVars.Get('os_disk_format'),
@ -814,8 +894,10 @@ class cl_install(color_print):
if cmdDataDev:
cmdMountOptions = cmdDataDev[0]["options"]
newFileSystem = cmdDataDev[0]["fileSystem"]
isFormat = "yes" if cmdDataDev[0]["isFormat"] else ""
else:
newFileSystem = oldFileSystem
isFormat = ""
listInstallFileSystem.append(newFileSystem)
if cmdMountOptions:
mountOptions = ",".join(cmdMountOptions)
@ -825,13 +907,17 @@ class cl_install(color_print):
else:
mountOptions = "noatime"
listInstallMountOptions.append(mountOptions)
listInstallPerformFormat.append(isFormat)
else:
listInstallMountOptions.append("")
listInstallFileSystem.append("")
listInstallPerformFormat.append("")
self.clVars.Set('os_install_disk_options', listInstallMountOptions,
True)
self.clVars.Set('os_install_disk_format', listInstallFileSystem,
True)
self.clVars.Set('os_install_disk_perform_format',
listInstallPerformFormat, True)
if listBinds:
cmdBindSrcDirs = map(lambda x: x['srcMountPoint'], listBinds)
@ -867,7 +953,7 @@ class cl_install(color_print):
listInstallMountOptions = []
listInstallFileSystem = []
# Check '/' in start device
wrongDevices = filter(lambda x: x["dev"][0]!="/" and \
wrongDevices = filter(lambda x: not x["dev"] in osDiskDevices and \
x["dev"]!="none",
listSwaps)
if wrongDevices:
@ -899,6 +985,13 @@ class cl_install(color_print):
True)
self.clVars.Set('os_install_disk_format', listInstallFileSystem,
True)
# discard disks without mountPoint (it specified with none mountPoint)
self.listDisksOptions = filter(lambda x: x['mountPoint'],
self.listDisksOptions)
self.listSwapsOptions = filter(lambda x: x['dev'] != "none",
self.listSwapsOptions)
self.listBindsOptions = filter(lambda x: x['destMountPoint'] != "none",
self.listBindsOptions)
return True
def getDeviceByField(self,field,value, secondPrefix="os_disk"):
@ -997,6 +1090,13 @@ class cl_install(color_print):
self.clVars.Get('os_install_disk_mount'))))
return title, headerList, dataList
def generateTableBindData(self):
"""Get bind data for print table"""
title = _("Bind mounts")
headerList = [_("Source directory"),_("Mount point")]
return title, headerList, zip(self.clVars.Get('os_install_bind_dir'),
self.clVars.Get('os_install_bind_mountpoint'))
def getPwdHashUser(self, userName):
cl_overriding.printSUCCESS(_("Enter password for user %s") %userName)
userPwd = getUserPassword()
@ -1094,7 +1194,7 @@ the system") + " (yes/no)"
fileSystem = diskOptions["fileSystem"]
isFormat = diskOptions["isFormat"]
objMultiPartitions.addPartition(dev=dev,
mountPoint=mountPoint,
mountPoint=mountPoint,
fileSystem=fileSystem,
isFormat=isFormat)
# Swap multipartitions

@ -124,10 +124,8 @@ class install_cmd(cl_install,share_cmd):
if values.live:
self.checkIncompatibeLive()
else:
if values.d == None:
values.d = self.detectPreviousSystem()
if values.v is False and \
values.d is None:
values.d is None and not self.detectPreviousSystem():
self.optobj.error(_("need specify disk by '-d' option"))
# check syntax DISK:DIR:FS:'Do I need to format the disk'
if values.d:

@ -46,8 +46,9 @@ if __name__ == "__main__":
if not install.setVars(options):
sys.exit(1)
# check and set installed options
if not install.checkAndSetInstallOptions(options.d,options.w,options.b):
sys.exit(1)
if not options.live:
if not install.checkAndSetInstallOptions(options.d,options.w,options.b):
sys.exit(1)
# print variables
if options.v:
install.displayVars(options.v)

Loading…
Cancel
Save