cle_clock
Home > wikikonf >  was/actions/by kikonf > mail







Mail

print

Action : was.mail   (Category : was, Name : mail, By : kikonf)
Complete Name : was.mail.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 mail plugin : Configure a Java Mail Client

The following shows the main Source Code File for the Action : was.mail

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 Mail(wasAction):
    PROVIDER='MailProvider:Built-in Mail Provider/'
            
    def extract(self, scope_attrs=None, name=None, prefix=None, **keywords):
        self_funct='extract'
        scope_id, scope_attrs, scope=self.getScope(scope_attrs=scope_attrs, indent=self.getIndent())
        self.verbose(scope_attrs, name=name, prefix=prefix)
        indent=self.getIndent() + 3*' '

        verbose('MailSession listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        
        msessions=getStartByNameAsDict(split( AdminConfig.list('MailSession', scope_id) ))        
        for msname in msessions.keys():
            if prefix!=None and name!=None and msname==prefix + '_' + name \
            or prefix==None and name!=None and name==msname \
            or prefix!=None and name==None and msname.startswith(prefix) \
            or prefix==None and name==None:

                mail_sessions=getShowAsDict(AdminConfig.show(msessions[msname]))
                verbose('MailSession:' + msname + ' listed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())                
                
                attrs={}     
                mail_node=self.newTop() #-- because in extract mode, each call returns a new blank top node.
                _name=msname
                if prefix!=None:_name=msname.split(prefix + '_')[1]
                
                attrs['name']=_name
                attrs['jndi_name']=mail_sessions['jndiName']
                if mail_sessions.has_key('mailTransportHost'):attrs['host']=mail_sessions['mailTransportHost']
                if mail_sessions.has_key('user'):attrs['user']=mail_sessions['mailTransportUser']
                else:attrs['user']='?'
                if mail_sessions.has_key('password'):attrs['password']=mail_sessions['mailTransportPassword']
                else:attrs['password']='?'
                attrs['store']=AdminConfig.showAttribute(mail_sessions['mailStoreProtocol'], 'protocol')

                mail_node.setAttrs(**attrs)                                     # tag: mail

                mkNodeScope(mail_node, scope_attrs, isUnique=True)              # tag: scope

    def remove(self, no_name, no_name_no_prefix):
        self_funct='remove'
        mail_node = self.getTop()        
        mail_attrs = mail_node.getAttrs()
        scope_id, scope_attrs, scope=self.getScope(parent_node=mail_node, indent=self.getIndent()) #-- Retreives scope
        self.verbose(scope_attrs, name=mail_attrs.name, prefix=mail_attrs.prefix)
        indent=self.getIndent() + 3*' '
        
        # no_name/no_name_no_prefix
        prefix=mail_attrs.prefix        
        name=mail_attrs.name
        if no_name or no_name_no_prefix:name=None
        if no_name_no_prefix:prefix=None
        
        self.rmvMail(name=mail_attrs.name, prefix=mail_attrs.prefix, indent=indent)
        
    def inject(self):
        self_funct='inject'
        mail_node = self.getTop()        
        mail_attrs = mail_node.getAttrs()
        scope_id, scope_attrs, scope=self.getScope(parent_node=mail_node, indent=self.getIndent()) #-- Retreives scope

        #-- name
        if mail_attrs.prefix==None:name=mail_attrs.name
        else:name=mail_attrs.prefix + '_' + mail_attrs.name
        self.verbose(scope_attrs, name=mail_attrs.name, prefix=mail_attrs.prefix)
        indent=self.getIndent() + 3*' '

        #-- remove first
        self.rmvMail(name=mail_attrs.name, prefix=mail_attrs.prefix, indent=indent)
    
        verbose('MailProvider retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        prv = AdminConfig.getid(self.getScopeCP() + '/' + Mail.PROVIDER)
        pprvs=split(AdminConfig.showAttribute(prv, 'protocolProviders'))
        
        transport_protocol=None
        store_protocol=None
        for pprv in pprvs:
            protocol_providers=getShowAsDict(AdminConfig.show(pprv))
            if protocol_providers['type']=='TRANSPORT' and protocol_providers['protocol']=='smtp':
                transport_protocol=pprv
            elif protocol_providers['type']=='STORE' and protocol_providers['protocol']==mail_attrs.store:store_protocol=pprv

        cmdvalues=[]
        cmdvalues.append(['name', name])
        cmdvalues.append(['jndiName', mail_attrs.jndi_name])
        cmdvalues.append(['mailTransportHost', mail_attrs.host])
        cmdvalues.append(['mailTransportUser', mail_attrs.user])
        cmdvalues.append(['mailTransportPassword', mail_attrs.password])
        cmdvalues.append(['mailStoreProtocol', store_protocol])
        cmdvalues.append(['mailTransportProtocol', transport_protocol])

        verbose('MailSession creating.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        AdminConfig.create('MailSession', prv, cmdvalues)
        verbose('MailSession:' + name + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())                
        
    def rmvMail(self, name=None, prefix=None, indent=None):
        scope_id, scope_attrs, scope=self.getScope()
        
        verbose('MailSession listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        msessions = getStartByNameAsDict(split(AdminConfig.list('MailSession', scope_id)))
        for msname in msessions.keys():

            if prefix!=None and msname.startswith(prefix) \
            or prefix==None and name!=None and name==msname \
            or prefix==None and name==None:
            
                verbose('MailSession:' + msname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
                AdminConfig.remove(msessions[msname])
                verbose('MailSession:' + msname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())                
                
    def verbose(self, scope_attrs, name=None, prefix=None):
        scope=str(scope_attrs).replace("'", '')[1:-1]
        
        if name!=None:verbose('MailSession:' + name + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
        elif prefix!=None:verbose('MailSessions under prefix:' + prefix + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
        else:verbose('MailSessions at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
							
(Source: <KIKONF_INSTALLATION_DIR>/plugins/actions/was/mail/by/kikonf/mail.py)


  • Line 1 to 3 say something , say something , say something
  • Line 10 to 17 say something , say something , say something , say something , say something
  • Line 20 to 25 say something



Trademarks :
  • "IBM", "WebSphere", "WebSphere Aplication Server", "WAS" are registred trademarks of International Business Machines Corporation.
  • "Java" and "JVM" are a registred trademarks of Oracle and/or its affiliates.
  • Other names may be trademarks of their respective owners.

Copyright © 2011 - Patrick Placidoux, Hélène Malamoud