|
|
|
Crtserver
Action : was.crtserver (Category : was, Name : crtserver, By : kikonf)
Complete Name : was.crtserver.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 crtserver plugin : Creates a new Server The following shows the main Source Code File for the Action : was.crtserver 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 Crtserver(wasAction): def extract(self, scope_attrs=None, **keywords): self_funct='extract' dct={'server': None, 'node': None, 'cluster': None} dct.update(scope_attrs) scope_attrs=dct server, node, cluster = scope_attrs['server'], scope_attrs['node'], scope_attrs['cluster'] self.verbose(scope_attrs) if server!=None and node!=None and cluster!=None:self.extAllKind({'server':server, 'node':node, 'cluster':cluster}, **keywords) elif cluster!=None and server==None and node==None: cl=AdminConfig.getid('/ServerCluster:' + cluster) if cl=='':raise xception.kikonfActionParameterException(self, self_funct, 'Scope: Unable to retreive cluster:' + cluster + '. Your scope:' + str({'server':server, 'node':node, 'cluster':cluster}) + '.') mbrs=split(AdminConfig.showAttribute(cl, 'members')) for mbr in mbrs: members=getShowAsDict( AdminConfig.show(mbr) ) server=members['memberName'] node=members['nodeName'] #id=members['uniqueId'] weight=members['weight'] self.extAllKind({'server':server, 'node':node, 'cluster':cluster}, weight=weight, **keywords) elif server!=None and cluster==None: if node!=None:node='/Node:' + node else:node='' srvs=split(AdminConfig.getid(node + '/Server:' + server)) if srvs=='':raise xception.kikonfActionParameterException(self, self_funct, 'Scope: Unable to retreive server:' + server + '. Your scope:' + str({'server':server, 'node':node, 'cluster':cluster}) + '.') for srv in srvs: node=srv.split('/nodes/')[1].split('/servers')[0] #--check if cluster: cluster=AdminConfig.showAttribute(srv,'clusterName') if cluster=='':cluster=None # make it self.extAllKind({'server':server, 'node':node, 'cluster':cluster}, **keywords) else:raise xception.kikonfActionParameterException(self, self_funct, 'Scope: Unvalide scope:' + '. Your scope:' + str({'server':server, 'node':node, 'cluster':cluster}) + '. At least server or cluster must be guiven !') def extAllKind(self, scope_attrs, weight=None, **keywords): if scope_attrs['node']==None or scope_attrs['server']==None:raise xception.kikonfActionParameterException(self, self_funct, 'Scope: Attributes "node" and "server" are required !') crtserver_node=self.newTop() indent=self.getIndent() + 3*' ' verbose('Server:' + scope_attrs['server'] + ' retreived.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) if scope_attrs['cluster']!=None: if weight!=None: cm, node, c=getClusterMember(cluster=scope_attrs['cluster'], node=scope_attrs['node'], member=scope_attrs['server'], asServer=False, asMember=True, doRaise=True) #id=AdminConfig.showAttribute(cm, 'uniqueId') weight=AdminConfig.showAttribute(cm, 'weight') crtserver_node.setAttrs(weight=weight) mkNodeScope(crtserver_node, scope_attrs, isUnique=True) def remove(self, no_name, no_name_no_prefix): crtserver_node = self.getTop() crtserver_attrs = crtserver_node.getAttrs() if not crtserver_node.hasNode('scope'):raise xception.kikonfActionSystemException(self, self_funct, 'Node scope is required !') scope_attrs=crtserver_node.getNode('scope')[0].getAttrs() self.verbose({'node': scope_attrs.node, 'server': scope_attrs.server, 'cluster': scope_attrs.cluster}) indent=self.getIndent() + 3*' ' self.rmvSrv(scope_attrs, indent=indent) def inject(self): self_funct='inject' crtserver_node = self.getTop() crtserver_attrs = crtserver_node.getAttrs() if not crtserver_node.hasNode('scope'):raise xception.kikonfActionSystemException(self, self_funct, 'Node scope is required !') scope_attrs=crtserver_node.getNode('scope')[0].getAttrs() if scope_attrs.node==None or scope_attrs.server==None:raise xception.kikonfActionSystemException(self, self_funct, 'Scope: server and node required. Your scope:' + str({'node':scope_attrs.node, 'server': scope_attrs.server})) self.verbose({'node': scope_attrs.node, 'server': scope_attrs.server, 'cluster': scope_attrs.cluster}) indent=self.getIndent() + 3*' ' #-- remove first self.rmvSrv(scope_attrs, indent=indent) if scope_attrs.cluster!=None: first=False verbose('ServerCluster retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) cl=AdminConfig.getid( '/Cell:' + self.getCell() + '/ServerCluster:' + scope_attrs.cluster) if cl=='':raise xception.kikonfActionSystemException(self, self_funct, 'Cluster:' + scope_attrs.cluster + ' not found !') node_group=AdminConfig.showAttribute(cl, 'nodeGroupName') if len(split(AdminConfig.showAttribute(cl, 'members')))==0:first=True cmdvalues=[] cmdvalues.append(['clusterName', scope_attrs.cluster]) mbrs=[] cmdvalues.append(['memberConfig', mbrs]) mbrs.append(['memberName', scope_attrs.server]) mbrs.append(['memberNode', scope_attrs.node]) mbrs.append(['memberWeight', crtserver_attrs.weight]) mbrs.append(['memberWeight', crtserver_attrs.weight]) if first: fms=[] cmdvalues.append(['firstMember', fms]) fms.append(['templateName', crtserver_attrs.template]) fms.append(['nodeGroup', node_group]) verbose('ClusterMember:' + scope_attrs.server + ' creating.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) cmdvalues=trsToAdminTask(cmdvalues) AdminTask.createClusterMember(cmdvalues) verbose('ClusterMember:' + scope_attrs.server + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) else: cmdvalues=[] cmdvalues.append(['name', scope_attrs.server]) cmdvalues.append(['templateName', crtserver_attrs.template]) verbose('ApplicationServer:' + scope_attrs.server + ' creating.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) cmdvalues=trsToAdminTask(cmdvalues) AdminTask.createApplicationServer(scope_attrs.node, cmdvalues) verbose('ApplicationServer:' + scope_attrs.server + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) def rmvSrv(self, scope_attrs, indent=None): if scope_attrs.cluster!=None: verbose('ClusterMember listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) srv, node, c=getClusterMember(cluster=scope_attrs.cluster, node=scope_attrs.node, member=scope_attrs.server) if srv=='':return verbose('ClusterMember removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) AdminConfig.remove(srv) verbose('ClusterMember:' + scope_attrs.server + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) else: verbose('ApplicationServer retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) sv=AdminConfig.getid('/Cell:' + self.getCell() + '/Node:' + scope_attrs.node + '/Server:' + scope_attrs.server + '/') if sv=='':return verbose('ApplicationServer removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) AdminConfig.remove(sv) verbose('ApplicationServer:' + scope_attrs.server + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) def verbose(self, scope_attrs): verbose('Application Server at scope: node:' + str(scope_attrs['node']) + ' server:' + str(scope_attrs['server']) + ' cluster:' + str(scope_attrs['cluster']) + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
Trademarks :
|