|
|
|
Vhost
Action : wls.vhost (Category : wls, Name : vhost, By : kikonf)
Complete Name : wls.vhost.by.kikonf Version : 4.0 License : Modified BSD License Purpose of the wls category : Easy to customize. This category use in background the wlst command in jython mode, to drive WebLogic Server ® configuration. You can use it to manage the whole WebLogic ® architecture. Purpose of this vhost plugin : Creates a Virtual Host The following shows the main Source Code File for the Action : wls.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.wls.tools import * from java.lang import String class Vhost(wlsAction): def extract(self, scope_attrs, name=None, prefix=None, **keywords): self_funct='extract' self.verbose(scope_attrs, name=name, prefix=prefix) scope_cp, scope_attrs, scope=self.getScope(scope_attrs=scope_attrs, indent=self.getIndent()) indent=self.getIndent() + 3*' ' verbose('VirtualHost retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) cmo=cd('/') vmb=getMBean('/VirtualHosts') vhs=vmb.getVirtualHosts() for vhost in vhs: vname=vhost.getName() 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: if not checkTarget(vhost, scope):continue cmo=cd('/VirtualHosts/' + vhost.getName()) verbose('VirtualHost:' + vname + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) channel=cmo.getNetworkAccessPoint() # - gets description cmo=cd('/VirtualHosts/' + vname) desc=cmo.getNotes() if desc==DESIGN_NOTICE:desc=None 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, desc=desc, channel=channel, prefix=prefix) mkNodeScope(vhost_node, scope_attrs, isUnique=True) #-- creates a scope node. urls=cmo.getVirtualHostNames() for url in urls: vhost_node.newNode('aliases', host=url) def remove(self, no_name, no_name_no_prefix): vhost_node = self.getTop() vhost_attrs = vhost_node.getAttrs() scope_cp, scope_attrs, scope=self.getScope(parent_node=vhost_node, indent=self.getIndent()) #-- Retreives scope self.verbose(scope_attrs, 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() scope_cp, scope_attrs, scope=self.getScope(parent_node=vhost_node, indent=self.getIndent()) #-- Retreives scope self.verbose(scope_attrs, 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 # - create vost cmo=cd('/') vhmb=cmo.createVirtualHost(name) # - description if vhost_attrs.desc!=None:desc=vhost_attrs.desc else:desc=DESIGN_NOTICE cmo=cd('/VirtualHosts/' + name) cmo.setNotes(desc) # - set target cmo=cd('/') tg=getMBean(scope_cp) vhmb.addTarget(tg) # <=> cmo=cd('/VirtualHosts/' + name) ? # cmo.setTargets(getMBean(scope_cp)) if vhost_node.hasNode('alias'): alias_nodes=vhost_node.getNode('alias') as=[] for aliase_node in alias_nodes: alias_attrs=aliase_node.getAttrs() as.append(String(alias_attrs.host)) verbose('VirtualHost:' + name + ' retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) cmo=cd('/VirtualHosts/' + name) cmo.setVirtualHostNames(jarray.array(as, String)) verbose('VirtualHost:' + name + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) def rmvVirtualHost(self, name, prefix=None, indent=None): scope_cp, scope_attrs, scope=self.getScope() verbose('VirtualHost retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile(), logFile=self.getLogFile()) cmo=cd('/') vmb=getMBean('/VirtualHosts') vhs=vmb.getVirtualHosts() for vhost in vhs: vname=vhost.getName() if prefix!=None and vname.startswith(prefix) \ or prefix==None and name!=None and name==vname \ or prefix==None and name==None: if not checkTarget(vhost, scope):continue verbose('VirtualHost:' + vname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) cmo=cd('/') cmo.destroyVirtualHost(vhost) verbose('VirtualHost:' + vname + ' 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 and prefix!=None:verbose('VirtualHost:' + name + ', under prefix:' + prefix+ ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent()) elif name!=None:verbose('VirtualHost:' + name + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent()) elif prefix!=None:verbose('VirtualHosts under prefix:' + prefix + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent()) else:verbose('VirtualHosts at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
Trademarks :
|