Update for new vars.

master3.3
Mike Hiretsky 12 years ago
parent 7ff04284a1
commit 84d378dda1

@ -34,40 +34,34 @@ import traceback
class InstallInfo(ClassSerializer): class InstallInfo(ClassSerializer):
"""Parameters for method install""" """Parameters for method install"""
os_location_data = Array(Array(String)) cl_image_filename = String
os_install_disk_single = String
os_install_mbr = Array(String)
os_install_root_type = String
cl_uuid_set = Boolean
cl_image_linux_shortname = String cl_image_linux_shortname = String
cl_image_arch_machine = String cl_image_arch_machine = String
cl_image_linux_ver = String cl_image_linux_ver = String
cl_image_linux_build = String cl_image_linux_build = String
cl_image_filename = String
os_install_disk_single = String
os_location_data = Array(Array(String))
os_install_mbr = Array(String)
os_install_root_type = String
os_install_scratch = Boolean os_install_scratch = Boolean
cl_uuid_set = Boolean
os_install_kernel_scheduler = String
os_install_locale_lang = String os_install_locale_lang = String
os_install_clock_timezone = String
cl_migrate_data = Array(Array(String)) cl_migrate_data = Array(Array(String))
cl_autologin = String cl_autologin = String
#user = Array(String)
#autologin = String
#password = Array(String)
os_install_net_fqdn = String os_install_net_fqdn = String
os_install_net_data = Array(Array(String)) os_install_net_data = Array(Array(String))
os_install_net_route_data = Array(Array(String)) os_install_net_route_data = Array(Array(String))
os_install_net_conf = String os_install_net_conf = String
#netconf = String
#dhcp = Array(String)
#ip = Array(String)
#route = Array(Array(String))
#dns = Array(String)
#proxy = String
os_install_ntp = String os_install_ntp = String
os_install_x11_video_drv = String os_install_x11_video_drv = String
os_install_x11_resolution = String os_install_x11_resolution = String
os_install_x11_composite = Boolean os_install_x11_composite = Boolean
os_install_fb_resolution = String os_install_fb_resolution = String
os_install_clock_timezone = String
os_install_kernel_scheduler = String
cl_autopartition_device = String cl_autopartition_device = String
cl_autopartition_scheme = String cl_autopartition_scheme = String
@ -106,37 +100,6 @@ def catchExcept():
return wrapper return wrapper
class Wsdl: class Wsdl:
def check_params (self, dv, info,allvars=False,ordered=None):
errors = []
keys = sorted(filter(lambda x:x.lower() == x,
info._type_info.keys()))
if ordered:
keys = ordered + filter(lambda x:not x in ordered,
keys)
for var in keys:
# get value of variable from info
val = info.__getattribute__(var)
# check value if value send of check allvariables
if val != None or allvars:
try:
# if value not send, then get from datavars
if val == None:
val = dv.Get(var)
else:
uncomperr = dv.Uncompatible(var)
if uncomperr:
raise VariableError(uncomperr)
if not dv.Uncompatible(var):
dv.Set(var, val)
except VariableError, e:
mess = ''
messages = e.message if type(e.message) == list else [e.message]
for error in messages:
mess += str(error) + '\n'
errors.append(ReturnedMessage(type = 'error', field = var,
message = mess))
return errors
from calculate.api.server.baseClass import Basic from calculate.api.server.baseClass import Basic
from calculate.api.server.decorators import Dec from calculate.api.server.decorators import Dec
@ -147,20 +110,11 @@ class Wsdl:
try: try:
dv = self.get_cache(sid,methodname,"vars") dv = self.get_cache(sid,methodname,"vars")
if not dv: if not dv:
reload(cl_install) dv = initfunc()
dv = cl_install.DataVarsInstall() else:
dv.importInstall() dv.processRefresh()
dv.flIniFile() errors = map(lambda x:ReturnedMessage(**x),
initfunc(dv) dv.checkGroups(info,allvars=not info.CheckOnly))
errors = self.check_params(dv, info,
ordered=['cl_autopartition_scheme',
'cl_autopartition_device',
'cl_autopartition_root_size',
'cl_image_linux_shortname',
'cl_image_arch_machine',
'cl_image_linux_ver',
'cl_image_linux_build'],
allvars=not info.CheckOnly)
if errors: if errors:
return errors return errors
if info.CheckOnly: if info.CheckOnly:
@ -186,9 +140,38 @@ class Wsdl:
@Dec.console('cl-install') @Dec.console('cl-install')
@Dec.gui(_('System'),_('Install'),'drive-harddisk') @Dec.gui(_('System'),_('Install'),'drive-harddisk')
def install ( self, sid, info): def install ( self, sid, info):
def init_func(dv): return self.installCommon(sid,info,'install',self.install_vars)
dv.Set('cl_action','system',True)
return self.installCommon(sid,info,'install',init_func) def install_vars(self):
reload(cl_install)
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
dv.Set('cl_action','system',True)
dv.addGroup(_("Distribute"),
normal=('cl_image_filename',),
expert=('cl_image_linux_shortname', 'cl_image_arch_machine',
'cl_image_linux_ver', 'cl_image_linux_build'))
dv.addGroup(_("Autopartition"),
normal=('cl_autopartition_scheme','cl_autopartition_device'),
expert=('cl_autopartition_table','cl_autopartition_root_size'))
dv.addGroup(_("Partitioning"),
normal=('os_location_data','os_install_scratch','cl_uuid_set'),
expert=('os_install_root_type','os_install_mbr',
'os_install_kernel_scheduler'))
dv.addGroup(_("Locale"),
normal=('os_install_locale_lang','os_install_clock_timezone'))
dv.addGroup(_("Networking"),
normal=('os_install_net_conf','os_install_net_data',
'os_install_net_fqdn','os_install_ntp'),
expert=('os_install_net_route_data',))
dv.addGroup(_("Users"),
normal=('cl_migrate_data','cl_autologin'))
dv.addGroup(_("Video"),
normal=('os_install_x11_video_drv','os_install_x11_composite',
'os_install_x11_resolution','os_install_fb_resolution'),
next_label=_("Install"))
return dv
@rpc(Integer, Integer, Boolean,_returns = ViewInfo) @rpc(Integer, Integer, Boolean,_returns = ViewInfo)
@catchExcept() @catchExcept()
@ -196,45 +179,26 @@ class Wsdl:
curThread = threading.currentThread() curThread = threading.currentThread()
dv = self.get_cache(sid,"install","vars") dv = self.get_cache(sid,"install","vars")
if not dv: if not dv:
reload(cl_install) dv = self.install_vars()
dv = cl_install.DataVarsInstall() else:
dv.importInstall() dv.processRefresh()
dv.flIniFile() view = getViewForVariables (dv,step,expert)
dv.Set('cl_action','system',True)
view = getViewForVariables (dv, [
(_("Distribute"), \
('cl_image_filename',),
('cl_image_linux_shortname','cl_image_arch_machine',
'cl_image_linux_ver','cl_image_linux_build'),
_("Next")), \
(_("Autopartition"), \
('cl_autopartition_device',
'cl_autopartition_scheme'),
('cl_autopartition_table','cl_autopartition_root_size'),
_("Next")), \
(_("Partitioning"), \
('os_location_data','os_install_scratch','cl_uuid_set'),
('os_install_root_type','os_install_mbr',
'os_install_kernel_scheduler'),
_("Next")), \
(_("Locale"), \
('os_install_locale_lang','os_install_clock_timezone'),(), \
_("Next")),
(_("Networking"), \
('os_install_net_conf','os_install_net_data','os_install_net_fqdn',
'os_install_ntp'),('os_install_net_route_data',), \
_("Next")),
(_("Users"), \
('cl_migrate_data','cl_autologin'),(), \
_("Next")),
(_("Video"), \
('os_install_x11_video_drv', 'os_install_x11_composite',
'os_install_x11_resolution', 'os_install_fb_resolution'),(), \
_("Install")),
],step,expert)
self.set_cache(sid, 'install', "vars",dv,smart=False) self.set_cache(sid, 'install', "vars",dv,smart=False)
return view return view
def install_flash_vars(self):
reload(cl_install)
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
dv.Set('cl_action','system',True)
dv.Set('cl_install_type','flash')
dv.addGroup(_("Flash install"),
normal=('os_install_disk_single','cl_image_filename'),
expert=('os_location_data',),
next_label=_("Install"))
return dv
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage)) @rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@Dec.check_permissions(["install"]) @Dec.check_permissions(["install"])
@Dec.gui(_('System'),_('Flash install'), @Dec.gui(_('System'),_('Flash install'),
@ -243,27 +207,17 @@ class Wsdl:
""" """
Install to flash Install to flash
""" """
def init_func(dv): return self.installCommon(sid,info,'install_flash',
dv.Set('cl_action','system',True) self.install_flash_vars)
dv.Set('cl_install_type','flash')
return self.installCommon(sid,info,'install_flash',init_func)
@rpc(Integer, Integer, Boolean,_returns = ViewInfo) @rpc(Integer, Integer, Boolean,_returns = ViewInfo)
@catchExcept() @catchExcept()
def install_flash_view (self, sid, step,expert): def install_flash_view (self, sid, step,expert):
dv = self.get_cache(sid,"install_flash","vars") dv = self.get_cache(sid,"install_flash","vars")
if not dv: if not dv:
reload(cl_install) dv = self.install_flash_vars()
dv = cl_install.DataVarsInstall() else:
dv.importInstall() dv.processRefresh()
dv.flIniFile() view = getViewForVariables (dv,step,expert)
dv.Set('cl_action','system',True)
dv.Set('cl_install_type','flash')
view = getViewForVariables (dv, [
(_("Distribute"), \
('os_install_disk_single','cl_image_filename'),
('os_location_data',),
_("Install")), \
],step,expert)
self.set_cache(sid, 'install_flash', "vars",dv,smart=False) self.set_cache(sid, 'install_flash', "vars",dv,smart=False)
return view return view

@ -132,10 +132,13 @@ class VariableClAutopartitionDevice(Variable):
def init(self): def init(self):
self.help = _("set autopartition device") self.help = _("set autopartition device")
self.label = _("Install device") self.label = _("Autopartition device")
def choice(self): def choice(self):
return [""]+self.Get('os_device_dev') deviceParentMap = dict(self.ZipVars('os_device_dev','os_device_name'))
return map(lambda x:(x,"%s (%s)"%(x,
deviceParentMap.get(x,_("Unknown")))),
self.Get('os_device_dev'))+[("","")]
def check(self,value): def check(self,value):
if self.Get('cl_autopartition_scheme'): if self.Get('cl_autopartition_scheme'):
@ -144,11 +147,12 @@ class VariableClAutopartitionDevice(Variable):
" device")) " device"))
useDisks = self.Select('os_disk_parent', useDisks = self.Select('os_disk_parent',
where='os_disk_mount', where='os_disk_mount',
eq=value) ne='')
if value in useDisks: if value in useDisks:
raise VariableError( raise VariableError(
_("Device already is used by current system")) _("Device already is used by current system"))
class VariableClAutopartitionScheme(Variable,AutoPartition): class VariableClAutopartitionScheme(Variable,AutoPartition):
""" """
Autopartition scheme Autopartition scheme
@ -170,12 +174,11 @@ class VariableClAutopartitionRootSize(Variable):
""" """
Root partition size for autopartition Root partition size for autopartition
""" """
type = "int"
opt = ["--root-size"] opt = ["--root-size"]
metavalue = "SIZE" metavalue = "SIZE"
def init(self): def init(self):
self.label = _("Root partition size") self.label = _("Root partition size")+ " (MB)"
self.help = _("set root partition size for autopartition") self.help = _("set root partition size for autopartition")
def get(self): def get(self):
@ -198,8 +201,8 @@ class VariableClAutopartitionRootSize(Variable):
res = reSizeValue.search(value) res = reSizeValue.search(value)
intValue = int(res.group(1)) intValue = int(res.group(1))
if res.group(2): if res.group(2):
intValue = intValue / sizeMap[res.group(2)] intValue = intValue * sizeMap[res.group(2)]
return str(intValue) return str(int(intValue))
def check(self,value): def check(self,value):
if self.Get('cl_autopartition_device') and \ if self.Get('cl_autopartition_device') and \
@ -390,9 +393,9 @@ class VariableClAutopartitionFreeSize(ReadonlyVariable):
return 0 return 0
sizeDevice = self.Select('os_device_size', sizeDevice = self.Select('os_device_size',
where='os_device_dev', where='os_device_dev',
eq=device,limit=1) eq=device,limit=1) or '0'
sizes = self.Get('cl_autopartition_disk_size') sizes = self.Get('cl_autopartition_disk_size')
return reduce(lambda x,y: x - int(y) if y.isdigit() else x, return reduce(lambda x,y: (x - int(y)) if y.isdigit() else x,
sizes,int(sizeDevice)) sizes,int(sizeDevice))
class VariableClAutopartitionBindData(ReadonlyVariable): class VariableClAutopartitionBindData(ReadonlyVariable):
@ -410,7 +413,8 @@ class VariableClAutopartitionBindPath(ReadonlyVariable):
type = "list" type = "list"
def generatePath(self,scheme): def generatePath(self,scheme):
for line in scheme.split(';'): for line in filter(lambda x:x,
scheme.split(';')):
source,mp = line.split(':') source,mp = line.split(':')
if source.startswith('/'): if source.startswith('/'):
yield source yield source
@ -427,7 +431,8 @@ class VariableClAutopartitionBindMountpoint(ReadonlyVariable):
type = "list" type = "list"
def generateMountPoint(self,scheme): def generateMountPoint(self,scheme):
for line in scheme.split(';'): for line in filter(lambda x:x,
scheme.split(';')):
source,mp = line.split(':') source,mp = line.split(':')
if source.startswith('/'): if source.startswith('/'):
yield mp yield mp

