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.
calculate-utils-3-install/install/cl_wsdl_install.py

272 lines
10 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, getViewForVariables
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_install',sys.modules[__name__])
import traceback
class InstallInfo(ClassSerializer):
"""Parameters for method install"""
os_location_data = Array(Array(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_arch_machine = String
cl_image_linux_ver = String
cl_image_linux_build = String
cl_image_filename = String
os_install_scratch = Boolean
os_install_locale_lang = String
cl_migrate_data = Array(Array(String))
cl_autologin = String
#user = Array(String)
#autologin = String
#password = Array(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
#netconf = String
#dhcp = Array(String)
#ip = Array(String)
#route = Array(Array(String))
#dns = Array(String)
#proxy = 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
os_install_clock_timezone = String
os_install_kernel_scheduler = String
cl_autopartition_device = String
cl_autopartition_scheme = String
cl_autopartition_table = String
cl_autopartition_root_size = String
#default = Array(String)
CheckOnly = Boolean
def catchExcept():
class wrapper:
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,selfobj,*args,**kwargs):
try:
return self.f(selfobj,*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)
print "!!!!EXCEPTION!!!!"
for i in apply(traceback.format_exception, sys.exc_info()):
print i
return view
return wrapper
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)
print "333333333333333:",info.cl_autopartition_scheme
print "222222222222222:",info.cl_autopartition_device
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.decorators import Dec
def installCommon(self,sid,info,methodname,initfunc):
"""
Install common method
"""
try:
dv = self.get_cache(sid,methodname,"vars")
if not dv:
reload(cl_install)
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
initfunc(dv)
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:
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'),_('Install'),'drive-harddisk')
def install ( self, sid, info):
def init_func(dv):
dv.Set('cl_action','system',True)
return self.installCommon(sid,info,'install',init_func)
@rpc(Integer, Integer, Boolean,_returns = ViewInfo)
@catchExcept()
def install_view (self, sid, step,expert):
curThread = threading.currentThread()
dv = self.get_cache(sid,"install","vars")
if not dv:
reload(cl_install)
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
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)
return view
@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
"""
def init_func(dv):
dv.Set('cl_action','system',True)
dv.Set('cl_install_type','flash')
return self.installCommon(sid,info,'install_flash',init_func)
@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:
reload(cl_install)
dv = cl_install.DataVarsInstall()
dv.importInstall()
dv.flIniFile()
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)
return view