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.
193 lines
7.5 KiB
193 lines
7.5 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__])
|
|
|
|
class InstallInfo(ClassSerializer):
|
|
"""Parameters for method install"""
|
|
os_location_data = Array(Array(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))
|
|
#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_fb_resolution = String
|
|
os_install_clock_timezone = String
|
|
#default = Array(String)
|
|
CheckOnly = Boolean
|
|
|
|
class Wsdl:
|
|
def check_params (self, dv, info,allvars=False,ordered=None):
|
|
errors = []
|
|
keys = filter(lambda x:x.lower() == x,
|
|
info._type_info.keys())
|
|
if ordered:
|
|
keys = ordered + filter(lambda x:not x in ordered,
|
|
keys)
|
|
print info.os_location_data
|
|
print info.os_install_net_data
|
|
for var in keys:
|
|
val = info.__getattribute__(var)
|
|
if val != None or allvars:
|
|
try:
|
|
if val == None:
|
|
val = dv.Get(var)
|
|
#TODO: uncomment uncompatible check
|
|
#else:
|
|
# uncomperr = dv.Uncompatible(var)
|
|
# if uncomperr:
|
|
# raise VariableError(uncomperr)
|
|
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
|
|
|
|
@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):
|
|
try:
|
|
name_meth = 'install'
|
|
dv = self.get_cache(sid,"install","vars")
|
|
print "Install,sid,dv",sid,dv
|
|
if not dv:
|
|
reload(cl_install)
|
|
dv = cl_install.DataVarsInstall()
|
|
dv.importInstall()
|
|
dv.flIniFile()
|
|
dv.Set('cl_action','system',True)
|
|
errors = self.check_params(dv, info,
|
|
ordered=['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,"install")
|
|
return [returnmess]
|
|
finally:
|
|
if dv:
|
|
self.set_cache(sid,"install","vars",dv,smart=False)
|
|
return []
|
|
|
|
@rpc(Integer, Integer, Boolean,_returns = ViewInfo)
|
|
def install_view (self, sid, step,expert):
|
|
try:
|
|
dv = self.get_cache(sid,"install","vars")
|
|
print "Install,sid,dv",sid,dv
|
|
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_linux_shortname','cl_image_arch_machine'),
|
|
('cl_image_linux_ver','cl_image_linux_build',
|
|
'cl_image_filename'),
|
|
_("Next")), \
|
|
(_("Partitioning"), \
|
|
('os_location_data','os_install_scratch','cl_uuid_set'),
|
|
('os_install_root_type','os_install_mbr',),
|
|
_("Next")), \
|
|
(_("Locale"), \
|
|
('os_install_locale_lang','os_install_clock_timezone'),(), \
|
|
_("Next")),
|
|
(_("Networking"), \
|
|
('os_install_net_data','os_install_net_fqdn',
|
|
'os_install_ntp'),(), \
|
|
_("Next")),
|
|
(_("Users"), \
|
|
('cl_migrate_data','cl_autologin'),(), \
|
|
_("Next")),
|
|
(_("Video"), \
|
|
('os_install_x11_video_drv','os_install_x11_resolution',
|
|
'os_install_fb_resolution'),(), \
|
|
_("Done")),
|
|
],step,expert)
|
|
self.set_cache(sid, 'install', "vars",dv,smart=False)
|
|
return view
|
|
except BaseException,e:
|
|
view = ViewInfo(groups=[])
|
|
group = GroupField(name=_("Error"),last=True)
|
|
group.fields = []
|
|
group.fields.append(Field(
|
|
name = "error_label",
|
|
label = str(e),
|
|
default = 'color:red;',
|
|
element = "label"))
|
|
view.groups.append(group)
|
|
raise
|
|
return view
|
|
|