#############################################################################
# Create a OSB domain
#
# @author fibik, Bluegarden
# @version 1.0, 2017-07-07
#
#############################################################################
# Modify these values as necessary
import os
import sys, traceback
scriptName = 'createDomain.py'


propertyFile = sys.argv[1]
print "Loading properties from %s" % propertyFile
loadProperties(propertyFile)

#
# Load and update properties from System Environment
if os.environ.get("MW_HOME") != None:
	MW_HOME = os.environ.get("MW_HOME")

if os.environ.get("DOMAIN_NAME") != None:
	DOMAIN_NAME = os.environ.get("DOMAIN_NAME")

if os.environ.get("DOMAIN_HOME") != None:
	soaDomainHome = os.environ.get("DOMAIN_HOME")
else:
	soaDomainHome = DOMAIN_DIR + '/' + DOMAIN_NAME
if os.environ.get("APPLICATION_HOME") != None:
	soaApplicationsHome = os.environ.get("APPLICATION_HOME")
else:
	soaApplicationsHome = APPLICATIONS_HOME + '/' + DOMAIN_NAME
	
if os.environ.get("APP_HOST") != None:
	ADMINSERVER_LISTENADDRESS = os.environ.get("APP_HOST")
if os.environ.get("ADMIN_PORT") != None:
	ADMINSERVER_PORT = os.environ.get("ADMIN_PORT")
if os.environ.get("ADMIN_PASSWORD") != None:
	ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD")
if os.environ.get("DB_HOST") != None:
	SOA_REPO_DB_URL = 'jdbc:oracle:thin:@' + os.environ.get("DB_HOST") + ':1521/opdb'
if os.environ.get("SCHEMA_PREFIX") != None:
	SOA_REPO_DB_USER_PREFIX = os.environ.get("SCHEMA_PREFIX")
if os.environ.get("RCU_PASSWORD") != None:
	SOA_REPO_STB_PWD = os.environ.get("RCU_PASSWORD")


#
#Home Folders
wlsHome             = MW_HOME + '/wlserver'
#soaDomainHome       = DOMAIN_DIR + '/' + DOMAIN_NAME
#soaApplicationsHome = APPLICATIONS_HOME + '/' + DOMAIN_NAME

#
# Templates for 12.2.1
wlsjar              = MW_HOME + '/wlserver/common/templates/wls/wls.jar'
oracleCommonTplHome = MW_HOME + '/oracle_common/common/templates'
wlservicetpl        = oracleCommonTplHome + '/wls/oracle.wls-webservice-template.jar'
osbtpl              = MW_HOME + '/osb/common/templates/wls/oracle.osb_template.jar'
applCoreTpl         = oracleCommonTplHome + '/wls/oracle.applcore.model.stub_template.jar'



#
# ServerGroup definitions
adminSvrGrpDesc = 'WSM-CACHE-SVR WSMPM-MAN-SVR JRF-MAN-SVR'
adminSvrGrp     = ["WSM-CACHE-SVR" , "WSMPM-MAN-SVR" , "JRF-MAN-SVR"]
osbSvrGrpDesc   = "OSB-MGD-SVRS-COMBINED"
osbSvrGrp       = ["OSB-MGD-SVRS-COMBINED"]
singlOsbSvrGrpDesc   = "WSM-CACHE-SVR WSMPM-MAN-SVR JRF-MAN-SVR OSB-MGD-SVRS-COMBINED"
singlOsbSvrGrp       = ["WSM-CACHE-SVR" , "WSMPM-MAN-SVR" , "JRF-MAN-SVR", "OSB-MGD-SVRS-COMBINED"]
#
#
lineSeperator='__________________________________________________________________________________'
#
#
def usage():
	print 'Call script as: '
	print 'Windows: wlst.cmd ' + scriptName + ' -loadProperties localhost.properties'
	print 'Linux: wlst.sh ' + scriptName + ' -loadProperties environment.properties'
	print 'Property file should contain the following properties: '
	print "adminUrl='localhost:7000'"
	print "adminUser='weblogic'"
	print "adminPwd='welcome1'"

#
# Create a boot properties file.
def createBootPropertiesFile(directoryPath, fileName, username, password):
	print ('Create Boot Properties File for folder: ' + directoryPath)
	print (lineSeperator)
	serverDir = File(directoryPath)
	bool = serverDir.mkdirs()
	fileNew=open(directoryPath + '/'+fileName, 'w')
	fileNew.write('username=%s\n' % username)
	fileNew.write('password=%s\n' % password)
	fileNew.flush()
	fileNew.close()

