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.
247 lines
9.2 KiB
247 lines
9.2 KiB
#-*- coding: utf-8 -*-
|
|
|
|
# Copyright 2010-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 soaplib, sys, time, os
|
|
import threading
|
|
|
|
from soaplib.serializers.primitive import String, Integer, Any, Boolean
|
|
from soaplib.serializers.clazz import Array, ClassSerializer
|
|
from soaplib.service import rpc, DefinitionBase
|
|
from calculate.api.server.api_types import ReturnedMessage
|
|
from calculate.api.server.api_types import ChoiceValue, Table, Option, Field, \
|
|
GroupField, ViewInfo
|
|
from calculate.lib.datavars import VariableError
|
|
|
|
#from cl_install import Install,DataVarsInstall
|
|
import cl_install
|
|
from calculate.lib.cl_lang import setLocalTranslate
|
|
from calculate.api.server.decorators import Dec
|
|
setLocalTranslate('cl_install3',sys.modules[__name__])
|
|
import traceback
|
|
from functools import wraps,WRAPPER_ASSIGNMENTS
|
|
|
|
class InstallInfo(ClassSerializer):
|
|
"""Parameters for method install"""
|
|
cl_image_filename = String
|
|
cl_image_linux_shortname = String
|
|
cl_image_arch_machine = String
|
|
cl_image_linux_ver = String
|
|
cl_image_linux_build = 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
|
|
cl_uuid_set = Boolean
|
|
os_install_kernel_scheduler = String
|
|
|
|
os_install_locale_lang = String
|
|
os_install_clock_timezone = String
|
|
|
|
cl_migrate_data = Array(Array(String))
|
|
cl_autologin = String
|
|
os_install_net_fqdn = String
|
|
os_install_net_data = Array(Array(String))
|
|
os_install_net_route_data = Array(Array(String))
|
|
os_install_net_conf = String
|
|
os_install_ntp = String
|
|
os_install_x11_video_drv = String
|
|
os_install_x11_resolution = String
|
|
os_install_x11_composite = Boolean
|
|
os_install_fb_resolution = String
|
|
|
|
cl_autopartition_device = Array(String)
|
|
cl_autopartition_scheme = Array(String)
|
|
cl_autopartition_set = String
|
|
cl_autopartition_table = String
|
|
cl_autopartition_root_size = String
|
|
|
|
Default = Array(String)
|
|
CheckOnly = Boolean
|
|
|
|
class catchExcept:
|
|
def __init__(self,f):
|
|
self.f = f
|
|
self.func_name = f.func_name
|
|
self.func_code = f.func_code
|
|
self.__doc__ = f.__doc__
|
|
self.__name__ = f.__name__
|
|
|
|
def __call__(self,*args,**kwargs):
|
|
try:
|
|
return self.f(*args,**kwargs)
|
|
except BaseException as e:
|
|
view = ViewInfo(groups=[])
|
|
group = GroupField(name=_("Error"),last=True)
|
|
group.fields = []
|
|
group.fields.append(Field(
|
|
name = "error",
|
|
label = str(e),
|
|
default = 'color:red;',
|
|
element = "error"))
|
|
view.groups.append(group)
|
|
for i in apply(traceback.format_exception, sys.exc_info()):
|
|
print i
|
|
return view
|
|
|
|
class Wsdl:
|
|
from calculate.api.server.baseClass import Basic
|
|
from calculate.api.server.decorators import Dec
|
|
|
|
def installCommon(self,sid,info,methodname,initfunc):
|
|
"""
|
|
Install common method
|
|
"""
|
|
try:
|
|
dv = self.get_cache(sid,methodname,"vars")
|
|
if not dv:
|
|
dv = initfunc()
|
|
else:
|
|
if methodname == "install":
|
|
self.fixInstallLocalization(sid,dv)
|
|
dv.processRefresh()
|
|
errors = map(lambda x:ReturnedMessage(**x),
|
|
dv.checkGroups(info,allvars=not info.CheckOnly))
|
|
print "Networking",dv.Get('os_install_net_route')
|
|
print "Networking2",dv.Get('os_install_net_nmroute')
|
|
if errors:
|
|
return errors
|
|
if info.CheckOnly:
|
|
returnmess = ReturnedMessage(type = '', message = None)
|
|
return [returnmess]
|
|
install_meth = type("CommonInstall",(self.Common,
|
|
cl_install.Install, object), {})
|
|
pid = self.startprocess(sid, target=install_meth,
|
|
method="installSystem",\
|
|
args_proc = (dv,))
|
|
returnmess = ReturnedMessage(type = 'pid', message = pid)
|
|
returnmess.type = "pid"
|
|
returnmess.message = pid
|
|
dv = self.clear_cache(sid,methodname)
|
|
return [returnmess]
|
|
finally:
|
|
if dv:
|
|
self.set_cache(sid,methodname,"vars",dv,smart=False)
|
|
return []
|
|
|
|
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
|
|
@Dec.check_permissions(["install"])
|
|
@Dec.console('cl-install')
|
|
@Dec.gui(_('System'),_('Installing'),'drive-harddisk')
|
|
def install ( self, sid, info):
|
|
return self.installCommon(sid,info,'install',self.install_vars)
|
|
|
|
def install_vars(self,dv=None):
|
|
if not dv:
|
|
dv = cl_install.DataVarsInstall()
|
|
dv.importInstall()
|
|
dv.flIniFile()
|
|
dv.Set('cl_action','system',True)
|
|
dv.addGroup(_("Choice of locale"),
|
|
normal=('os_install_locale_lang','os_install_clock_timezone'))
|
|
dv.addGroup(_("Choice of distro"),
|
|
normal=('cl_image_filename',),
|
|
expert=('cl_image_linux_shortname', 'cl_image_arch_machine',
|
|
'cl_image_linux_ver', 'cl_image_linux_build'))
|
|
dv.addGroup(_("Allocating drive space"),
|
|
normal=('cl_autopartition_set',),
|
|
expert=('cl_autopartition_scheme','cl_autopartition_device',
|
|
'cl_autopartition_table','cl_autopartition_root_size'),
|
|
expert_label=_("Click for autopartition settings"))
|
|
dv.addGroup(_("Choice of mount points"),
|
|
normal=('os_location_data',),
|
|
expert=('os_install_scratch','cl_uuid_set',
|
|
'os_install_root_type','os_install_mbr',
|
|
'os_install_kernel_scheduler'))
|
|
dv.addGroup(_("Network settings"),
|
|
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
|
|
|
|
def fixInstallLocalization(self,sid,dv):
|
|
"""
|
|
Fix localization on change lang in install method
|
|
"""
|
|
curThread = threading.currentThread()
|
|
curThread.lang = dv.Get('os_install_locale_lang')
|
|
currentLang = self.get_cache(sid,"install","lang")
|
|
if currentLang != curThread.lang:
|
|
dv.clearGroups()
|
|
self.install_vars(dv)
|
|
dv.reinit()
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
@rpc(Integer, Integer, Boolean,_returns = ViewInfo)
|
|
@catchExcept
|
|
def install_view (self, sid, step,expert):
|
|
dv = self.get_cache(sid,"install","vars")
|
|
if not dv:
|
|
dv = self.install_vars()
|
|
langChanged = False
|
|
else:
|
|
langChanged = self.fixInstallLocalization(sid,dv)
|
|
lang = dv.Get('os_install_locale_lang')
|
|
self.set_cache(sid,"install","lang",lang,smart=False)
|
|
dv.processRefresh()
|
|
view = ViewInfo(dv,step,expert,allsteps=langChanged)
|
|
self.set_cache(sid, 'install', "vars",dv,smart=False)
|
|
return view
|
|
|
|
def install_flash_vars(self):
|
|
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))
|
|
@Dec.check_permissions(["install"])
|
|
@Dec.gui(_('System'),_('Flash install'),
|
|
'drive-removable-media-usb-pendrive,media-removable')
|
|
def install_flash ( self, sid, info):
|
|
"""
|
|
Install to flash
|
|
"""
|
|
return self.installCommon(sid,info,'install_flash',
|
|
self.install_flash_vars)
|
|
|
|
@rpc(Integer, Integer, Boolean,_returns = ViewInfo)
|
|
@catchExcept
|
|
def install_flash_view (self, sid, step,expert):
|
|
dv = self.get_cache(sid,"install_flash","vars")
|
|
if not dv:
|
|
dv = self.install_flash_vars()
|
|
else:
|
|
dv.processRefresh()
|
|
view = ViewInfo(dv,step,expert)
|
|
self.set_cache(sid, 'install_flash', "vars",dv,smart=False)
|
|
return view
|