@ -17,6 +17,8 @@
import os import os
import sys import sys
import re import re
import pty,fcntl
from subprocess import Popen
from os import path from os import path
from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable from calculate.lib.datavars import Variable,VariableError,ReadonlyVariable
from calculate.lib.utils.device import (getUdevDeviceInfo,getDeviceType, from calculate.lib.utils.device import (getUdevDeviceInfo,getDeviceType,
@ -74,6 +76,15 @@ class VariableOsDeviceDev(ReadonlyVariable,DeviceHelper):
""" """
type = "list" type = "list"
def init(self):
self.master,slave = pty.openpty()
self.monitor = Popen(["/sbin/udevadm","monitor","--kernel",
"--subsystem-match=block"],stdout=slave,
close_fds=True)
os.close(slave)
fl = fcntl.fcntl(self.master,fcntl.F_GETFL)
fcntl.fcntl(self.master, fcntl.F_SETFL, fl | os.O_NONBLOCK)
def get(self): def get(self):
"""Get device /dev name""" """Get device /dev name"""
def _getDiskName(devpath): def _getDiskName(devpath):
@ -91,6 +102,20 @@ class VariableOsDeviceDev(ReadonlyVariable,DeviceHelper):
self.getDeviceFromSysPath()))), self.getDeviceFromSysPath()))),
key=self.separateDevice) key=self.separateDevice)
def close(self):
self.monitor.kill()
self.monitor.wait()
def refresh(self):
try:
res = os.read(self.master,65535)
if res:
while len(res) == 65535:
res = os.read(self.master,65535)
self.parent.Invalidate(self.name)
except OSError as e:
pass
class VariableOsDeviceType(ReadonlyVariable): class VariableOsDeviceType(ReadonlyVariable):
""" """
Device type (hdd,cdrom,usb-flash) Device type (hdd,cdrom,usb-flash)