#
# Create Startup Properties File
def createAdminStartupPropertiesFile(directoryPath, args):
	print 'Create AdminServer Boot Properties File for folder: '+directoryPath
	print (lineSeperator)
	adminserverDir = File(directoryPath)
	bool = adminserverDir.mkdirs()
	fileNew=open(directoryPath + '/startup.properties', 'w')
	args=args.replace(':', '\\:')
	args=args.replace('=', '\\=')
	fileNew.write('Arguments=%s\n' % args)
	fileNew.flush()
	fileNew.close()

#
# Set Log properties
def setLogProperties(logMBeanPath):
	print '\nSet Log Properties for: ' + logMBeanPath
	print (lineSeperator)
	cd(logMBeanPath)
	print ('Server log path: ' + pwd())
	#print '. set FileName to ' + logFile
	#set('FileName'    ,logFile)
	print '. set FileCount to ' + str(FILE_COUNT)
	set('FileCount', int(FILE_COUNT))
	print '. set FileMinSize to ' + str(FILE_MINSIZE)
	set('FileMinSize' ,int(FILE_MINSIZE))
	print '. set RotationType to '+ ROTATION_TYPE
	set('RotationType', ROTATION_TYPE)
	print '. set FileTimeSpan to '+str(FILE_TIMESPAN)
	set('FileTimeSpan',int(FILE_TIMESPAN))
	print '. set RotateLogOnStartup to '+'true'
	set('RotateLogOnStartup', 'true')
	print '. set DateFormatPattern to '+'yyyy-MM-dd, HH:mm:ss,S z'
	set('DateFormatPattern', 'yyyy-MM-dd, HH:mm:ss,S z')

#
# Set Log properties
def setExtraLogProperties(serverName):
	print '\nSet Extra Log Properties for: ' + serverName
	print (lineSeperator)
	cd('/Servers/' + serverName)
	create(serverName, 'WebServer')
	cd('WebServer/' + serverName)
	create(serverName, 'WebServerLog')
	cd('WebServerLog/' + serverName)
	print ('Server log path: ' + pwd())
	print '. set FileCount to ' + str(FILE_COUNT)
	set('FileCount', int(FILE_COUNT))
	print '. set FileMinSize to ' + str(FILE_MINSIZE)
	set('FileMinSize' ,int(FILE_MINSIZE))
	print '. set RotationType to '+ ROTATION_TYPE
	set('RotationType', ROTATION_TYPE)
	print '. set FileTimeSpan to '+str(FILE_TIMESPAN)
	set('FileTimeSpan',int(FILE_TIMESPAN))
	print '. set RotateLogOnStartup to '+'true'
	set('RotateLogOnStartup', 'true')

	cd('/Servers/' + serverName)
	create(serverName, 'DataSource')
	cd('DataSource/' + serverName)
	create(serverName, 'DataSourceLogFile')
	cd('DataSourceLogFile/' + serverName)
	print ('Server log path: ' + pwd())
	print '. set FileCount to ' + str(FILE_COUNT)
	set('FileCount', int(FILE_COUNT))
	print '. set FileMinSize to ' + str(FILE_MINSIZE)
	set('FileMinSize' ,int(FILE_MINSIZE))
	print '. set RotationType to '+ ROTATION_TYPE
	set('RotationType', ROTATION_TYPE)
	print '. set FileTimeSpan to '+str(FILE_TIMESPAN)
	set('FileTimeSpan',int(FILE_TIMESPAN))
	print '. set RotateLogOnStartup to '+'true'
	set('RotateLogOnStartup', 'true')

#
#
def createLogDir(directoryPath):
	print ('\nCreate Log dir ' + directoryPath + '/logs')
	print (lineSeperator)
	serverDir = File(directoryPath + '/logs')
	bool = serverDir.mkdirs()

#
#
def createServerLog(serverName):
	print ('\nCreate Log for ' + serverName)
	print (lineSeperator)
	cd('/Server/' + serverName)
	create(serverName,'Log')
	setLogProperties('/Server/' + serverName + '/Log/' + serverName)
	setExtraLogProperties(serverName)

