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







Vhost

print

Action : was.vhost   (Category : was, Name : vhost, By : kikonf)
Complete Name : was.vhost.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 vhost plugin : Creates a WebSphere Virtual Host

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

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 Vhost(wasAction):
    
    def extract(self, name=None, prefix=None, **keywords):
        self.verbose(name=name, prefix=prefix)
        indent=self.getIndent() + 3*' '        

        verbose('VirtualHost retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())        
        vhs=getStartByNameAsDict(split(AdminConfig.getid('/Cell:' + self.getCell() + '/VirtualHost:/')))
                
        for vname in vhs.keys():
            
            if prefix!=None and name!=None and vname==prefix + '_' + name \
            or prefix==None and name!=None and name==vname \
            or prefix!=None and name==None and vname.startswith(prefix) \
            or prefix==None and name==None:
                vhosts=getShowAsDict(AdminConfig.show(vhs[vname]))
                verbose('VirtualHost:' + vname + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())

                vhost_node=self.newTop() # because in extract, this return a blank vhost node.
                if prefix!=None:vname=vname.split(prefix + '_')[1]
                
                vhost_node.setAttrs(name=vname, prefix=prefix)

                as=split(vhosts['aliases'])
                for a in as:
                    if a=='':continue
                    aliases=getShowAsDict(AdminConfig.show(a))
                    vhost_node.newNode('alias', host=aliases['hostname'], port=aliases['port'])

    def remove(self, no_name, no_name_no_prefix):
        vhost_node = self.getTop()        
        vhost_attrs = vhost_node.getAttrs()
        self.verbose(name=vhost_attrs.name, prefix=vhost_attrs.prefix)
        indent=self.getIndent() + 3*' '
            
        # no_name/no_name_no_prefix
        prefix=vhost_attrs.prefix        
        name=vhost_attrs.name
        if no_name or no_name_no_prefix:name=None
        if no_name_no_prefix:prefix=None
        
        self.rmvVirtualHost(name=name, prefix=prefix, indent=indent)

    def inject(self):
        self_funct='inject'
        vhost_node = self.getTop()        
        vhost_attrs = vhost_node.getAttrs()
        self.verbose(name=vhost_attrs.name, prefix=vhost_attrs.prefix)
        indent=self.getIndent() + 3*' '
        
        self.rmvVirtualHost(name=vhost_attrs.name, prefix=vhost_attrs.prefix, indent=indent)
        
        # - name
        if vhost_attrs.prefix==None:name=vhost_attrs.name
        else:name=vhost_attrs.prefix + '_' + vhost_attrs.name

        cmdvalues=[]
        cmdvalues.append(['name', name])
        
        aliases=[]
        cmdvalues.append(['aliases', aliases])
        
        if vhost_node.hasNode('alias'):
            alias_nodes=vhost_node.getNode('alias')
            
            for aliase_node in alias_nodes:
                as=[]
                aliases.append(as)
                alias_attrs=aliase_node.getAttrs()
                
                as.append(['hostname', alias_attrs.host])
                as.append(['port', alias_attrs.port])

        verbose('VirtualHost:' + name + ' retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        AdminConfig.create('VirtualHost', AdminConfig.getid('/Cell:' + self.getCell() + '/'), cmdvalues)
        verbose('VirtualHost:' + name + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
        
    def rmvVirtualHost(self, name, prefix=None, indent=None):
        verbose('VirtualHost retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        
        vhs=getStartByNameAsDict(split(AdminConfig.getid('/Cell:' + self.getCell() + '/VirtualHost:/')))
        
        for vname in vhs.keys():
            
            if prefix!=None and vname.startswith(prefix) \
            or prefix==None and name!=None and name==vname \
            or prefix==None and name==None:
                verbose('VirtualHost:' + vname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())        
                AdminConfig.remove(vhs[vname])
                verbose('VirtualHost:' + vname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())        
        
    def verbose(self, name=None, prefix=None):
        
        if name!=None:verbose('VirtualHost:' + name + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
        elif prefix!=None:verbose('VirtualHosts under prefix:' + prefix + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
        else:verbose('VirtualHosts.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
							
(Source: <KIKONF_INSTALLATION_DIR>/plugins/actions/was/vhost/by/kikonf/vhost.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