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

161 lines
6.1 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.cl_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
#user = Array(String)
#autologin = String
#password = Array(String)
os_install_net_fqdn = 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)
for var in keys:
val = info.__getattribute__(var)
if val != None or allvars:
try:
if val == None:
val = dv.Get(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
@rpc(Integer, InstallInfo, _returns = Array(ReturnedMessage))
@Dec.check_permissions(["install"])
@Dec.console('cl-install')
@Dec.gui('System.Install')
def install ( self, sid, info):
try:
name_meth = 'install'
dv = self.get_cache(sid,"install","vars")
if not dv:
dv = DataVarsInstall()
dv.importInstall()
dv.Set('cl_action','system',True)
dv.Set('cl_image_arch_machine','i686',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, Install, object), {})
#name = sh.name
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:
self.set_cache(sid,"install","vars",dv)
return []
@rpc(Integer, Integer, Boolean,_returns = ViewInfo)
def install_view (self, sid, step,expert):
dv = self.get_cache(sid,"install","vars")
if not dv:
dv = DataVarsInstall()
dv.importInstall()
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_fqdn','os_install_ntp'),(), \
_("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)
return view