#
# Change DataSource to XA
def changeDatasourceToXA(datasource):
	print 'Change datasource ' + datasource
	print (lineSeperator)
	cd('/')
	cd('/JDBCSystemResource/' + datasource + '/JdbcResource/' + datasource + '/JDBCDriverParams/NO_NAME_0')
	set('DriverName','oracle.jdbc.xa.client.OracleXADataSource')
	print '. Set UseXADataSourceInterface=' + 'True'
	set('UseXADataSourceInterface', 'True') 
	cd('/JDBCSystemResource/' + datasource + '/JdbcResource/' + datasource + '/JDBCDataSourceParams/NO_NAME_0')
	print '. Set GlobalTransactionsProtocol=' + 'TwoPhaseCommit'
	set('GlobalTransactionsProtocol', 'TwoPhaseCommit')
	cd('/')
#
#
def createCluster(cluster, clusterAddress):
	print ('\nCreate ' + cluster)
	print (lineSeperator)
	cd('/')
	create(cluster, 'Cluster')
	cd('Cluster/' + cluster)
	# Using unicast with the default broadcast channel.  Can override channel by setting attribute 'ClusterBroadcastChannel'
	print '. Set ClusterMessagingMode=' + 'unicast'
	set('ClusterMessagingMode', 'unicast')
	print '. Set ClusterAddress=' + clusterAddress
	set('ClusterAddress', clusterAddress)

#
# Create a Unix Machine
def createUnixMachine(serverMachine, serverAddress, port):
	print('\nCreate machine ' + serverMachine + ' with type UnixMachine')
	print (lineSeperator)
	cd('/')
	create(serverMachine, 'UnixMachine')
	cd('UnixMachine/' + serverMachine)
	create(serverMachine, 'NodeManager')
	cd('NodeManager/' + serverMachine)
	set('ListenAddress', serverAddress)
	#set('NMType', 'Plain')
	set('ListenPort', int(port))
  
#
# Add server to  Unix Machine
def addServerToMachine(serverName, serverMachine):
	print('\nAdd server ' + serverName + ' to ' + serverMachine)
	print (lineSeperator)
	cd('/Servers/' + serverName)
	set('Machine', serverMachine)

#
# Determine the Server Java Args
def getServerJavaArgs(serverName,javaArgsBase,logsHome):
	#javaArgs = javaArgsBase+' -Dweblogic.Stdout='+logsHome+'/'+serverName+'.out -Dweblogic.Stderr='+logsHome+'/'+serverName+'_err.out'
	javaArgs = javaArgsBase
	return javaArgs

#
# Defines the remote startup parameters of the given server.
def setupServerStart(name, startupJavaArgs):
	cd('/Servers/' + name)
	print ('. Create ServerStart')
	create(name, 'ServerStart')
	cd('ServerStart/' + name)
	print ('.. Set JavaVendor' + JAVA_VENDOR)
	set('JavaVendor', JAVA_VENDOR)
	set('PasswordEncrypted', ADMIN_PASSWORD)
	print ('.. Set JavaHome' + JAVA_HOME)
	set('JavaHome', JAVA_HOME)
	print ('.. Set Username' + ADMIN_NAME)
	set('Username', ADMIN_NAME)
	print ('.. Set Arguments' + startupJavaArgs)
	set('Arguments', startupJavaArgs)
	print ('.. Set RootDirectory' + soaDomainHome)
	set('RootDirectory', soaDomainHome)
	print ('.. Set BeaHome' + MW_HOME)
	set('BeaHome', MW_HOME)
	print ('.. Set ClassPath' + STARTUP_CLASSPATH)
	set('ClassPath', STARTUP_CLASSPATH)
	print ('.. Set SecurityPolicyFile' + MW_HOME + '/wlserver/server/lib/weblogic.policy')
	set('SecurityPolicyFile', MW_HOME + '/wlserver/server/lib/weblogic.policy')

