|
|
|
Envars
Action : was.envars (Category : was, Name : envars, By : kikonf)
Complete Name : was.envars.by.kikonf Version : 5.0 License : Modified BSD License Purpose of the was category : Easy to customize. This category use in background the wsadmin command in jython mode (through AdminConfig, AdminControl and AdminTask), to drive WebSphere Application Server ® configuration. You can use it to manage the whole WebSphere ® architecture. Purpose of this envars plugin : Creates one or more JVM environment(s) variable(s) into the target Server The following shows the main Source Code File for the Action : was.envars Toggle lines ## Copyright (c) 2008, Patrick Germain Placidoux ## All rights reserved. ## ## This file is part of Kikonf Public Software. ## ## Kikonf Public Software is released under the modified BSD License, ## which should accompany it or any part of it in the file "COPYING". ## If you do not have this file you can access the license ## through the WWW at http://www.kikonf.org/license/bsd/license.txt. ## ## Home: http://www.kikonf.org ## Contact: kikonf@gmx.com from actions.was.tools import * class Envars(wasAction): def extract(self, scope_attrs=None, prefix=None, **keywords): self_funct='extract' self.verbose(scope_attrs, prefix=prefix) scope_id, scope_attrs, scope=self.getScope(scope_attrs=scope_attrs, indent=self.getIndent()) envars_node=self.newTop() #-- because in extract mode, each call returns a new blank top node. indent=self.getIndent() + 3*' ' envars_node.setAttrs(prefix=prefix) mkNodeScope(envars_node, scope_attrs, isUnique=True) #-- creates a scope node. verbose('JavaProcessDef listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) pjd=AdminConfig.list('JavaProcessDef', scope_id) verbose('JavaProcessDef listed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) vs=getStartByNameAsDict(split(AdminConfig.showAttribute(pjd, 'environment'))) if len(vs)==0:return for vname in vs.keys(): if vname=='':continue if prefix!=None and vname.startswith(prefix) \ or prefix==None: verbose('Environnment Variable:' + vname + ' listed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) attrs={} vars=getShowAsDict(AdminConfig.show(vs[vname])) _name=vname if prefix!=None:_name=vname.split(prefix + '_')[1] if vars.has_key('description') and vars['description']!=None:desc=vars['description'][1:-1] else:desc=None if desc==DESIGN_NOTICE:desc=None envars_node.newNode('var', name=_name, value=vars['value'], required=vars['required'], desc=desc) def remove(self, no_name, no_name_no_prefix): envars_node = self.getTop() envars_attrs = envars_node.getAttrs() scope_id, scope_attrs, scope=self.getScope(parent_node=envars_node, indent=self.getIndent()) #-- Retreives scope self.verbose(scope_attrs, prefix=envars_attrs.prefix) indent=self.getIndent() + 3*' ' # no_name/no_name_no_prefix prefix=envars_attrs.prefix if no_name_no_prefix:prefix=None if no_name_no_prefix or prefix!=None:self.rmvVar(prefix=prefix, indent=indent) else: if envars_node.hasNode('var'): var_nodes=envars_node.getNode('var') for var_node in var_nodes: var_attrs = var_node.getAttrs() self.rmvVar(name=var_attrs.name, indent=indent) def inject(self): self_funct='inject' envars_node = self.getTop() envars_attrs = envars_node.getAttrs() scope_id, scope_attrs, scope=self.getScope(parent_node=envars_node, indent=self.getIndent()) #-- Retreives scope self.verbose(scope_attrs, prefix=envars_attrs.prefix) indent=self.getIndent() + 3*' ' if envars_attrs.prefix!=None:self.rmvVar(prefix=envars_attrs.prefix, indent=indent) if envars_node.hasNode('var'): pjd=AdminConfig.list('JavaProcessDef', scope_id) var_nodes=envars_node.getNode('var') cmdvalues=[] for var_node in var_nodes: var_attrs = var_node.getAttrs() #-- name if envars_attrs.prefix==None:name=var_attrs.name else:name=envars_attrs.prefix + '_' + var_attrs.name indent=self.getIndent() + 3*' ' if envars_attrs.prefix==None:self.rmvVar(name=var_attrs.name, indent=indent) vars=[] vars.append(['name', name]) vars.append(['value', var_attrs.value]) vars.append(['required', var_attrs.required]) if var_attrs.desc!=None:vars.append(['description', var_attrs.desc]) else:vars.append(['description', DESIGN_NOTICE]) cmdvalues.append(vars) verbose('JavaProcessDef listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) verbose('Environnment Variables modifying.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) AdminConfig.modify(pjd, 'environment', cmdvalues) verbose('Environnment Variables modified.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) def rmvVar(self, name=None, prefix=None, indent=None): scope_id, scope_attrs, scope=self.getScope() verbose('JavaProcessDef listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) pjd=AdminConfig.list('JavaProcessDef', scope_id) vs=getStartByNameAsDict(split(AdminConfig.showAttribute(pjd, 'environment'))) for vname in vs.keys(): if prefix!=None and vname.startswith(prefix) \ or prefix==None and name!=None and name==vname \ or prefix==None and name==None: verbose('Environnment Variable:' + vname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) AdminConfig.remove(vs[vname]) verbose('Environnment Variable:' + vname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) def verbose(self, scope_attrs, prefix=None): scope=str(scope_attrs).replace("'", '')[1:-1] if prefix!=None:verbose('Environment Variables under prefix:' + prefix + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent()) else:verbose('Environment Variables at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
Trademarks :
|