|
|
|
Mqm
Action : wmq.mqm (Category : wmq, Name : mqm, By : kikonf)
Complete Name : wmq.mqm.by.kikonf Version : 5.0 License : Modified BSD License Purpose of the wmq category : Easy to customize. This category use in background the runmqsc command to create and configure : Qmanagers, Qlocals, Qremotes, Clusters, Channels, Triggers, Processes, XMITQs, Listeners or SSL for WebSphere MQ ®. You can use it to manage the whole IBM WebSphere MQ ® architecture. Purpose of this mqm plugin : Configures a QManager The following shows the main Source Code File for the Action : wmq.mqm Toggle lines ## Copyright (c) 2008, Patrick Germain Placidoux ## All rights reserved. ## ## This file is part of Kiko Public Software. ## ## Kiko 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.kickconf.com/license/bsd/license.txt. ## ## Home: http://www.kickconf.com ## Contact: kickconf@gmx.com from actions.wmq.tools import * class Mqm(wmqAction): def remove(self, no_name, no_name_no_prefix): self_funct='remove' mqm_node = self.getTop() mqm_attrs = mqm_node.getAttrs() from os import path self.verbose(mqm_attrs.name) indent=self.getIndent() + 3*' ' doPrint=False if self.getVerbose()>=5:doPrint=True ## Queue Manager (begin) ## st=None if mqm_attrs.force == 'true': if self.getVerbose()>=1:st='Queue Manager ' + mqm_attrs.name if self.getVerbose()>=2:st += ':' if st!=None:verbose(st, level=self.getVerbose(), level=self.getVerbose(), ifLevel=1, indent=indent, logFile=self.getLogFile()) # Stopping Listeners if mqm_node.hasNode('listeners'): verbose('Stopping Listeners', level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) cde = path.normpath(self.getBinPath() + '/' + 'endmqlsr') + self.getBinarySufix() + ' -w -m ' + mqm_attrs.name verbose(cde, level=self.getVerbose(), ifLevel=3, indent=indent + 6*' ', logFile=self.getLogFile()) ret, stdout, sdterr=subprocess(cde) if self.getVerbose()>=5: print stdout print sdterr # if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Echec triying to Kill the Listener !') # Stopping QManager verbose('Stopping Queue Manager: ' + mqm_attrs.name, level=self.getVerbose(), level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) cde = path.normpath(self.getBinPath() + '/' + 'endmqm') + self.getBinarySufix() + ' -w ' + mqm_attrs.name verbose(cde, level=self.getVerbose(), ifLevel=3, indent=indent + 6*' ', logFile=self.getLogFile()) ret, stdout, sdterr=subprocess(cde, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr # Deleting QManager verbose('Deleting Queue Manager: ' + mqm_attrs.name, level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) cde = path.normpath(self.getBinPath() + '/' + 'dltmqm') + self.getBinarySufix() + ' ' + mqm_attrs.name verbose(cde, level=self.getVerbose(), ifLevel=3, indent=indent + 6*' ', logFile=self.getLogFile()) ret, stdout, sdterr=subprocess(cde, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr if sdterr.find('is still running')>=0: verbose('Killing pending processes:', level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) pcs=sdterr.split('\n') for pc in pcs: if not pc.startswith('Process'):continue pid=pc.split(' ')[1] verbose('PID:' + str(pid), level=self.getVerbose(), ifLevel=3, indent=indent + 6*' ', logFile=self.getLogFile()) kill(pid) ret, stdout, sdterr=subprocess(cde, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr if mqm_node.hasNode('ssl'): ssl_node=mqm_node.getNode('ssl')[0] ssl_attrs=ssl_node.getAttrs() from os import path from os import remove dir=ssl_attrs.repos_dir for sufix in ('crl', 'kdb', 'rdb', 'sth', 'cert'): file=path.realpath(path.normpath(dir + '/' + mqm_attrs.name + '.' + sufix)) if path.isfile(file):remove(file) ## Queue Manager (end) ## def inject(self): self_funct='inject' # Get top nodes mqm_node = self.getTop() mqm_attrs = mqm_node.getAttrs() from os import path self.verbose(mqm_attrs.name) indent=self.getIndent() + 3*' ' doPrint=False if self.getVerbose()>=5:doPrint=True ## Queue Manager (begin) ## st=None if self.getVerbose()>=1:st='Queue Manager ' + mqm_attrs.name if self.getVerbose()>=2:st += ':' if st!=None:verbose(st, level=self.getVerbose(), ifLevel=1, indent=indent, logFile=self.getLogFile()) # Creating QManager verbose('Creating Queue Manager: ' + mqm_attrs.name, level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) cde = path.normpath(self.getBinPath() + '/' + 'crtmqm') + self.getBinarySufix() + ' ' + mqm_attrs.name verbose(cde, level=self.getVerbose(), ifLevel=3, indent=indent + 6*' ', logFile=self.getLogFile()) ret, stdout, sdterr=subprocess(cde, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Echec de Creation du QManager') # Starting QManager verbose('Starting Queue Manager: ' + mqm_attrs.name, level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) cde = path.normpath(self.getBinPath() + '/' + 'strmqm') + self.getBinarySufix() + ' ' + mqm_attrs.name verbose(cde, level=self.getVerbose(), ifLevel=3, indent=indent + 6*' ', logFile=self.getLogFile()) ret, stdout, sdterr=subprocess(cde, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr print ## Queue Manager (end) ## ## Listeners (begin) ## if mqm_node.hasNode('listeners'): listener_nodes=mqm_node.getNode('listeners')[0].getNodes() for listener_node in listener_nodes: listener_attrs = listener_node.getAttrs() host='' if self.getVerbose()>=2: if listener_attrs.host!=None:host=' host: ' + str(listener_attrs.host) if listener_attrs.dfn=='false': verbose('Running Listener on' + host + ' port: ' + str(listener_attrs.port), level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) cde = path.normpath(self.getBinPath() + '/' + 'runmqlsr') + self.getBinarySufix() + ' -t TCP -m ' + mqm_attrs.name + ' -i ' + str(listener_attrs.host) + ' -p ' + str(listener_attrs.port) verbose(cde, level=self.getVerbose(), ifLevel=3, indent=indent + 6*' ', logFile=self.getLogFile()) ret, stdout, sdterr=subprocess(cde, wait=False) if self.getVerbose()>=5: print stdout print sdterr if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Echec triying to Run the Listener !') else: verbose('Creating Listener on' + host + ' port: ' + str(listener_attrs.port), level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) # Temporary command file fileIn=path.normpath(self.getCurrentDir() + '/templates/' + 'mqm_listener.tmpl') template=Template(fileIn) template.replace('name', listener_attrs.name) if listener_attrs.host!=None:template.replace('host', listener_attrs.host) else:template.replace('host', '') template.replace('port', listener_attrs.port) if listener_attrs.desc!=None:template.replace('desc', listener_attrs.desc) else:template.replace('desc', '') stdin=template.process() cde = '\"' + path.normpath(self.getBinPath() + '/' + 'runmqsc') + self.getBinarySufix() + '\" ' + mqm_attrs.name ret, stdout, sdterr=subprocess(cde, stdin=stdin, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Echec Creating the Listener !') ## Listeners (end) ## ## Clusters (begin) ## cls_clusters=[] cls_full_repos=[] cls_full=None cls_global=None if mqm_node.hasNode('clusters'): cls_clusters=[] cls_full_repos=[] cluster='' cluster_nodes=mqm_node.getNode('clusters')[0].getNodes() for cluster_node in cluster_nodes: cluster_attrs = cluster_node.getAttrs() cls_clusters.append(cluster_attrs.name) if cluster_attrs.full_repos=='true':cls_full_repos.append(cluster_attrs.name) cls_clusters.sort() cls_full_repos.sort() #-- Create a global Namelist for full repos if len(cls_full_repos)>1: name='_'.join(cls_full_repos) names=str(cls_full_repos).replace("'", '')[1:-1] verbose('Creating a global Namelist for artefact $ (for all full repos) named : ' + name, level=self.getVerbose(), ifLevel=3, indent=indent + 3*' ', logFile=self.getLogFile()) # Temporary command file fileIn=path.normpath(self.getCurrentDir() + '/templates/' + 'mqm_namelist.tmpl') template=Template(fileIn) template.replace('name', name) template.replace('names', names) stdin=template.process() cde = '\"' + path.normpath(self.getBinPath() + '/' + 'runmqsc') + self.getBinarySufix() + '\" ' + mqm_attrs.name ret, stdout, sdterr=subprocess(cde, stdin=stdin, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Echec Creating the Namelist !') #-- Alter QManager with full repos infos if len(cls_full_repos)>0: repos='' reposnl='' if len(cls_full_repos)>1:cls_full=reposnl='_'.join(cls_full_repos) else:cls_full=repos=cls_full_repos[0] verbose('Altering QManager with full repos infos: ' + name, level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) # Temporary command file fileIn=path.normpath(self.getCurrentDir() + '/templates/' + 'mqm_qmanager.tmpl') template=Template(fileIn) template.replace('repos', repos) template.replace('reposnl', reposnl) stdin=template.process() cde = '\"' + path.normpath(self.getBinPath() + '/' + 'runmqsc') + self.getBinarySufix() + '\" ' + mqm_attrs.name ret, stdout, sdterr=subprocess(cde, stdin=stdin, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Echec altering QManager with full repos infos !') #-- Create a global Namelist for artefact * if len(cls_clusters)>1: cls_global=name='CLUSTERS' names=str(cls_clusters).replace("'", '')[1:-1] verbose('Creating a global Namelist for artefact * (for all repos) named : ' + 'CLUSTERS', level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) # Temporary command file fileIn=path.normpath(self.getCurrentDir() + '/templates/' + 'mqm_namelist.tmpl') template=Template(fileIn) template.replace('name', name) template.replace('names', names) stdin=template.process() cde = '\"' + path.normpath(self.getBinPath() + '/' + 'runmqsc') + self.getBinarySufix() + '\" ' + mqm_attrs.name ret, stdout, sdterr=subprocess(cde, stdin=stdin, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Echec Creating the Namelist !') #-- Try to Retreive sender and receiver for cluster if cls_full!=None: verbose('Trying to Retreive Sender and Receiver for cluster: ' + cls_full, level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) #---- Sender: found=False tdc='mqm/channels/channel@type=CLUSSDR,@cluster=$' try: nodes=mqm_node.tdc(tdc, checkIsNode=True, checkIsUnique=True) channel_sdr = nodes[0].getAttrs() found=True except:pass tdc='mqm/channels/channel@type=CLUSSDR,@cluster=' + cls_full if not found: try: nodes=mqm_node.tdc(tdc, checkIsNode=True, checkIsUnique=True) channel_sdr = nodes[0].getAttrs() found=True except:pass if not found:raise xception.kikonfActionSystemException(self, self_funct, 'Failed Trying to Retreive a Sender Channel for cluster: ' + cls_full + '.' + \ ' Advice: add a tag of this shape into the <channels> stanza of your xml :\n' + \ "<channel name='YOURNAME' type='CLUSSDR' cluster='$' host='ONE_LISTENER_HOST' port='ONE_LISTENER_PORT'>\nor\n" + \ "<channel name='YOURNAME' type='CLUSSDR' cluster='" + cls_full + "' host='ONE_LISTENER_HOST' port='ONE_LISTENER_PORT'> !") #---- Receiver: found=False tdc='mqm/channels/channel@type=CLUSRCVR,@cluster=$' try: nodes=mqm_node.tdc(tdc, checkIsNode=True, checkIsUnique=True) channel_rcvr = nodes[0].getAttrs() if channel_rcvr.name!=channel_sdr.name:raise found=True except:pass tdc='mqm/channels/channel@type=CLUSRCVR,@cluster=' + cls_full if not found: try: nodes=mqm_node.tdc(tdc, checkIsNode=True, checkIsUnique=True) channel_rcvr = nodes[0].getAttrs() if channel_rcvr.name!=channel_sdr.name:raise found=True except:pass if not found:raise xception.kikonfActionSystemException(self, self_funct, 'Failed Trying to Retreive a Receiver Channel for cluster: ' + cls_full + '. Beware that the receiver channel must hold the same name as the Sender channel.' + \ ' Advice: add a tag of this shape into the <channels> stanza of your xml :\n' + \ "<channel name='" + channel_sdr.name + "' type='CLUSRCVR' cluster='$' host='ONE_LISTENER_HOST' port='ONE_LISTENER_PORT'>\nor\n" + \ "<channel name='" + channel_sdr.name + "' type='CLUSRCVR' cluster='" + cls_full + "' host='ONE_LISTENER_HOST' port='ONE_LISTENER_PORT'> !") verbose('', level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) if len(cls_clusters)>0: #-- Check Cluster Attribute for all Channels if mqm_node.hasNode('channels'): channel_nodes=mqm_node.getNode('channels')[0].getNodes() for node in channel_nodes: attrs = node.getAttrs() if attrs.cluster==None:continue self.checkClsAttributes(node, mqm_attrs, cls_global=cls_global, cls_full=cls_full, cls_full_repos=cls_full_repos, cls_clusters=cls_clusters, indent=indent) #-- Check Cluster Attribute for all Queues if mqm_node.hasNode('queues'): queues_node=mqm_node.getNode('queues')[0] if queues_node.hasNode('local'): local_nodes=queues_node.getNode('local') for node in local_nodes: attrs = node.getAttrs() if attrs.cluster==None:continue self.checkClsAttributes(node, mqm_attrs, cls_global=cls_global, cls_full=cls_full, cls_full_repos=cls_full_repos, cls_clusters=cls_clusters, indent=indent) if queues_node.hasNode('remote'): remote_nodes=queues_node.getNode('remote') attrs = node.getAttrs() for node in remote_nodes: attrs = node.getAttrs() if attrs.cluster==None:continue self.checkClsAttributes(node, mqm_attrs, cls_global=cls_global, cls_full=cls_full, cls_full_repos=cls_full_repos, cls_clusters=cls_clusters, indent=indent) if mqm_node.hasNode('queues'): queue_nodes=mqm_node.getNode('queues')[0].getNodes() for queue_node in queue_nodes: ## Queue Remotes (begin) ## if queue_node.getTag()=='remote': queue_remote_node=queue_node queue_remote_attrs = queue_remote_node.getAttrs() # Mq Server : Creation of the Queue Remote : verbose('Creating Remote Queue : ' + queue_remote_attrs.name, level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) # Temporary command file fileIn=path.normpath(self.getCurrentDir() + '/templates/' + 'mqm_queue_remote.tmpl') template=Template(fileIn) template.replace('name', queue_remote_attrs.name) template.replace('rqmname', queue_remote_attrs.rqmname) template.replace('rname', queue_remote_attrs.rname) if queue_remote_attrs.put!=None:template.replace('put', queue_remote_attrs.put) else:template.replace('put', '') if queue_remote_attrs.cluster!=None:template.replace('cluster', queue_remote_attrs.cluster) else:template.replace('cluster', '') if queue_remote_attrs.clusnl!=None:template.replace('clusnl', queue_remote_attrs.clusnl) else:template.replace('clusnl', '') if queue_remote_attrs.desc!=None:template.replace('desc', queue_remote_attrs.desc) else:template.replace('desc', '') #-- Channel Sdr name if queue_remote_attrs.channel_sdr!=None:sdr=queue_remote_attrs.channel_sdr else:sdr=queue_remote_attrs.name + '.ch001' #-- Channel Rcvr name if queue_remote_attrs.channel_rcvr!=None:rcvr=queue_remote_attrs.channel_rcvr else: l=queue_remote_attrs.name.split('.') l.reverse() rcvr='.'.join(l) #-- Xmitq name if queue_remote_attrs.xmitq!=None:xmitq=queue_remote_attrs.xmitq else:xmitq=queue_remote_attrs.name + '.xm001' template.replace('xmitq', xmitq) #-- Retreive xmitq in queue locals if exist found=False if queue_remote_attrs.xmitq!=None: tdc='mqm/queues/local@name=' + queue_remote_attrs.xmitq try: nodes=mqm_node.tdc(tdc, checkIsNode=True, checkIsUnique=True) found=True except:pass if found: self.mkQlocal(template, node=nodes[0], mqm_node=mqm_node) node._getParent()._remove(nodes[0]) else: attrs={ 'name':xmitq, 'usage':'XMITQ', 'trigger':'TRIGGER', 'trigdata':sdr, 'initq':'SYSTEM.CHANNEL.INITQ' } self.mkQlocal(template, attrs=attrs) #-- Retreive channel_sdr in channels if exist found=False if queue_remote_attrs.channel_sdr!=None: tdc='mqm/channels/channel@type=SDR,@name=' + queue_remote_attrs.channel_sdr try: nodes=mqm_node.tdc(tdc, checkIsNode=True, checkIsUnique=True) found=True except:pass if found: self.mkChannel(template, node=nodes[0]) node._getParent()._remove(nodes[0]) else: attrs={ 'name':sdr, 'type':'SDR', 'host':queue_remote_attrs.host, 'port': queue_remote_attrs.port, 'xmitq':xmitq } self.mkChannel(template, attrs=attrs, usePrefix='sdr_') #-- Retreive channel_rcvr in channels if exist found=False if queue_remote_attrs.channel_rcvr!=None: tdc='mqm/channels/channel@type=RCVR,@name=' + queue_remote_attrs.channel_rcvr try: nodes=mqm_node.tdc(tdc, checkIsNode=True, checkIsUnique=True) found=True except:pass if found: self.mkChannel(template, node=nodes[0]) node._getParent()._remove(nodes[0]) else: attrs={ 'name':rcvr + '.ch001', 'type':'RCVR', } self.mkChannel(template, attrs=attrs, usePrefix='rcvr_') stdin=template.process() cde = '\"' + path.normpath(self.getBinPath() + '/' + 'runmqsc') + self.getBinarySufix() + '\" ' + mqm_attrs.name ret, stdout, sdterr=subprocess(cde, stdin=stdin, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Failed Creating the Queue Remote !') print ## Queue Remotes (end) ## ## Queue Locals (begin) ## elif queue_node.getTag()=='local': queue_local_node=queue_node queue_local_attrs = queue_local_node.getAttrs() # Mq Server : Creation of the Queue Local : verbose('Creating Local Queue : ' + queue_local_attrs.name, level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) # Temporary command file fileIn=path.normpath(self.getCurrentDir() + '/templates/' + 'mqm_queue_local.tmpl') template=Template(fileIn) self.mkQlocal(template, node=queue_local_node, mqm_node=mqm_node) stdin=template.process() cde = '\"' + path.normpath(self.getBinPath() + '/' + 'runmqsc') + self.getBinarySufix() + '\" ' + mqm_attrs.name ret, stdout, sdterr=subprocess(cde, stdin=stdin, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Failed Creating the Queue Local !') ## Queue Locals (end) ## ## Channels (begin) ## if mqm_node.hasNode('channels'): channels_nodes=mqm_node.getNode('channels')[0].getNodes() for channel_node in channels_nodes: # Temporary command file fileIn=path.normpath(self.getCurrentDir() + '/templates/' + 'mqm_channel.tmpl') template=Template(fileIn) channel_attrs = channel_node.getAttrs() # Mq Server : Creation of the Queue Local : verbose('Creating Channel : ' + channel_attrs.name, level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) self.mkChannel(template, node=channel_node) stdin=template.process() cde = '\"' + path.normpath(self.getBinPath() + '/' + 'runmqsc') + self.getBinarySufix() + '\" ' + mqm_attrs.name ret, stdout, sdterr=subprocess(cde, stdin=stdin, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Failed Creating the Channel !') print ## Channels (end) ## ## Processes (begin) ## if mqm_node.hasNode('processes'): processes_nodes=mqm_node.getNode('processes')[0].getNodes() for process_node in processes_nodes: # Temporary command file fileIn=path.normpath(self.getCurrentDir() + '/templates/' + 'mqm_process.tmpl') template=Template(fileIn) process_attrs = process_node.getAttrs() # Mq Server : Creation of the Queue Local : verbose('Creating Process : ' + process_attrs.name, level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) self.mkProcess(template, node=process_node) stdin=template.process() cde = '\"' + path.normpath(self.getBinPath() + '/' + 'runmqsc') + self.getBinarySufix() + '\" ' + mqm_attrs.name ret, stdout, sdterr=subprocess(cde, stdin=stdin, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Failed Creating the Process !') print ## Processes (end) ## ## ssl (begin) ## ## ssl (begin) ## if mqm_node.hasNode('ssl'): ssl_node=mqm_node.getNode('ssl')[0] ssl_attrs=ssl_node.getAttrs() doc=dosc=False # - Clearing Variables # Cert infos cert_label=cert_format=cert_path=None # Self sign cert infos slabel=scert_path=scert_format=scert_dn=scert_size=scert_expire=scert_sigalg=None selfcert_attrs = None if ssl_node.hasNode('selfcert'): selfcert_attrs = ssl_node.getNode('selfcert')[0].getAttrs() cert_attrs = None if ssl_node.hasNode('cert'): cert_attrs = ssl_node.getNode('cert')[0].getAttrs() # - Feeding Variables # Global and cert keystore infos dir=path.realpath(path.normpath(ssl_attrs.repos_dir)) name=mqm_attrs.name password=ssl_attrs.password expire=ssl_attrs.expire # - Cert infos if cert_attrs != None: doc=True cert_label=cert_attrs.label cert_format=cert_attrs.format cert_path=path.realpath(path.normpath(dir + '/' + cert_attrs.file)) # - Self sign cert infos if selfcert_attrs != None: dosc=True slabel=mqm_attrs.name scert_path=path.realpath(path.normpath(dir + '/' + mqm_attrs.name + '.cert')) scert_format=selfcert_attrs.format scert_dn=selfcert_attrs.dn scert_size=selfcert_attrs.cert_size scert_expire=selfcert_attrs.cert_expire scert_sigalg=selfcert_attrs.cert_sigalg # - Checks # if not path.isdir(dir):raise xception.kikonfActionSystemException(self, self_funct, 'The keystore directory: ' + dir + ' should exist !') # - Call self.mkSslKeys(dir, name, expire=expire, password=password, doc=doc, cert_label=cert_label, cert_format=cert_format, cert_path=cert_path, dosc=dosc, slabel=slabel, scert_path=scert_path, scert_format=scert_format, scert_dn=scert_dn, scert_size=scert_size, scert_expire=scert_expire, scert_sigalg=scert_sigalg, indent=indent ) ## ssl (end) ## def mkQlocal(self, template, node=None, attrs=None, mqm_node=None, usePrefix=None): self_funct='mkQlocal' if attrs==None:attrs=node.getdAttrs() if usePrefix==None:usePrefix='' template.replace(usePrefix + 'qlocal_name', attrs['name']) if attrs.has_key('max_depth') and attrs['max_depth']!=None:template.replace(usePrefix + 'qlocal_max_depth', attrs['max_depth']) else:template.replace(usePrefix + 'qlocal_max_depth', '5000') if attrs.has_key('usage') and attrs['usage']!=None:usage=attrs['usage'] else:usage='NORMAL' template.replace(usePrefix + 'qlocal_usage', usage) if attrs.has_key('get') and attrs['get']!=None:template.replace(usePrefix + 'qlocal_get', attrs['get']) else:template.replace(usePrefix + 'qlocal_get', 'ENABLED') if attrs.has_key('put') and attrs['put']!=None:template.replace(usePrefix + 'qlocal_put', attrs['put']) else:template.replace(usePrefix + 'qlocal_put', 'ENABLED') if attrs.has_key('priority') and attrs['priority']!=None:template.replace(usePrefix + 'qlocal_priority', attrs['priority']) else:template.replace(usePrefix + 'qlocal_priority', '0') if attrs.has_key('cluster') and attrs['cluster']!=None: if usage=='XMITQ':raise xception.kikonfActionSystemException(self, self_funct, 'Local queue:' + attrs['name'] + ', the attribute cluster is not allowed for type XMITQ !') template.replace(usePrefix + 'qlocal_cluster', attrs['cluster']) else:template.replace(usePrefix + 'qlocal_cluster', '') if attrs.has_key('clusnl') and attrs['clusnl']!=None: if usage=='XMITQ':raise xception.kikonfActionSystemException(self, self_funct, 'Local queue:' + attrs['name'] + ', the attribute cluster is not allowed for type XMITQ !') template.replace(usePrefix + 'qlocal_clusnl', attrs['clusnl']) else:template.replace(usePrefix + 'qlocal_clusnl', '') if attrs.has_key('desc') and attrs['desc']!=None:template.replace(usePrefix + 'qlocal_desc', attrs['desc']) else:template.replace(usePrefix + 'qlocal_desc', '') #-- trigger template.replace(usePrefix + 'qlocal_trigger', 'NOTRIGGER') if node!=None and node.hasNode('trigger'): trigger_node=node.get('trigger')[0] trigger_attrs=trigger_node.getAttrs() if usage!='XMITQ':raise xception.kikonfActionSystemException(self, self_funct, 'Local queue:' + attrs['name'] + ', with usage:' + usage + ', Not allowed trigger. Triggers are only allowed on transmission queues !') if (trigger_attrs.trigdata!=None and trigger_attrs.process!=None) or (trigger_attrs.trigdata, trigger_attrs.process)==(None, None):raise xception.kikonfActionSystemException(self, self_funct, 'Local queue:' + attrs['name'] + ', only one of Trigger data or process is required !') if (trigger_attrs.trigdata!=None and trigger_attrs.process!=None):raise xception.kikonfActionSystemException(self, self_funct, 'Local queue:' + attrs['name'] + ', trigdata is not allowed when process is specified !') #if (trigger_attrs.userdata!=None and trigger_attrs.process==None):raise xception.kikonfActionSystemException(self, self_funct, 'Local queue:' + attrs['name'] + ', userdata is only allowed when process is specified !') if trigger_attrs.process!=None and trigger_attrs.initq=='SYSTEM.CHANNEL.INITQ':initq='SYSTEM.DEFAULT.INITIATION.QUEUE' else:initq=trigger_attrs.initq template.replace(usePrefix + 'qlocal_trigger', 'TRIGGER') template.replace(usePrefix + 'qlocal_trigtype', trigger_attrs.type) if trigger_attrs.trigdata!=None:template.replace(usePrefix + 'qlocal_trigdata', trigger_attrs.trigdata) else:template.replace(usePrefix + 'qlocal_trigdata', '') template.replace(usePrefix + 'qlocal_initq', initq) if trigger_attrs.process!=None:template.replace(usePrefix + 'qlocal_process', trigger_attrs.process) else:template.replace(usePrefix + 'qlocal_process', '') #-- Check if initq exists in queue locals if not initq.startswith('SYSTEM.'): tdc='mqm/queues/local@name=' + initq try: nodes=mqm_node.tdc(tdc, checkIsNode=True, checkIsUnique=True) except Exception, e: raise xception.kikonfActionSystemException(self, self_funct, 'Local queue:' + attrs['name'] + ', because the initq:' + trigger_attrs.initq + ' is not SYSTEM.CHANNEL.INITQ, it must be defined as Local queue ! SubException is:' + str(e)) #-- Check if process exists in processes. if trigger_attrs.process!=None: tdc='mqm/processes/process@name=' + trigger_attrs.process try: nodes=mqm_node.tdc(tdc, checkIsNode=True, checkIsUnique=True) except Exception, e: raise xception.kikonfActionSystemException(self, self_funct, 'Local queue:' + attrs['name'] + ', because the Process name:' + trigger_attrs.process + ' is defined for this queue, it must be defined as Process ! SubException is:' + str(e)) else: template.replace(usePrefix + 'qlocal_trigtype', 'NONE') template.replace(usePrefix + 'qlocal_trigdata', '') template.replace(usePrefix + 'qlocal_initq', '') template.replace(usePrefix + 'qlocal_process', '') def mkChannel(self, template, node=None, attrs=None, usePrefix=None): self_funct='mkChannel' if attrs==None:attrs=node.getdAttrs() typ=attrs['type'] # SVRCONN,CLNTCONN,RCVR,SDR,CLUSRCVR,CLUSSDR if usePrefix==None:usePrefix='' if (typ.endswith('SDR') or typ=='CLUSRCVR') and (attrs['host']==None or attrs['port']==None):raise xception.kikonfActionSystemException(self, self_funct, 'Channel:' + attrs['name'] + ', Host and Port attributes are required for sender channels !') if not typ.endswith('SDR'): if typ not in ('CLNTCONN', 'CLUSRCVR') and ((attrs.has_key('host') and attrs['host']!=None) or (attrs.has_key('port') and attrs['port']!=None)):raise xception.kikonfActionSystemException(self, self_funct, 'Channel:' + attrs['name'] + ', Host and Port attributes are only allowed for sender or CLNTCONN and CLUSRCVR channels !') if attrs.has_key('xmitq') and attrs['xmitq']!=None:raise xception.kikonfActionSystemException(self, self_funct, 'Channel:' + attrs['name'] + ', Xmitq is only allowed for sender channeles !') template.replace(usePrefix + 'channel_name', attrs['name']) template.replace(usePrefix + 'channel_type', typ) if typ in ('CLNTCONN', 'CLUSRCVR') or typ.endswith('SDR'):template.replace(usePrefix + 'channel_conname', "CONNAME('" + attrs['host'] + '(' + str(attrs['port']) + ')' + "')") else:template.replace(usePrefix + 'channel_conname', '') if typ.endswith('SDR') and typ!='CLUSSDR': if attrs.has_key('xmitq'):template.replace(usePrefix + 'channel_xmitq', "XMITQ('" + attrs['xmitq'] + "')") else:template.replace(usePrefix + 'channel_xmitq', "XMITQ(NONE)") else:template.replace(usePrefix + 'channel_xmitq', '') # - ssl if attrs.has_key('do_ssl') and attrs['do_ssl']=='true': if attrs.has_key('sslciph') and attrs['sslciph']!=None:template.replace(usePrefix + 'channel_sslciph', attrs['sslciph']) else:template.replace(usePrefix + 'channel_sslciph', '') if attrs.has_key('sslpeer') and attrs['sslpeer']!=None:template.replace(usePrefix + 'channel_sslpeer', attrs['sslpeer']) else:template.replace(usePrefix + 'channel_sslpeer', '') else: template.replace(usePrefix + 'channel_sslciph', '') template.replace(usePrefix + 'channel_sslpeer', '') if attrs.has_key('cluster') and attrs['cluster']!=None:template.replace(usePrefix + 'channel_cluster', "CLUSTER('" + attrs['cluster'] + "')") else:template.replace(usePrefix + 'channel_cluster', '') if attrs.has_key('clusnl') and attrs['clusnl']!=None:template.replace(usePrefix + 'channel_clusnl', "CLUSNL('" + attrs['clusnl'] + "')") else:template.replace(usePrefix + 'channel_clusnl', '') if (attrs.has_key('scydata') and attrs['scydata']!=None) or (attrs.has_key('scyexit') and attrs['scyexit']!=None): if typ!='SVRCONN':raise xception.kikonfActionSystemException(self, self_funct, 'Channel:' + attrs['name'] + ', Scydata and Scyexit Attributes are only allowed for SVRCONN channels !') if attrs.has_key('scydata') and attrs['scydata']!=None:template.replace(usePrefix + 'channel_scydata', attrs['scydata']) else:template.replace(usePrefix + 'channel_scydata', '') if attrs.has_key('scyexit') and attrs['scyexit']!=None:template.replace(usePrefix + 'channel_scyexit', attrs['scyexit']) else:template.replace(usePrefix + 'channel_scyexit', '') else: template.replace(usePrefix + 'channel_scydata', '') template.replace(usePrefix + 'channel_scyexit', '') if attrs.has_key('desc') and attrs['desc']!=None:template.replace(usePrefix + 'channel_desc', attrs['desc']) else:template.replace(usePrefix + 'channel_desc', '') def mkProcess(self, template, node=None, attrs=None, usePrefix=None): self_funct='mkProcess' if attrs==None:attrs=node.getdAttrs() if usePrefix==None:usePrefix='' template.replace(usePrefix + 'name', attrs['name']) template.replace(usePrefix + 'type', attrs['type']) template.replace(usePrefix + 'exec_path', attrs['exec_path']) if attrs.has_key('userdata') and attrs['userdata']!=None:template.replace(usePrefix + 'userdata', attrs['userdata']) else:template.replace(usePrefix + 'userdata', '') if attrs.has_key('desc') and attrs['desc']!=None:template.replace(usePrefix + 'desc', attrs['desc']) else:template.replace(usePrefix + 'desc', '') def mkSslKeys(self, dir, name, expire=None, password=None, doc=False, cert_label=None, cert_format=None, cert_path=None, dosc=False, slabel=None, scert_path=None, scert_format=None, scert_dn=None, scert_size=None, scert_expire=None, scert_sigalg=None, indent='' ): self_funct='mkSslKeys' from os import path doPrint=False if self.getVerbose()>=5:doPrint=True kpath=path.normpath(dir + '/' + name) + '.kdb' # -dn rules - # -size 512/10234/2048 - #! -x509version : 1/2/3 deft 3 #! -expire dft 365 #! -fips mode or not # -sigalg dft sha1, md5/sha1/sha224/sha256/sha384/sha512 - # -format dft ascii, binary - gsk7capicmd_cde = '\"' + path.normpath(self.getCAttr('software_gsk_bin') + '/gsk7capicmd' + self.getBinarySufix()) + '\"' ## Self keystore if not path.isfile(kpath): verbose('Keystore at:' + kpath + ' creating.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) # ex: gsk7capicmd.exe -keydb -create -db /my/keys/dir/wmqca.kdb -pw chocolate -type cms -expire 3650 -stash cdes=gsk7capicmd_cde + ' -keydb -create -db ' + kpath + ' -pw ' + password + ' -type cms -expire ' + str(expire) + ' -stash' # exec: ret, stdout, sdterr=subprocess(cdes, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr print if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Failed Creating the Self Sign Certificate keytsore !') verbose('Keystore at:' + kpath + ' created.\n', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) else:verbose('Pre-existing Keystore at:' + kpath + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) ## Self Sig Cert if dosc: verbose('Self Sign Certificate: ' + slabel + ' generating.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) # ex: gsk7capicmd.exe -cert -create -db /my/keys/dir/wmqca.kdb -pw chocolate -label wmqca -dn "CN=John,O=mycompany,OU=myunit,OU=test,C=US" -size 512 -expire 3650 cdes=gsk7capicmd_cde + ' -cert -create -db ' + kpath + ' -pw ' + password + ' -label ' + slabel + ' -dn ' + scert_dn + ' -size ' + str(scert_size) + ' -expire ' + str(scert_expire) # - Generates - exec ret, stdout, sdterr=subprocess(cdes, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr print if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Failed Generating Self Sign Certificate keytsore !') verbose('Self Sign Certificate: ' + slabel + ' generated.\n', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) #-- Infos: -cert Allow this parameters list: # -dn rules # -size 512/10234/2048 # -x509version : 1/2/3 deft 3 # -expire dft 365 # -fips mode or not # -sigalg dft sha1, md5/sha1/sha224/sha256/sha384/sha512 #-- print check cert presence # - Lists - exec verbose('Just created Self Sign Certificate: ' + slabel + ' listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) cdes=gsk7capicmd_cde + ' -cert -list -db ' + kpath + ' -pw ' + password ret, stdout, sdterr=subprocess(cdes, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr print if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Failed Listing just created Self Sign Certificate keytsore !') verbose('Just created Self Sign Certificate: ' + slabel + ' listed.\n', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) ## Extracting Self Cert verbose('Self Sign Certificate: ' + slabel + ' extracting.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) if self.getVerbose()>=1:print indent + '' # ex: gsk7capicmd.exe -cert -extract -db /my/keys/dir/wmqca.kdb -pw chocolate -label wmqca -target /my/keys/dir/wmqca.cert -format ascii cdes=gsk7capicmd_cde + ' -cert -extract -db ' + kpath + ' -pw ' + password + ' -label ' + slabel + ' -target ' + scert_path + ' -format ' + str(scert_format) # exec: ret, stdout, sdterr=subprocess(cdes, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr print if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Failed Extracting the Self Sign Certificate !') verbose('Self Sign Certificate: ' + slabel + ' extracted.\n', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) #-- Infos: ex: Requesting a cert # gsk7capicmd.exe -certreq -create -db /my/keys/dir/qm1.kdb -pw chocolate -label mykey_label -dn "CN=Paul, O=mycompany, OU=myunit, OU=test, C=US" -size 512 -file /my/keys/dir/mykey_certreq -fips -sigalg sha512 ## Cert if doc: # - Receiving the personal Cert if not path.isfile(cert_path):raise xception.kikonfActionSystemException(self, self_funct, 'Unable to find the Certificate file at:' + cert_path + ' please check your action file !') verbose('Certificate:' + cert_path + ' into keystore at:' + kpath + ' receiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) #gsk7capicmd.exe -cert -receive -file /my/keys/dir/myselfsign_cms -db qm1.kdb -pw chocolate -format ascii -fips cdes=gsk7capicmd_cde + ' -cert -add -db ' + kpath + ' -pw ' + password + ' -label ' + cert_label + ' -file ' + cert_path + ' -format ' + str(cert_format) # exec: ret, stdout, sdterr=subprocess(cdes, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr print if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Failed receiving Certificate into the keytsore !') verbose('Certificate:' + cert_path + ' into keystore at:' + kpath + ' received.\n', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) #-- Infos: -cert Allow this parameters list: # -format dft ascii, binary # -fips mode or not def getBinPath(self): bpath = self.getCAttr('software_wmq_bin') return bpath def getBinarySufix(self): if getOsType()=='windows':sufix='.exe' else:sufix='.sh' return sufix def checkClsAttributes(self, node, mqm_attrs, cls_global=None, cls_full=None, cls_full_repos=None, cls_clusters=None, indent=None): self_funct='checkClsAttributes' attrs = node.getAttrs() from os import path if node.getTag()=='channel' and attrs.type not in ('CLUSSDR', 'CLUSRCVR'):raise xception.kikonfActionSystemException(self, self_funct, 'Tag channel:' + attrs.name + ' the cluster attribute is only allowed for channel with type: CLUSSDR or CLUSRCVR !') doPrint=False if self.getVerbose()>=5:doPrint=True if attrs.cluster=='*': if len(cls_clusters)>1: node.setAttr('clusnl', cls_global) node.setAttr('cluster', None) else:node.setAttr('cluster', cls_clusters[0]) elif attrs.cluster=='$': if cls_full==None:raise xception.kikonfActionSystemException(self, self_funct, 'Tag channel, the usage of "$" for attribute cluster is only allowed when at least one cluster is defined with: full_repos="true" ! ') if len(cls_full_repos)>1: node.setAttr('clusnl', cls_full) node.setAttr('cluster', None) else:node.setAttr('cluster', cls_full_repos[0]) elif attrs.cluster.find(',')>=0: clusters=attrs.cluster.split(',') for cls in clusters: if cls not in cls_clusters:raise xception.kikonfActionSystemException(self, self_funct, 'Tag channel, the cluster:' + cls + ' should be defined as clusters/cluster ! ') clusters.sort() if clusters==cls_clusters: node.setAttr('clusnl', cls_global) node.setAttr('cluster', None) elif clusters==cls_full_repos: node.setAttr('clusnl', cls_full) node.setAttr('cluster', None) else: # Create specific Namelist name='_'.join(clusters) names=str(clusters).replace("'", '')[1:-1] verbose('Creating a specific Namelist: ' + name, level=self.getVerbose(), ifLevel=2, indent=indent + 3*' ', logFile=self.getLogFile()) # Temporary command file fileIn=path.normpath(self.getCurrentDir() + '/templates/' + 'mqm_namelist.tmpl') template=Template(fileIn) template.replace('name', name) template.replace('names', names) stdin=template.process() cde = '\"' + path.normpath(self.getBinPath() + '/' + 'runmqsc') + self.getBinarySufix() + '\" ' + mqm_attrs.name ret, stdout, sdterr=subprocess(cde, stdin=stdin, doPrint=doPrint) if self.getVerbose()>=5: print stdout print sdterr if ret!=0:raise xception.kikonfActionSystemException(self, self_funct, 'Echec Creating the Namelist !') node.setAttr('clusnl', name) node.setAttr('cluster', None) else: if attrs.cluster not in cls_clusters:raise node.setAttr('cluster', attrs.cluster) def verbose(self, name): verbose('Managing Qmanager:' + name, level=self.getVerbose(), level=self.getVerbose(), ifLevel=2, indent=self.getIndent(), logFile=self.getLogFile())
Trademarks :
|