#
# Change Managed Server
def changeManagedServer(server, listenAddress, listenPort, useSSL, sslPort, javaArgs):
	print '\nChange ManagedServer ' + server
	print (lineSeperator)
	cd('/Servers/' + server)
	print '. Set listen address and port to: ' + listenAddress + ':' + str(listenPort)
	set('ListenAddress', listenAddress)
	set('ListenPort', int(listenPort))
	# ServerStart
	setupServerStart(server, javaArgs)
	
	# SSL
	cd('/Server/' + server)
	print ('. Create server SSL')
	create(server, 'SSL')
	cd('SSL/' + server)
	print ('. Set SSL Enabled to: ' + useSSL)
	set('Enabled', useSSL)
	if useSSL == "true":
		print ('. Set SSL ListenPort to: ' + str(sslPort))
		set('ListenPort', int(sslPort))
		set('TwoWaySSLEnabled', 'true')
		set('ClientCertificateEnforced', 'false')

	print ('. Set SSL HostNameVerificationIgnored to: ' + 'True')
	set('HostNameVerificationIgnored', 'True')
	#
	if jsseEnabled == 'true':
		print ('. Set JSSEEnabled to: ' + 'True')
		set('JSSEEnabled', 'True')
	else:
		print ('. Set JSSEEnabled to: ' + 'False')
		set('JSSEEnabled', 'False')

	cd('/Server/' + server)
	print ('. Set Max Message Size For Server: ' + server + ' value: ' + str(MAX_MSG_SIZE))
	set('MaxMessageSize', int(MAX_MSG_SIZE))
	# Set weblogic plugin enabled
	cd('/Servers/' + server)
	set('WeblogicPluginEnabled', 'true')
	set('ClientCertProxyEnabled', 'true')

#
# Create a Managed Server
def createManagedServer(server, listenAddress, listenPort, cluster, machine, useSSL, sslPort, javaArgs):
	print('\nCreate '+server)
	print (lineSeperator)
	cd('/')
	create(server, 'Server')
	cd('/Servers/' + server)
	changeManagedServer(server, listenAddress, listenPort, useSSL, sslPort, javaArgs)
	createServerLog(server)
	print('Add ' + server + ' to cluster ' + cluster)
	cd('/')
	assign('Server', server, 'Cluster', cluster)
	addServerToMachine(server, machine)

#
# Adapt a Managed Server
def adaptManagedServer(server, newSrvName, listenAddress, listenPort, cluster, machine, useSSL, sslPort, javaArgs):
	print('\nAdapt ' + server)
	print (lineSeperator)
	cd('/')
	cd('/Servers/' + server)
	# name of adminserver
	print '. Rename ' + server + ' to ' + newSrvName
	set('Name', newSrvName)
	cd('/Servers/' + newSrvName)
	changeManagedServer(newSrvName, listenAddress, listenPort, useSSL, sslPort, javaArgs)
	createServerLog(newSrvName)
	print('Add ' + newSrvName + ' to cluster ' + cluster)
	cd('/')
	assign('Server', newSrvName, 'Cluster', cluster)
	addServerToMachine(newSrvName, machine)

#
# Change Admin Server
def changeAdminServer(adminServerName, listenAddress, listenPort, useSSL, sslPort, javaArguments):
	print '\nChange AdminServer'
	print (lineSeperator)
	cd('/Servers/AdminServer')
	# name of adminserver
	print '. Set Name to ' + adminServerName
	set('Name', adminServerName )
	cd('/Servers/' + adminServerName)
	# address and port
#	print '. Set ListenAddress to ' + listenAddress
#	set('ListenAddress', listenAddress)
	print '. Set ListenPort to ' + str(listenPort)
	set('ListenPort', int(listenPort))
	#
	# ServerStart
	setupServerStart(adminServerName, javaArguments)
	
	# SSL
	cd('/Server/' + adminServerName)
	print 'Create SSL'
	create(adminServerName, 'SSL')
	cd('SSL/' + adminServerName)
	print ('. Set SSL Enabled to: ' + useSSL)
	set('Enabled', useSSL)
	if useSSL == "true":
		print ('. Set SSL ListenPort to: ' + str(sslPort))
		set('ListenPort', int(sslPort))
		set('TwoWaySSLEnabled', 'true')
		set('ClientCertificateEnforced', 'false')
	
	set('HostNameVerificationIgnored', 'True')
	
	#
	if jsseEnabled == 'true':
		print ('. Set JSSEEnabled to: ' + 'True')
		set('JSSEEnabled', 'True')
	else:
		print ('. Set JSSEEnabled to: ' + 'False')
		set('JSSEEnabled', 'False')
	cd('/Server/' + adminServerName)
	print ('. Set Max Message Size For Server: ' + adminServerName + ' value: ' + str(MAX_MSG_SIZE))
	set('MaxMessageSize', int(MAX_MSG_SIZE))



