Change for set install devices

master3.3
Mike Hiretsky 14 years ago
parent 10ba81a1e2
commit 49b3b05cce

@ -24,6 +24,10 @@ from cl_utils import isMount
from cl_distr import DistributiveRepository
class fillVars(object, glob_attr):
nonTransferedDirs = ["/","/bin", "/dev", "/etc",
"/lib", "/lib32", "/lib64",
"/opt", "/proc", "/sbin",
"/sys", "/usr", "/var"]
def get_os_net_interfaces_info(self):
"""Информация о существующих сетевых интерфейсах"""
@ -172,9 +176,9 @@ class fillVars(object, glob_attr):
map(lambda x: [x[0], x[1]],
listFstab)),[""]))[0]
def get_os_disk_install(self):
def get_os_install_disk_mount(self):
"""List mounted points for installed system"""
rootdev = self.Get('os_root_dev')
rootdev = self.Get('os_install_root_dev')
disk_hash = self.Get('os_disk_hash')
def getMountPoint(disk):
if disk == rootdev:
@ -184,14 +188,14 @@ class fillVars(object, glob_attr):
return "swap"
else:
mount_point = self.isFstabMount(disk)
if mount_point == "/":
if mount_point in self.nonTransferedDirs:
return ""
else:
return mount_point
return map(lambda x: getMountPoint(x),
sorted(self.Get('os_disk_hash').keys()))
def get_os_disk_load(self):
def get_os_disk_mount(self):
"""List mounted points for current operation system"""
disk_hash = self.Get('os_disk_hash')
def isSwap(disk):
@ -215,6 +219,10 @@ class fillVars(object, glob_attr):
"""Type of partition devices (primary, extended or logical)"""
return self.getAttributeFromHash('os_disk_hash','part')
def get_os_disk_perform_format(self):
"""Needformat partitions"""
return self.getAttributeFromHash('os_disk_hash','needformat')
def get_os_disk_size(self):
"""Partition size"""
return self.getAttributeFromHash('os_disk_hash','size')
@ -252,7 +260,7 @@ class fillVars(object, glob_attr):
devicesForFstab = sorted(
filter(lambda x: x[1] != "" and x[1] != "swap",
zip(self.Get('os_disk_dev'),
self.Get('os_disk_install'),
self.Get('os_install_disk_mount'),
self.Get('os_disk_format'))),
lambda x,y: cmp(x[1],y[1]))
# rootLine one string, but it correct work if devicesForFstab is empty
@ -325,7 +333,7 @@ class fillVars(object, glob_attr):
return "\n".join(map(lambda x: "%s\tnone\tswap\tsw\t0 0"%x[0],
filter(lambda x: x[1] == "swap",
zip(self.Get('os_disk_dev'),
self.Get('os_disk_install')))))
self.Get('os_install_disk_mount')))))
def get_os_install_linux_system(self):
"""Get linux system (server or desktop)"""
@ -346,7 +354,7 @@ class fillVars(object, glob_attr):
"""Get scheduler for root device"""
root_dev = filter(lambda x: x[1] == '/',
zip(self.Get('os_disk_dev'),
self.Get('os_disk_install')))
self.Get('os_install_disk_mount')))
if root_dev:
root_dev = root_dev[0][0]
root_dev = filter(lambda x: x in root_dev,
@ -369,7 +377,7 @@ class fillVars(object, glob_attr):
def get_os_kernel_resume(self):
"""Kernel resume parameter"""
for dev, install in zip(self.Get('os_disk_dev'),
self.Get('os_disk_install')):
self.Get('os_install_disk_mount')):
if install == "swap":
return "resume=%s"%dev
return ""
@ -382,7 +390,7 @@ class fillVars(object, glob_attr):
grubconf = reRemoveComments.sub("",open(pathGrubConf,'r').read())
roothd = filter(lambda x: x[1] == '/',
zip(self.Get('os_disk_grub'),
self.Get('os_disk_install')))
self.Get('os_install_disk_mount')))
if roothd:
roothd = "root (hd%s)" % roothd[0][0]
return ("".join(filter(lambda x: not roothd in x,
@ -447,3 +455,47 @@ class fillVars(object, glob_attr):
return "Linux"
else:
return "Linux"
def get_os_bind_hash(self):
"""List mounted points for current operation system"""
# convert fstab to
# [['/dev/sda3', '/', '', 'reiserfs', 'noatime', '', '', '0', '2\n'],
# ['/dev/sda5', '/var/calculate', 'reiserfs', 'noatime', '0', '0\n']]
listFstab = map(lambda x: filter(lambda x: x,
x.replace('\t',' ').split(' ')),
filter(lambda x: not x.startswith('#') and x.strip(),
open("/etc/fstab")))
return dict(map(lambda x:[x[0],x[1]],
filter(lambda x: "bind" in x[3],
listFstab)))
def get_os_bind_dir(self):
"""Directories for bind"""
return sorted(self.Get('os_bind_hash').keys())
def get_os_bind_mountpoint(self):
"""Mountpoint for directories bind"""
bindhash = self.Get('os_bind_hash')
return [ bindhash[i] for i in sorted(bindhash.keys()) ]
def get_os_install_bind_dir(self):
"""Install directories for bind"""
return map(lambda x:x[0],
# skip nonTransferedDirs
filter(lambda x: not x[0] in self.nonTransferedDirs and
not x[1] in self.nonTransferedDirs,
zip(self.Get('os_bind_dir'),
self.Get('os_bind_mountpoint'))))
def get_os_install_bind_mountpoint(self):
"""Mountpoint for install directories bind"""
return map(lambda x:x[1],
# skip nonTransferedDirs
filter(lambda x: not x[0] in self.nonTransferedDirs and
not x[1] in self.nonTransferedDirs,
zip(self.Get('os_bind_dir'),
self.Get('os_bind_mountpoint'))))
def get_os_install_root_dev(self):
return self.Get('os_root_dev')

@ -147,7 +147,7 @@ class cl_install(color_print):
", ".join(map(lambda x: x[0],
filter(lambda x: not x[1] in ["","/","swap"],
zip(self.clVars.Get('os_disk_dev'),
self.clVars.Get('os_disk_load'))))))
self.clVars.Get('os_disk_mount'))))))
self.defaultPrint(_("Network services\n"))
self.printSUCCESS(_("PROXY")+": %s"%
@ -194,55 +194,110 @@ class cl_install(color_print):
def setInstallDisk(self,disks):
"""Set installation partitions"""
osdiskdev = self.clVars.Get('os_disk_dev')
# all disks must starts with /
wrongDisks = map(lambda x:x[0],
filter(lambda x: not x[0].startswith('/'),
disks))
if wrongDisks:
raise InstallError(_("Wrong disk names %s"%
", ".join(wrongDisks)))
# all mount points must starts with /
wrongMP = map(lambda x:x[1],
filter(lambda x: x[1] and
not x[1].startswith('/'),
disks))
if wrongMP:
raise InstallError(_("Wrong mount point %s"%
", ".join(wrongMP)))
# separate disks to binds and devices
binds, devs = [],[]
for i in disks:
if i[2] == "bind" or not i[0].startswith('/dev'):
binds.append(i)
else:
devs.append(i)
# default mount point for disks is root
devs = map(lambda x:[x[0], x[1] or '/', x[2], x[3]], devs)
# find wrong disks
wrongDisks = filter(lambda x: not x[0] in osdiskdev,disks)
wrongDisks = map(lambda x:x[0],
filter(lambda x: not x[0] in osdiskdev,
devs))
if wrongDisks:
raise InstallError(_("Wrong disk names %s"%", ".join(wrongDisks)))
# default mount point is root
disks = map(lambda x:[x[0],x[1] or '/',x[2]], disks)
raise InstallError(_("Disk %s is not exists"%
", ".join(wrongDisks)))
# root partition needed
if not filter(lambda x: x[1] == '/',disks):
rootDev = filter(lambda x: x[1] == '/',devs)
if not rootDev:
raise InstallError(_("Need specify root partition"))
rootDev = rootDev[0][0]
# detect duplicate mountPoints
mountPoints = map(lambda x:x[1], disks)
if list(set(mountPoints)) != mountPoints:
mountPoints = filter(lambda x:x, map(lambda x:x[1], devs + binds))
dupPoint = filter(lambda x: mountPoints.count(x)>1,set(mountPoints))
if dupPoint:
raise InstallError(_("Duplicate mount points %s")%", ".join(
filter(lambda x: mountPoints.count(x) > 1,
list(set(mountPoints)))))
# detect duplicate partition
devices = map(lambda x:x[0], disks)
if list(set(devices)) != devices:
raise InstallError(_("Duplicate devices points %s")%", ".join(
filter(lambda x: devices.count(x) > 1,
list(set(devices)))))
dupPoint))
## detect duplicate partition
devices = map(lambda x:x[0], devs)
dupDevices = filter(lambda x: devices.count(x)>1,set(devices))
if dupDevices:
raise InstallError(_("Duplicate devices %s")%", ".join(
dupDevices))
# detect using extended drives
usedExtendedDrives = map(lambda x: x[0] and x in devices,
filter(lambda x: x[1] == "extended",
zip(self.clVars.Get('os_disk_dev'),
self.clVars.Get('os_disk_part'))))
usedExtendedDrives = map(lambda x: x[0],
filter(lambda x: x[1] == "extended" and
x[0] in devices,
zip(self.clVars.Get('os_disk_dev'),
self.clVars.Get('os_disk_part'))))
if usedExtendedDrives:
raise InstallError(_("Specified disk '%s' is extended")%", ".join(
usedExtendedDrives))
#for disk in disks:
#
#else:
# osdiskload = \
# filter(lambda x: (x[1] or x[2] == "extended") and x[0] == disk,
# zip(self.clVars.Get('os_disk_dev'),
# self.clVars.Get('os_disk_load'),
# self.clVars.Get('os_disk_part')))
# if len(osdiskload) > 0:
# if osdiskload[0][2] == "extended":
# raise InstallError(
# _("Specified drive '%s' is extended"%disk))
# else:
# raise InstallError(
# _("Specified drive '%s' mounted to '%s'")%
# (disk,osdiskload[0][1]))
# else:
# self.clVars.Set('os_root_dev',disk,True)
usedExtendedDrives))
# find device on loaded system and check mounted
loadMount = filter(lambda x:x[0] == rootDev and x[1] != '',
zip(self.clVars.Get('os_disk_dev'),
self.clVars.Get('os_disk_mount')))
if loadMount:
raise InstallError(
_("Specified root disk '%s' mounted to '%s' in current system")%
(rootDev,loadMount[0][1]))
self.clVars.Set('os_install_root_dev',rootDev,True)
# change os_install_disk_mount
newDisks = dict(map(lambda x: [x[0],x[1]],devs))
self.clVars.Set('os_install_disk_mount',
map(lambda x: newDisks[x[0]] if x[0] in newDisks else x[1],
zip(self.clVars.Get('os_disk_dev'),
self.clVars.Get('os_install_disk_mount'))),True)
bdirs = map(lambda x: x[0],binds)
bmountpoints = map(lambda x: x[1],binds)
# remove from old the mountpoint definde by -d
loadbinds = filter(lambda x:not x[0] in bdirs and
not x[1] in bmountpoints,
zip(self.clVars.Get('os_install_bind_dir'),
self.clVars.Get('os_install_bind_mountpoint')))
# add new to old, remove empty mountpoint
loadbinds = loadbinds + filter(lambda x:x[1],
zip(bdirs,bmountpoints))
# reset new bind dirs
self.clVars.Set('os_install_bind_dir',map(lambda x:x[0],loadbinds),True)
self.clVars.Set('os_install_bind_mountpoint',map(lambda x:x[1],loadbinds),True)
# newFormat = dict(filter(lambda x: x[2],
# map(lambda x: [x[0],[x[2],[x[3]]],devs)))
#
#def pr(device,format):
# if device in newFormat
#self.clVars.Set('os_disk_format',
# map(lambda x: newFormat[x[0]] if x[0] in newFormat and newFormat[x[0]] else x[1],
# zip(self.clVars.Get('os_disk_dev'),
# self.clVars.Get('os_disk_format'))),True)
def getDeviceByField(self,field,value):
"""Get device by fields (install load format uuid grub part name)"""

