codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#! /bin/false # This script must be run with the command: java weblogic.WLST RenameDomain.py # from the source domain directory. # # Author: Simon Vans-Colina # Client: XXXXXX # Date: 10 July 2006 # Purpose: This script runs in the domain home of a weblogic domain that needs to be # standardized. It takes the essential config from the domain and builds a new domain # according to an agreed standard. This new domain is put in the standard location, # will have standard start and stop scripts etc. try: import weblogic except: print "Weblogic.jar needs to be on your CLASSPATH. Exiting" raise SystemExit(1) import javax.xml import java.io.FileInputStream as fis import java.io.FileOutputStream as fos try: import org.apache.tools.ant as ant except: print "Ant.jar needs to be on your classpath" raise SystemExit(1) try: import os import shutil except: print "Python shutils could not be found, are you running java weblogic.WLST to execute this script?" raise SystemExit(1) import java.io.BufferedReader as BR import java.lang.System.in java.lang.System.in as Sin import java.io.InputStreamReader as isr import java.lang.System.out.print as jprint import weblogic.security es=weblogic.security.internal.SerializedSystemIni.getEncryptionService(".") ces=weblogic.security.internal.encryption.ClearOrEncryptedService(es) #Standards are defined here class ConfigStore: def __init__(self, fileLocation): factory=javax.xml.parsers.DocumentBuilderFactory.newInstance() builder=factory.newDocumentBuilder() input=fis(fileLocation) self.document=builder.parse(input) self.DOM=self.document.getDocumentElement() def write(self, newFileLocation): xmlFrom=javax.xml.transform.dom.DOMSource(self.document) xmlTo=javax.xml.transform.stream.StreamResult(fos(newFileLocation)) Transformer=javax.xml.transform.TransformerFactory.newInstance().newTransformer() Transformer.transform(xmlFrom, xmlTo) def ask(Question, default=None): jprint(Question) if default: jprint("[%s]" % default) return BR(isr(Sin)).readLine() or default def changeAttributes(node, oldvalue, newvalue): if node.getAttributes(): for i in range(node.getAttributes().getLength()): attr=node.getAttributes().item(i) if attr.getValue()==oldvalue: attr.setValue(newvalue) def nodeWalk(node, oldvalue, newvalue): for n in range(node.getChildNodes().getLength()): cn=node.getChildNodes().item(n) nodeWalk(cn, oldvalue, newvalue) changeAttributes(node, oldvalue, newvalue) configxml=ConfigStore("./config.xml") numServers=configxml.DOM.getElementsByTagName("Server").getLength() domainName=configxml.DOM.getAttribute("Name") print "The domain found: %s has %s servers." % (domainName, numServers) ## Rename the Domain. oldName=configxml.DOM.getAttribute("Name") newName=ask("What do you want to rename this domain to? ", "Domain") nodeWalk(configxml.DOM, oldName, newName) ## Rename the servers if required. for i in range(configxml.DOM.getElementsByTagName("Server").getLength()): serverNode=configxml.DOM.getElementsByTagName("Server").item(i) oldName=serverNode.getAttribute("Name") newName= ask("What do you want to rename the %s server to? " % oldName, oldName) nodeWalk(configxml.DOM, oldName, newName) ## Decrypt the JDBC passwords for j in range(configxml.DOM.getElementsByTagName("JDBCConnectionPool").getLength()): poolNode=configxml.DOM.getElementsByTagName("JDBCConnectionPool").item(j) poolNode.setAttribute("Password", ces.decrypt(poolNode.getAttribute("PasswordEncrypted")) ) poolNode.removeAttribute("PasswordEncrypted") ## Decrypt the EmbeddedLDAP for j in range(configxml.DOM.getElementsByTagName("EmbeddedLDAP").getLength()): poolNode=configxml.DOM.getElementsByTagName("EmbeddedLDAP").item(j) poolNode.setAttribute("Credential", ces.decrypt(poolNode.getAttribute("CredentialEncrypted")) ) poolNode.removeAttribute("CredentialEncrypted") ## Decrypt the Security Configuration for j in range(configxml.DOM.getElementsByTagName("SecurityConfiguration").getLength()): poolNode=configxml.DOM.getElementsByTagName("SecurityConfiguration").item(j) poolNode.setAttribute("Credential", ces.decrypt(poolNode.getAttribute("CredentialEncrypted")) ) poolNode.removeAttribute("CredentialEncrypted") ## Decrypt the ServerStart for j in range(configxml.DOM.getElementsByTagName("ServerStart").getLength()): poolNode=configxml.DOM.getElementsByTagName("ServerStart").item(j) poolNode.setAttribute("Password", ces.decrypt(poolNode.getAttribute("PasswordEncrypted")) ) poolNode.removeAttribute("PasswordEncrypted") ## Finally write out the config.xml configxml.write(ask("What do you want to call the new config.xml? ", "new-config.xml"))
Private
[
?
]
Run code