def createBaseDomain():
	print ('\nCreate base wls domain with template ' + wlsjar)
	print (lineSeperator)
	readTemplate(wlsjar)
	
	#
	cd('/')
	# Domain Log
	print('Set base_domain log')
	create('base_domain', 'Log')
	setLogProperties('/Log/base_domain')
	
	#
	# Admin Server
	changeAdminServer(ADMINSERVER_NAME, ADMINSERVER_LISTENADDRESS, ADMINSERVER_PORT, ADMINSERVER_SSLENABLED, ADMINSERVER_SSL_PORT, ADMIN_JAVA_ARGS)
	createServerLog(ADMINSERVER_NAME)   
	#
	print('\nSet password in ' + '/Security/base_domain/User/weblogic')
	cd('/')
	cd('Security/base_domain/User/weblogic')
	# weblogic user name + password
	print('. Set Name to: ' + ADMIN_NAME)
	set('Name', ADMIN_NAME)
	cmo.setPassword(ADMIN_PASSWORD)
	#
	print('. Set ServerStartMode to: ' + SERVER_START_MODE)
	setOption('ServerStartMode', SERVER_START_MODE)
	#
	print('write Domain...')
	# write path + domain name
	writeDomain(soaDomainHome)
	closeTemplate()
	
	createLogDir(soaDomainHome + '/servers/' + ADMINSERVER_NAME)
	#
	es = encrypt(ADMIN_PASSWORD, soaDomainHome)
	#
	readDomain(soaDomainHome)
	#
	print('set Domain password for ' + DOMAIN_NAME) 
	cd('/SecurityConfiguration/' + DOMAIN_NAME)
	set('CredentialEncrypted', es)
	#
	print('Set nodemanager password')
	set('NodeManagerUsername', ADMIN_NAME )
	set('NodeManagerPasswordEncrypted', es )
	#
	print '\nChanging Embedded LDAP credentials'
	# change credentials of Embedded LDAP
	cd('/EmbeddedLDAP/' + DOMAIN_NAME)
	set('CredentialEncrypted', es)
	#
	cd('/')
	setOption( "AppDir", soaApplicationsHome )
	#
	print('Finished base domain.')

#
#
def main():
	try:

#=======================================================================================
# Section 1: Base Domain + Admin Server
#=======================================================================================
		#
		print (lineSeperator)
		print ('1. Create Base domain ' + DOMAIN_NAME)

		createBaseDomain()



#=======================================================================================
# Section 2: Templates
#=======================================================================================
		print('\n2. Extend Base domain with templates.')
		print (lineSeperator)
		print ('Adding Webservice template ' + wlservicetpl)
		addTemplate(wlservicetpl)
		# OSB
		print ('Adding OSB template ' + osbtpl)
		addTemplate(osbtpl)
		
		#
		print ('Adding ApplCore Template ' + applCoreTpl)
		addTemplate(applCoreTpl)
		# 
		dumpStack()
		print ('Finished templates')
	
	
#=======================================================================================
# Section 3: Change Datasources
#=======================================================================================
		print ('\n3. Change datasources')
		print 'Change datasource LocalScvTblDataSource'
		cd('/JDBCSystemResource/LocalSvcTblDataSource/JdbcResource/LocalSvcTblDataSource/JDBCDriverParams/NO_NAME_0')
		set('URL', SOA_REPO_DB_URL)
		set('PasswordEncrypted', SOA_REPO_STB_PWD)
		cd('Properties/NO_NAME_0/Property/user')
		set('Value', SOA_REPO_DB_USER_PREFIX + '_STB')
		#
		print ('Call getDatabaseDefaults which reads the service table')
		getDatabaseDefaults()    
		#
		changeDatasourceToXA('wlsbjmsrpDataSource')
		changeDatasourceToXA('OraSDPMDataSource')
		changeDatasourceToXA('SOADataSource')
		#
		print 'Finshed DataSources'
	
	