@ -16,6 +16,7 @@
from cl_install import cl_install, InstallError, __app__, __version__
from cl_opt import opt
from cl_share_cmd import share_cmd
import re
import sys
from cl_lang import lang
@ -34,6 +35,7 @@ CMD_OPTIONS = [{'shortOption':"T",
{'shortOption':"d",
'longOption':"disk",
'optVal':"DISK[:[PART:FILESYSTEM]]",
'action':'append',
'help':_("the DISK for installation, which mounted to PART")
},
{'shortOption':"s",
@ -70,17 +72,19 @@ class install_cmd(cl_install,opt,share_cmd):
self.error(_("need specify disk by '-d' option"))
# check syntax DISK:PART:FS
if values.d:
wrongValue = filter(lambda x: x.count(":") > 2)
self.error(
_("option %s: disk specifing error: '%s'")
% ", ".join(wrongValue))
reTrueDisk = re.compile("^([^:]+(:[^:]*(:[^:]+(:(F|f))?)?)?)$")
wrongValue = filter(lambda x: not reTrueDisk.match(x),values.d)
if wrongValue:
self.error(
_("option %s: disk specifing error: '%s'")
% ("d",", ".join(wrongValue)))
if values.s:
choices = ['cld','cds','cls','css','cldg','cldx']
if not values.s.lower() in choices:
choices = ", ".join(map(repr, choices))
self.error(
_("option %s: invalid choice: %r (choose from %s)")
% (opt, values.s, choices))
% ("s", values.s, choices))
if values.b:
self.error(_("builder mode yet hasn`t supported"))
if not values.T in [None,"all"]:
@ -114,10 +118,10 @@ class install_cmd(cl_install,opt,share_cmd):
self.clVars.Set('cl_image','',True)
if options.d:
try:
# convert from ["/dev/sda1","/dev/sda5:/var/calculate]
# to [['/dev/sda1','',''],['/dev/sda5','/var/calculate','']]
# convert from ["/dev/sda1","/dev/sda5:/var]
# to [['/dev/sda1','','',''],['/dev/sda5','/var','','']]
self.setInstallDisk(
map(lambda x:x+['']*(3-len(x)),
map(lambda x:x+['']*(4-len(x)),
map(lambda x:x.split(':'),
options.d)))
except InstallError,e:

@ -48,14 +48,17 @@ class Data:
os_disk_dev = {}
# list mounted points for installed system
os_disk_install = {}
os_install_disk_mount = {}
# list mounted points for current operation system
os_disk_load = {}
os_disk_mount = {}
# list filesystem for partition devices
os_disk_format = {}
# need format
os_disk_perform_format = {}
# list uudi for partition devices
os_disk_uuid = {}
@ -136,3 +139,22 @@ class Data:
# installation os system: server or desktop
os_install_linux_system = {}
# root device of installed os
os_install_root_dev = {}
#
os_bind_hash = {'official':True}
# directories for bind
os_bind_dir = {}
# mountpoint for directories bind
os_bind_mountpoint = {}
os_install_bind_hash = {'official':True}
# install directories for bind
os_install_bind_dir = {}
# mountpoint for install directories bind
os_install_bind_mountpoint = {}

Loading…
Cancel
Save