@ -533,18 +533,24 @@ class VariableOsInstallNetConf(NetVariable):
listDirectory('/etc/runlevels/boot')+ listDirectory('/etc/runlevels/boot')+
listDirectory('/etc/runlevels/default')) \ listDirectory('/etc/runlevels/default')) \
or self.Get('os_install_root_type') == "livecd": or self.Get('os_install_root_type') == "livecd":
if isPkgInstalled("net-misc/networkmanager", nm = "networkmanager"
prefix=self.Get('cl_chroot_path')): if nm in map(lambda x:x[1],self.choice()):
return "networkmanager" return nm
return "openrc" else:
return "openrc"
def choice(self): def choice(self):
mapNetConf = (('networkmanager','net-misc/networkmanager',_("NetworkManager")), mapNetConf = (('networkmanager','net-misc/networkmanager',_("NetworkManager")),
('openrc','',_('OpenRC'))) ('openrc','',_('OpenRC')))
return map(lambda x:(x[0],x[2]), image = self.Get('cl_image')
filter(lambda x:not x[1] or isPkgInstalled(x[1], if image:
prefix=self.Get('cl_chroot_path')), with image as distr:
mapNetConf)) distrPath = image.getDirectory()
return map(lambda x:(x[0],x[2]),
filter(lambda x:not x[1] or isPkgInstalled(x[1],
prefix=distrPath),
mapNetConf))
return map(lambda x:x[0::2],mapNetConf[-1:])
class VariableOsInstallNetDnsSearch(NetVariable): class VariableOsInstallNetDnsSearch(NetVariable):
""" """

Loading…
Cancel
Save