#=======================================================================================
# Section 4: Create UnixMachines, Clusters and Managed Servers
#=======================================================================================
		print ('\n4. Create UnixMachines, Clusters and Managed Servers')
		print (lineSeperator)
		cd('/')
		#
		
		for x in range(1, int(SERVER_COUNT)+1):
			MA_NAME           = globals()['MA'+str(x)+'_NAME']
			MA_ADDRESS        = globals()['MA'+str(x)+'_ADDRESS']
			MA_PORT           = globals()['MA'+str(x)+'_PORT']
			print('Machine Nmae: ' + MA_NAME + ', Address: ' + MA_ADDRESS + ', Port: ' + MA_PORT)

			createUnixMachine(MA_NAME, MA_ADDRESS, MA_PORT)

		#
		if int(SERVER_COUNT) > 0:
			addServerToMachine(ADMINSERVER_NAME, MA1_NAME)
		#
		cd('/')
		# OSB
		if int(SERVER_COUNT) > 0:
			createCluster(CLUSTER_NAME, CLUSTER_ADDRESS)

		for x in range(1, int(SERVER_COUNT)+1):
			MA_NAME           = globals()['MA'+str(x)+'_NAME']
			MA_ADDRESS        = globals()['MA'+str(x)+'_ADDRESS']
			MS_NAME           = globals()['MS'+str(x)+'_NAME']
			MS_PORT           = globals()['MS'+str(x)+'_PORT']
			MS_SSLENABLED     = globals()['MS'+str(x)+'_SSLENABLED']
			MS_SSL_PORT       = globals()['MS'+str(x)+'_SSL_PORT']
			print('Managed Server Name: ' + MS_NAME + ', Port: ' + MS_PORT + ', SSL: ' + MS_SSLENABLED + ', SSL Port: ' + MS_SSL_PORT)

			if x == 1:
				adaptManagedServer('osb_server1', MS_NAME, MA_ADDRESS, MS_PORT, CLUSTER_NAME, MA_NAME, MS_SSLENABLED, MS_SSL_PORT, OSB_JAVA_ARGS)
			else:                 
				createManagedServer(MS_NAME, MA_ADDRESS, MS_PORT, CLUSTER_NAME, MA_NAME, MS_SSLENABLED, MS_SSL_PORT, OSB_JAVA_ARGS)
			createLogDir(soaDomainHome + '/servers/' + MS_NAME)

		#
		print ('Finshed creating Machines, Clusters and ManagedServers')
	
	
	
#=======================================================================================
# Section 5: Add Servers to ServerGroups.
#=======================================================================================
		print ('\n5. Add Servers to ServerGroups')
		print (lineSeperator)
		cd('/')
		if int(SERVER_COUNT) > 0:
			print 'Add server groups ' + adminSvrGrpDesc + ' to ' + ADMINSERVER_NAME
			setServerGroups(ADMINSERVER_NAME, adminSvrGrp)
		else:
			print 'Add server groups ' + singlOsbSvrGrpDesc + ' to ' + ADMINSERVER_NAME
			setServerGroups(ADMINSERVER_NAME, singlOsbSvrGrp)
		#      
		# OSB
		for x in range(1, int(SERVER_COUNT)+1):
			MS_NAME = globals()['MS'+str(x)+'_NAME']
			print 'Add server group ' + osbSvrGrpDesc + ' to ' + MS_NAME
			setServerGroups(MS_NAME, osbSvrGrp)
		#
		print ('Finshed ServerGroups.')
		#
		updateDomain()
		closeDomain();
	
	
	
#=======================================================================================
# Section 6: Create boot properties files.
#=======================================================================================
		print ('\n6. Create boot properties files')
		print (lineSeperator)
		#
		createAdminStartupPropertiesFile(soaDomainHome + '/servers/' + ADMINSERVER_NAME + '/data/nodemanager', ADMIN_JAVA_ARGS)
		createBootPropertiesFile(soaDomainHome + '/servers/' + ADMINSERVER_NAME + '/security', 'boot.properties', ADMIN_NAME, ADMIN_PASSWORD)
		# create nodemanager password
		createBootPropertiesFile(soaDomainHome + '/config/nodemanager', 'nm_password.properties', ADMIN_NAME, ADMIN_PASSWORD)
		#
		# OSB
		for x in range(1, int(SERVER_COUNT)+1):
			MS_NAME = globals()['MS'+str(x)+'_NAME']
			createBootPropertiesFile(soaDomainHome + '/servers/' + MS_NAME + '/security', 'boot.properties', ADMIN_NAME, ADMIN_PASSWORD)
		#


		print ('\nFinished')
		#
		print('\nExiting...')
		exit()
	except NameError, e:
		print 'Apparently properties not set.'
		print "Please check the property: ", sys.exc_info()[0], sys.exc_info()[1]
		usage()
	except:
		apply(traceback.print_exception, sys.exc_info())
		stopEdit('y')
		exit(exitcode=1)

#call main()
main()
exit()
