def main(): mode = False properties = False try: opts, args = getopt.getopt(sys.argv[1:], 'p:m:', ['properties=','mode=']) except getopt.GetoptError: pass # print('argv: ', sys.argv[1:]) # print('opts: ', opts) try: for opt, arg in opts: if opt in ('-p', '--properties'): if os.path.isfile(arg): properties = arg elif opt in ('-m', '--mode'): mode = arg except NameError: pass if not properties or not mode in ('offline', 'online'): print('modify-wls-domain.py -p <path-to-properties-file> -m [offline|online]') sys.exit(1) # print('properties:', properties) # print('mode :', mode) pars_base = lib.ConfigParserClass(file_value=properties, keys_value=KEYS_VALUE, section_value=SECTION_VALUE_BASE) settings_base = pars_base.settings if not settings_base: print('Error: %s' % settings_base) sys.exit(1) for key in settings_base: domain_name = settings_base[key]['domain_name'] admin_name = settings_base[key]['admin_name'] admin_listen_port = int(settings_base[key]['admin_listen_port']) production_mode = settings_base[key]['production_mode'] administration_port_enabled = settings_base[key]['administration_port_enabled'] administration_port = int(settings_base[key]['administration_port']) admin_console_enabled = settings_base[key]['admin_console_enabled'] pars_sec = lib.ConfigParserClass(file_value=properties, keys_value=KEYS_VALUE, section_value=SECTION_VALUE_SEC) settings_sec = pars_sec.settings if not settings_sec: print('Error: %s' % settings_sec) sys.exit(1) for key in settings_sec: username = settings_sec[key]['username'] password = settings_sec[key]['password'] domain_path = '/u01/oracle/user_projects/domains/%s' % domain_name # domain_template = '/u01/oracle/wlserver/common/templates/wls/wls.jar' print(lib.bcolors.BOLD + 'domain_name : [%s]' % domain_name + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'admin_name : [%s]' % admin_name + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'admin_listen_port : [%s]' % admin_listen_port + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'production_mode : [%s]' % production_mode + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'administration_port_enabled : [%s]' % administration_port_enabled + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'administration_port : [%s]' % administration_port + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'admin_console_enabled : [%s]' % admin_console_enabled + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'username : [%s]' % "******" + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'password : [%s]' % "******" + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'domain_path : [%s]' % domain_path + lib.bcolors.ENDC) # print(lib.bcolors.BOLD + 'domain_template : [%s]' % domain_template + lib.bcolors.ENDC) lib.check_value(domain_name, "domain_name") lib.check_value(admin_name, "admin_name") lib.check_value(admin_listen_port, "admin_listen_port") lib.check_value(production_mode, "production_mode") lib.check_value(administration_port_enabled, "administration_port_enabled") lib.check_value(administration_port, "administration_port") lib.check_value(admin_console_enabled, "admin_console_enabled") lib.check_value(username, "username") lib.check_value(password, "password") lib.check_value(domain_path, "domain_path") # lib.check_value(domain_template, "domain_template") admin_url = 't3://localhost:' + str(admin_listen_port) # if administration_port_enabled == 'false': # admin_url = 't3://localhost:' + str(admin_listen_port) # else: # admin_url = 't3s://localhost:' + str(administration_port) pars_dep = lib.ConfigParserClass(file_value=properties, keys_value=KEYS_VALUE, section_value=SECTION_VALUE_DEP) settings_dep = pars_dep.settings if not settings_dep: print('Error: %s' % settings_dep) sys.exit(1) try: if mode == 'offline': readDomain(domain_path) for key in settings_dep: app_name = settings_dep[key]['name'] app_type = settings_dep[key]['type'] app_sourcePath = settings_dep[key]['sourcePath'] app_securityDDModel = settings_dep[key]['securityDDModel'] print(lib.bcolors.BOLD + 'app_name : [%s]' % app_name + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'app_type : [%s]' % app_type + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'app_sourcePath : [%s]' % app_sourcePath + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'app_securityDDModel : [%s]' % app_securityDDModel + lib.bcolors.ENDC) lib.check_value(app_name, "app_name") lib.check_value(app_type, "app_type") lib.check_value(app_sourcePath, "app_sourcePath") lib.check_value(app_securityDDModel, "app_securityDDModel") if not os.path.isfile(app_sourcePath): print('Error: not found %s' % app_sourcePath) sys.exit(1) print(lib.bcolors.WARNING + 'Offline deploy application : [%s]' % app_name + lib.bcolors.ENDC) # https://github.com/oracle/docker-images/blob/master/OracleWebLogic/samples/12212-oradb-wlsstore/container-scripts/app-deploy.py # https://github.com/oracle/docker-images/blob/master/OracleWebLogic/samples/12212-msiserver/container-scripts/add-app-to-domain.py # https://github.com/oracle/docker-images/blob/master/OracleWebLogic/samples/12213-deploy-application/container-scripts/app-deploy.py cd('/') app = create(app_name, app_type) app.setSourcePath(app_sourcePath) app.setSecurityDDModel(app_securityDDModel) app.setStagingMode('nostage') assign(app_type, app_name, 'Target', admin_name) # assign(app_type, app_name, 'Target', cluster_name) updateDomain() closeDomain() if mode == 'online': # WLST Offline - AdministrationPort disable if lib.check_bool(administration_port_enabled): readDomain(domain_path) cd('/') cmo.setAdministrationPortEnabled(false) # cmo.setAdministrationPortEnabled(true) updateDomain() closeDomain() # WLST Online - Deploy application startServer(adminServerName=admin_name, domainName=domain_name, url=admin_url, username=username, password=password, domainDir=domain_path, jvmArgs='-Xms512m -Xmx512m') connect(username, password, admin_url) edit() startEdit() for key in settings_dep: app_name = settings_dep[key]['name'] app_type = settings_dep[key]['type'] app_sourcePath = settings_dep[key]['sourcePath'] app_securityDDModel = settings_dep[key]['securityDDModel'] print(lib.bcolors.BOLD + 'app_name : [%s]' % app_name + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'app_type : [%s]' % app_type + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'app_sourcePath : [%s]' % app_sourcePath + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'app_securityDDModel : [%s]' % app_securityDDModel + lib.bcolors.ENDC) lib.check_value(app_name, "app_name") lib.check_value(app_type, "app_type") lib.check_value(app_sourcePath, "app_sourcePath") lib.check_value(app_securityDDModel, "app_securityDDModel") if not os.path.isfile(app_sourcePath): print('Error: not found %s' % app_sourcePath) sys.exit(1) print(lib.bcolors.WARNING + 'Online deploy application : [%s]' % app_name + lib.bcolors.ENDC) if str(app_type).lower() == 'library': progress = deploy(app_name, app_sourcePath, targets=admin_name, stageMode='nostage', libraryModule='true', securityModel=app_securityDDModel, upload='true') progress.printStatus() else: progress = deploy(app_name, app_sourcePath, targets=admin_name, stageMode='nostage', libraryModule='false', securityModel=app_securityDDModel, upload='true') progress.printStatus() save() activate(block='true') shutdown(block = 'true') disconnect() # WLST Offline - AdministrationPort enable if lib.check_bool(administration_port_enabled): readDomain(domain_path) cd('/') # cmo.setAdministrationPortEnabled(false) cmo.setAdministrationPortEnabled(true) updateDomain() closeDomain() except Exception, ex: # print ex.toString() print('Error: %s' % ex) dumpStack() cancelEdit('y') sys.exit(1)
def main(): properties = False try: opts, args = getopt.getopt(sys.argv[1:], 'p:', ['properties=']) except getopt.GetoptError: pass # print('argv: ', sys.argv[1:]) # print('opts: ', opts) try: for opt, arg in opts: if opt in ('-p', '--properties'): if os.path.isfile(arg): properties = arg except NameError: pass if not properties: print('modify-wls-domain.py -p <path-to-properties-file>') sys.exit(1) # print('properties:', properties) pars_base = lib.ConfigParserClass(file_value=properties, keys_value=KEYS_VALUE, section_value=SECTION_VALUE_BASE) settings_base = pars_base.settings if not settings_base: print('Error: %s' % settings_base) sys.exit(1) for key in settings_base: domain_name = settings_base[key]['domain_name'] admin_name = settings_base[key]['admin_name'] admin_listen_port = int(settings_base[key]['admin_listen_port']) production_mode = settings_base[key]['production_mode'] administration_port_enabled = settings_base[key][ 'administration_port_enabled'] administration_port = int(settings_base[key]['administration_port']) admin_console_enabled = settings_base[key]['admin_console_enabled'] pars_sec = lib.ConfigParserClass(file_value=properties, keys_value=KEYS_VALUE, section_value=SECTION_VALUE_SEC) settings_sec = pars_sec.settings if not settings_sec: print('Error: %s' % settings_sec) sys.exit(1) for key in settings_sec: username = settings_sec[key]['username'] password = settings_sec[key]['password'] domain_path = '/u01/oracle/user_projects/domains/%s' % domain_name # domain_template = '/u01/oracle/wlserver/common/templates/wls/wls.jar' print(lib.bcolors.BOLD + 'domain_name : [%s]' % domain_name + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'admin_name : [%s]' % admin_name + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'admin_listen_port : [%s]' % admin_listen_port + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'production_mode : [%s]' % production_mode + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'administration_port_enabled : [%s]' % administration_port_enabled + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'administration_port : [%s]' % administration_port + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'admin_console_enabled : [%s]' % admin_console_enabled + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'username : [%s]' % "******" + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'password : [%s]' % "******" + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'domain_path : [%s]' % domain_path + lib.bcolors.ENDC) # print(lib.bcolors.BOLD + 'domain_template : [%s]' % domain_template + lib.bcolors.ENDC) lib.check_value(domain_name, "domain_name") lib.check_value(admin_name, "admin_name") lib.check_value(admin_listen_port, "admin_listen_port") lib.check_value(production_mode, "production_mode") lib.check_value(administration_port_enabled, "administration_port_enabled") lib.check_value(administration_port, "administration_port") lib.check_value(admin_console_enabled, "admin_console_enabled") lib.check_value(username, "username") lib.check_value(password, "password") lib.check_value(domain_path, "domain_path") # lib.check_value(domain_template, "domain_template") # admin_url = 't3://localhost:' + str(admin_listen_port) if administration_port_enabled == 'false': admin_url = 't3://localhost:' + str(admin_listen_port) else: admin_url = 't3s://localhost:' + str(administration_port) try: # WLST Offline - AdministrationPort disable # if lib.check_bool(administration_port_enabled): # readDomain(domain_path) # cd('/') # cmo.setAdministrationPortEnabled(false) # # cmo.setAdministrationPortEnabled(true) # updateDomain() # closeDomain() connect(username, password, admin_url, adminServerName=admin_name) shutdown('AdminServer', 'Server', ignoreSessions='true') disconnect() # WLST Offline - AdministrationPort enable # if lib.check_bool(administration_port_enabled): # readDomain(domain_path) # cd('/') # # cmo.setAdministrationPortEnabled(false) # cmo.setAdministrationPortEnabled(true) # updateDomain() # closeDomain() except Exception, ex: # print ex.toString() print('Error: %s' % ex) dumpStack() cancelEdit('y') sys.exit(1)
def main(): mode = False properties = False try: opts, args = getopt.getopt(sys.argv[1:], 'p:m:', ['properties=', 'mode=']) except getopt.GetoptError: pass # print('argv: ', sys.argv[1:]) # print('opts: ', opts) try: for opt, arg in opts: if opt in ('-p', '--properties'): if os.path.isfile(arg): properties = arg elif opt in ('-m', '--mode'): mode = arg except NameError: pass if not properties or not mode in ('offline', 'online'): print( 'modify-wls-domain.py -p <path-to-properties-file> -m [offline|online]' ) sys.exit(1) # print('properties:', properties) # print('mode :', mode) pars_base = lib.ConfigParserClass(file_value=properties, keys_value=KEYS_VALUE, section_value=SECTION_VALUE_BASE) settings_base = pars_base.settings if not settings_base: print('Error: %s' % settings_base) sys.exit(1) for key in settings_base: domain_name = settings_base[key]['domain_name'] admin_name = settings_base[key]['admin_name'] admin_listen_port = int(settings_base[key]['admin_listen_port']) production_mode = settings_base[key]['production_mode'] administration_port_enabled = settings_base[key][ 'administration_port_enabled'] administration_port = int(settings_base[key]['administration_port']) admin_console_enabled = settings_base[key]['admin_console_enabled'] pars_sec = lib.ConfigParserClass(file_value=properties, keys_value=KEYS_VALUE, section_value=SECTION_VALUE_SEC) settings_sec = pars_sec.settings if not settings_sec: print('Error: %s' % settings_sec) sys.exit(1) for key in settings_sec: username = settings_sec[key]['username'] password = settings_sec[key]['password'] domain_path = '/u01/oracle/user_projects/domains/%s' % domain_name # domain_template = '/u01/oracle/wlserver/common/templates/wls/wls.jar' print(lib.bcolors.BOLD + 'domain_name : [%s]' % domain_name + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'admin_name : [%s]' % admin_name + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'admin_listen_port : [%s]' % admin_listen_port + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'production_mode : [%s]' % production_mode + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'administration_port_enabled : [%s]' % administration_port_enabled + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'administration_port : [%s]' % administration_port + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'admin_console_enabled : [%s]' % admin_console_enabled + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'username : [%s]' % "******" + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'password : [%s]' % "******" + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'domain_path : [%s]' % domain_path + lib.bcolors.ENDC) # print(lib.bcolors.BOLD + 'domain_template : [%s]' % domain_template + lib.bcolors.ENDC) lib.check_value(domain_name, "domain_name") lib.check_value(admin_name, "admin_name") lib.check_value(admin_listen_port, "admin_listen_port") lib.check_value(production_mode, "production_mode") lib.check_value(administration_port_enabled, "administration_port_enabled") lib.check_value(administration_port, "administration_port") lib.check_value(admin_console_enabled, "admin_console_enabled") lib.check_value(username, "username") lib.check_value(password, "password") lib.check_value(domain_path, "domain_path") # lib.check_value(domain_template, "domain_template") admin_url = 't3://localhost:' + str(admin_listen_port) # if administration_port_enabled == 'false': # admin_url = 't3://localhost:' + str(admin_listen_port) # else: # admin_url = 't3s://localhost:' + str(administration_port) pars_ds = lib.ConfigParserClass(file_value=properties, keys_value=KEYS_VALUE, section_value=SECTION_VALUE_DS) settings_ds = pars_ds.settings if not settings_ds: print('Error: %s' % settings_ds) sys.exit(1) try: if mode == 'offline': readDomain(domain_path) for key in settings_ds: ds_url = settings_ds[key]['url'] ds_user = settings_ds[key]['user'] ds_password = settings_ds[key]['password'] ds_Name = settings_ds[key]['Name'] ds_jndiName = settings_ds[key]['jndiName'] ds_GlobalTransactionsProtocol = settings_ds[key][ 'GlobalTransactionsProtocol'] ds_driver = settings_ds[key]['driver'] ds_MaxCapacity = settings_ds[key]['MaxCapacity'] ds_ConnectionCreationRetryFrequencySeconds = settings_ds[key][ 'ConnectionCreationRetryFrequencySeconds'] ds_TestTableName = settings_ds[key]['TestTableName'] ds_XaSetTransactionTimeout = settings_ds[key][ 'XaSetTransactionTimeout'] ds_XaTransactionTimeout = settings_ds[key][ 'XaTransactionTimeout'] print(lib.bcolors.BOLD + 'ds_url : [%s]' % ds_url + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_user : [%s]' % "******" + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_password : [%s]' % "******" + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_Name : [%s]' % ds_Name + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_jndiName : [%s]' % ds_jndiName + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_GlobalTransactionsProtocol : [%s]' % ds_GlobalTransactionsProtocol + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_driver : [%s]' % ds_driver + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_MaxCapacity : [%s]' % ds_MaxCapacity + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_ConnectionCreationRetryFrequencySeconds : [%s]' % ds_ConnectionCreationRetryFrequencySeconds + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_TestTableName : [%s]' % ds_TestTableName + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_XaSetTransactionTimeout : [%s]' % ds_XaSetTransactionTimeout + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_XaTransactionTimeout : [%s]' % ds_XaTransactionTimeout + lib.bcolors.ENDC) lib.check_value(ds_url, "ds_url") lib.check_value(ds_user, "ds_user") lib.check_value(ds_password, "ds_password") lib.check_value(ds_Name, "ds_Name") lib.check_value(ds_jndiName, "ds_jndiName") lib.check_value(ds_GlobalTransactionsProtocol, "ds_GlobalTransactionsProtocol") lib.check_value(ds_driver, "ds_driver") lib.check_value(ds_MaxCapacity, "ds_MaxCapacity") lib.check_value(ds_ConnectionCreationRetryFrequencySeconds, "ds_ConnectionCreationRetryFrequencySeconds") lib.check_value(ds_TestTableName, "ds_TestTableName") lib.check_value(ds_XaSetTransactionTimeout, "ds_XaSetTransactionTimeout") lib.check_value(ds_XaTransactionTimeout, "ds_XaTransactionTimeout") print(lib.bcolors.WARNING + 'Offline create datasource : [%s]' % ds_Name + lib.bcolors.ENDC) cd('/') create(ds_Name, 'JDBCSystemResource') cd('/JDBCSystemResource/' + ds_Name + '/JdbcResource/' + ds_Name) set('Name', ds_Name) cd('/JDBCSystemResource/' + ds_Name + '/JdbcResource/' + ds_Name) create(ds_Name + '_ds_params', 'JDBCDataSourceParams') cd('/JDBCSystemResource/' + ds_Name + '/JdbcResource/' + ds_Name + '/JDBCDataSourceParams/' + 'NO_NAME_0') set('JNDIName', ds_jndiName) if lib.check_bool(ds_GlobalTransactionsProtocol): cd('/JDBCSystemResource/' + ds_Name + '/JdbcResource/' + ds_Name + '/JDBCDataSourceParams/' + 'NO_NAME_0') set('GlobalTransactionsProtocol', ds_GlobalTransactionsProtocol) cd('/JDBCSystemResource/' + ds_Name + '/JdbcResource/' + ds_Name) create(ds_Name + '_driver_params', 'JDBCDriverParams') cd('/JDBCSystemResource/' + ds_Name + '/JdbcResource/' + ds_Name + '/JDBCDriverParams/' + 'NO_NAME_0') set('URL', ds_url) set('DriverName', ds_driver) set('PasswordEncrypted', ds_password) cd('/JDBCSystemResource/' + ds_Name + '/JdbcResource/' + ds_Name + '/JDBCDriverParams/' + 'NO_NAME_0') create(ds_Name + '_driver_props', 'Properties') cd('/JDBCSystemResource/' + ds_Name + '/JdbcResource/' + ds_Name + '/JDBCDriverParams/' + 'NO_NAME_0' + '/Properties/' + 'NO_NAME_0') create('user', 'Property') cd('/JDBCSystemResource/' + ds_Name + '/JdbcResource/' + ds_Name + '/JDBCDriverParams/' + 'NO_NAME_0' + '/Properties/' + 'NO_NAME_0' + '/Property/' + 'user') set('Value', ds_user) if lib.check_bool(ds_TestTableName) or lib.check_bool( ds_MaxCapacity) or lib.check_bool( ds_ConnectionCreationRetryFrequencySeconds): cd('/JDBCSystemResource/' + ds_Name + '/JdbcResource/' + ds_Name) create(ds_Name + '_conn_pool_params', 'JDBCConnectionPoolParams') if lib.check_bool(ds_TestTableName): cd('/JDBCSystemResource/' + ds_Name + '/JdbcResource/' + ds_Name + '/JDBCConnectionPoolParams/' + 'NO_NAME_0') set('TestTableName', ds_TestTableName) if lib.check_bool(ds_MaxCapacity): cd('/JDBCSystemResource/' + ds_Name + '/JdbcResource/' + ds_Name + '/JDBCConnectionPoolParams/' + 'NO_NAME_0') set('MaxCapacity', int(ds_MaxCapacity)) if lib.check_bool(ds_ConnectionCreationRetryFrequencySeconds): cd('/JDBCSystemResource/' + ds_Name + '/JdbcResource/' + ds_Name + '/JDBCConnectionPoolParams/' + 'NO_NAME_0') set('ConnectionCreationRetryFrequencySeconds', int(ds_ConnectionCreationRetryFrequencySeconds)) if lib.check_bool(ds_XaSetTransactionTimeout ) or lib.check_bool(ds_XaTransactionTimeout): cd('/JDBCSystemResource/' + ds_Name + '/JdbcResource/' + ds_Name) create(ds_Name + '_xa_params', 'JDBCXAParams') if lib.check_bool(ds_XaSetTransactionTimeout): cd('/JDBCSystemResource/' + ds_Name + '/JdbcResource/' + ds_Name + '/JDBCXAParams/' + 'NO_NAME_0') set('XaSetTransactionTimeout', ds_XaSetTransactionTimeout) if lib.check_bool(ds_XaTransactionTimeout): cd('/JDBCSystemResource/' + ds_Name + '/JdbcResource/' + ds_Name + '/JDBCXAParams/' + 'NO_NAME_0') set('XaTransactionTimeout', int(ds_XaTransactionTimeout)) assign('JDBCSystemResource', ds_Name, 'Target', admin_name) updateDomain() closeDomain() if mode == 'online': # WLST Offline - AdministrationPort disable if lib.check_bool(administration_port_enabled): readDomain(domain_path) cd('/') cmo.setAdministrationPortEnabled(false) # cmo.setAdministrationPortEnabled(true) updateDomain() closeDomain() # WLST Online - Deploy application startServer(adminServerName=admin_name, domainName=domain_name, url=admin_url, username=username, password=password, domainDir=domain_path, jvmArgs='-Xms512m -Xmx512m') connect(username, password, admin_url) edit() startEdit() for key in settings_ds: ds_url = settings_ds[key]['url'] ds_user = settings_ds[key]['user'] ds_password = settings_ds[key]['password'] ds_Name = settings_ds[key]['Name'] ds_jndiName = settings_ds[key]['jndiName'] ds_GlobalTransactionsProtocol = settings_ds[key][ 'GlobalTransactionsProtocol'] ds_driver = settings_ds[key]['driver'] ds_MaxCapacity = settings_ds[key]['MaxCapacity'] ds_ConnectionCreationRetryFrequencySeconds = settings_ds[key][ 'ConnectionCreationRetryFrequencySeconds'] ds_TestTableName = settings_ds[key]['TestTableName'] ds_XaSetTransactionTimeout = settings_ds[key][ 'XaSetTransactionTimeout'] ds_XaTransactionTimeout = settings_ds[key][ 'XaTransactionTimeout'] print(lib.bcolors.BOLD + 'ds_url : [%s]' % ds_url + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_user : [%s]' % "******" + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_password : [%s]' % "******" + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_Name : [%s]' % ds_Name + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_jndiName : [%s]' % ds_jndiName + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_GlobalTransactionsProtocol : [%s]' % ds_GlobalTransactionsProtocol + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_driver : [%s]' % ds_driver + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_MaxCapacity : [%s]' % ds_MaxCapacity + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_ConnectionCreationRetryFrequencySeconds : [%s]' % ds_ConnectionCreationRetryFrequencySeconds + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_TestTableName : [%s]' % ds_TestTableName + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_XaSetTransactionTimeout : [%s]' % ds_XaSetTransactionTimeout + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'ds_XaTransactionTimeout : [%s]' % ds_XaTransactionTimeout + lib.bcolors.ENDC) lib.check_value(ds_url, "ds_url") lib.check_value(ds_user, "ds_user") lib.check_value(ds_password, "ds_password") lib.check_value(ds_Name, "ds_Name") lib.check_value(ds_jndiName, "ds_jndiName") lib.check_value(ds_GlobalTransactionsProtocol, "ds_GlobalTransactionsProtocol") lib.check_value(ds_driver, "ds_driver") lib.check_value(ds_MaxCapacity, "ds_MaxCapacity") lib.check_value(ds_ConnectionCreationRetryFrequencySeconds, "ds_ConnectionCreationRetryFrequencySeconds") lib.check_value(ds_TestTableName, "ds_TestTableName") lib.check_value(ds_XaSetTransactionTimeout, "ds_XaSetTransactionTimeout") lib.check_value(ds_XaTransactionTimeout, "ds_XaTransactionTimeout") print(lib.bcolors.WARNING + 'Online create datasource : [%s]' % ds_Name + lib.bcolors.ENDC) cd('/') cmo.createJDBCSystemResource(ds_Name) cd('/JDBCSystemResources/' + ds_Name + '/JDBCResource/' + ds_Name) cmo.setName(ds_Name) cd('/JDBCSystemResources/' + ds_Name + '/JDBCResource/' + ds_Name + '/JDBCDataSourceParams/' + ds_Name) cmo.setJNDINames(jarray.array([String(ds_jndiName)], String)) if lib.check_bool(ds_GlobalTransactionsProtocol): cd('/JDBCSystemResources/' + ds_Name + '/JDBCResource/' + ds_Name + '/JDBCDataSourceParams/' + ds_Name) cmo.setGlobalTransactionsProtocol( ds_GlobalTransactionsProtocol) cd('/JDBCSystemResources/' + ds_Name + '/JDBCResource/' + ds_Name + '/JDBCDriverParams/' + ds_Name) cmo.setUrl(ds_url) cmo.setDriverName(ds_driver) cmo.setPassword(ds_password) cd('/JDBCSystemResources/' + ds_Name + '/JDBCResource/' + ds_Name + '/JDBCDriverParams/' + ds_Name + '/Properties/' + ds_Name) cmo.createProperty('user') cd('/JDBCSystemResources/' + ds_Name + '/JDBCResource/' + ds_Name + '/JDBCDriverParams/' + ds_Name + '/Properties/' + ds_Name + '/Properties/user') cmo.setValue(ds_user) if lib.check_bool(ds_TestTableName): cd('/JDBCSystemResources/' + ds_Name + '/JDBCResource/' + ds_Name + '/JDBCConnectionPoolParams/' + ds_Name) cmo.setTestTableName(ds_TestTableName) if lib.check_bool(ds_MaxCapacity): cd('/JDBCSystemResources/' + ds_Name + '/JDBCResource/' + ds_Name + '/JDBCConnectionPoolParams/' + ds_Name) cmo.setMaxCapacity(int(ds_MaxCapacity)) if lib.check_bool(ds_ConnectionCreationRetryFrequencySeconds): cd('/JDBCSystemResources/' + ds_Name + '/JDBCResource/' + ds_Name + '/JDBCConnectionPoolParams/' + ds_Name) cmo.setConnectionCreationRetryFrequencySeconds( int(ds_ConnectionCreationRetryFrequencySeconds)) if lib.check_bool(ds_XaSetTransactionTimeout): cd('/JDBCSystemResources/' + ds_Name + '/JDBCResource/' + ds_Name + '/JDBCXAParams/' + ds_Name) cmo.setXaSetTransactionTimeout(True) if lib.check_bool(ds_XaTransactionTimeout): cd('/JDBCSystemResources/' + ds_Name + '/JDBCResource/' + ds_Name + '/JDBCXAParams/' + ds_Name) cmo.setXaTransactionTimeout(int(ds_XaTransactionTimeout)) cd('/SystemResources/' + ds_Name) # set('Targets',jarray.array([ObjectName('com.bea:Name=' + cluster_name + ',Type=Cluster')], ObjectName)) set( 'Targets', jarray.array([ ObjectName('com.bea:Name=' + admin_name + ',Type=Server') ], ObjectName)) save() activate(block='true') shutdown(block='true') disconnect() # WLST Offline - AdministrationPort enable if lib.check_bool(administration_port_enabled): readDomain(domain_path) cd('/') # cmo.setAdministrationPortEnabled(false) cmo.setAdministrationPortEnabled(true) updateDomain() closeDomain() except Exception, ex: # print ex.toString() print('Error: %s' % ex) dumpStack() cancelEdit('y') sys.exit(1)
def main(): cid = False properties = False try: opts, args = getopt.getopt(sys.argv[1:], 'p:c:', ['properties=','cid=']) except getopt.GetoptError: pass # print('argv: ', sys.argv[1:]) # print('opts: ', opts) try: for opt, arg in opts: if opt in ('-p', '--properties'): if os.path.isfile(arg): properties = arg elif opt in ('-c', '--cid'): cid = arg except NameError: pass if not cid or not properties: print('modify-wls-domain.py -p <path-to-properties-file> -c 123456789abc') sys.exit(1) # print('properties:', properties) # print('cid :', cid) pars_base = lib.ConfigParserClass(file_value=properties, keys_value=KEYS_VALUE, section_value=SECTION_VALUE_BASE) settings_base = pars_base.settings if not settings_base: print('Error: %s' % settings_base) sys.exit(1) for key in settings_base: domain_name = settings_base[key]['domain_name'] admin_name = settings_base[key]['admin_name'] admin_listen_port = int(settings_base[key]['admin_listen_port']) production_mode = settings_base[key]['production_mode'] administration_port_enabled = settings_base[key]['administration_port_enabled'] administration_port = int(settings_base[key]['administration_port']) admin_console_enabled = settings_base[key]['admin_console_enabled'] pars_sec = lib.ConfigParserClass(file_value=properties, keys_value=KEYS_VALUE, section_value=SECTION_VALUE_SEC) settings_sec = pars_sec.settings if not settings_sec: print('Error: %s' % settings_sec) sys.exit(1) for key in settings_sec: username = settings_sec[key]['username'] password = settings_sec[key]['password'] domain_path = '/u01/oracle/user_projects/domains/%s' % domain_name # domain_template = '/u01/oracle/wlserver/common/templates/wls/wls.jar' print(lib.bcolors.BOLD + 'domain_name : [%s]' % domain_name + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'admin_name : [%s]' % admin_name + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'admin_listen_port : [%s]' % admin_listen_port + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'production_mode : [%s]' % production_mode + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'administration_port_enabled : [%s]' % administration_port_enabled + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'administration_port : [%s]' % administration_port + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'admin_console_enabled : [%s]' % admin_console_enabled + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'username : [%s]' % "******" + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'password : [%s]' % "******" + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'domain_path : [%s]' % domain_path + lib.bcolors.ENDC) # print(lib.bcolors.BOLD + 'domain_template : [%s]' % domain_template + lib.bcolors.ENDC) lib.check_value(domain_name, "domain_name") lib.check_value(admin_name, "admin_name") lib.check_value(admin_listen_port, "admin_listen_port") lib.check_value(production_mode, "production_mode") lib.check_value(administration_port_enabled, "administration_port_enabled") lib.check_value(administration_port, "administration_port") lib.check_value(admin_console_enabled, "admin_console_enabled") lib.check_value(username, "username") lib.check_value(password, "password") lib.check_value(domain_path, "domain_path") # lib.check_value(domain_template, "domain_template") admin_url = 't3://localhost:' + str(admin_listen_port) # if administration_port_enabled == 'false': # admin_url = 't3://localhost:' + str(admin_listen_port) # else: # admin_url = 't3s://localhost:' + str(administration_port) pars_log = lib.ConfigParserClass(file_value=properties, keys_value=KEYS_VALUE, section_value=SECTION_VALUE_LOG) settings_log = pars_log.settings if not settings_log: print('Error: %s' % settings_log) sys.exit(1) pars_sec_realm_authprov = lib.ConfigParserClass(file_value=properties, keys_value=KEYS_VALUE, section_value=SECTION_VALUE_SEC_REALM_AUTHPROV) settings_sec_realm_authprov = pars_sec_realm_authprov.settings if not settings_sec_realm_authprov: print('Error: %s' % settings_sec_realm_authprov) sys.exit(1) pars_sec_realm_rolemapp = lib.ConfigParserClass(file_value=properties, keys_value=KEYS_VALUE, section_value=SECTION_VALUE_SEC_REALM_ROLEMAPP) settings_sec_realm_rolemapp = pars_sec_realm_rolemapp.settings if not settings_sec_realm_rolemapp: print('Error: %s' % settings_sec_realm_rolemapp) sys.exit(1) try: # WLST Offline - AdministrationPort disable if lib.check_bool(administration_port_enabled): readDomain(domain_path) cd('/') cmo.setAdministrationPortEnabled(false) # cmo.setAdministrationPortEnabled(true) updateDomain() closeDomain() # WLST Online - Modify logging settings startServer(adminServerName=admin_name, domainName=domain_name, url=admin_url, username=username, password=password, domainDir=domain_path, jvmArgs='-Xms512m -Xmx512m') connect(username, password, admin_url) edit() startEdit() # print('Disable Admin Console') # cd('/') # cmo.setConsoleEnabled(false) for key in settings_log: log_path = settings_log[key]['path'] log_file = settings_log[key]['file'] log_fileMinSize = settings_log[key]['fileMinSize'] log_fileCount = settings_log[key]['fileCount'] log_rotateLogOnStartup = settings_log[key]['rotateLogOnStartup'] print(lib.bcolors.BOLD + 'log_path : [%s]' % log_path + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'log_file : [%s]' % log_file + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'log_fileMinSize : [%s]' % log_fileMinSize + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'log_fileCount : [%s]' % log_fileCount + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'log_rotateLogOnStartup : [%s]' % log_rotateLogOnStartup + lib.bcolors.ENDC) lib.check_value(log_path, "log_path") lib.check_value(log_file, "log_file") lib.check_value(log_fileMinSize, "log_fileMinSize") lib.check_value(log_fileCount, "log_fileCount") lib.check_value(log_rotateLogOnStartup, "log_rotateLogOnStartup") if key == 'domain': if log_path.lower() != ('/Log/' + domain_name).lower(): print('Error: The parameter [log.domain.path=%s] is incorrect! Exit!' % log_path) sys.exit(1) if key == 'diagnostic': log_file = log_file + '-' + str(cid) else: log_file = log_file.replace('.log', '-' + str(cid) + ".log") print(lib.bcolors.WARNING + 'Setup logging : [%s]' % log_file + lib.bcolors.ENDC) if key == 'diagnostic': cd(log_path) cmo.setImageDir(str(log_file)) # cmo.setImageTimeout(int(log_timeout)) else: cd(log_path) cmo.setFileName(str(log_file)) cmo.setRotateLogOnStartup(lib.check_bool(log_rotateLogOnStartup)) cmo.setFileCount(int(log_fileCount)) cmo.setFileMinSize(int(log_fileMinSize)) for key in settings_sec_realm_authprov: sec_realm_authprov_realm = settings_sec_realm_authprov[key]['realm'] sec_realm_authprov_name = settings_sec_realm_authprov[key]['name'] sec_realm_authprov_type = settings_sec_realm_authprov[key]['type'] sec_realm_authprov_ControlFlag = settings_sec_realm_authprov[key]['ControlFlag'] print(lib.bcolors.BOLD + 'sec_realm_authprov_realm : [%s]' % sec_realm_authprov_realm + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'sec_realm_authprov_name : [%s]' % sec_realm_authprov_name + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'sec_realm_authprov_type : [%s]' % sec_realm_authprov_type + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'sec_realm_authprov_ControlFlag : [%s]' % sec_realm_authprov_ControlFlag + lib.bcolors.ENDC) lib.check_value(sec_realm_authprov_realm, "sec_realm_authprov_realm") lib.check_value(sec_realm_authprov_name, "sec_realm_authprov_name") lib.check_value(sec_realm_authprov_type, "sec_realm_authprov_type") lib.check_value(sec_realm_authprov_ControlFlag, "sec_realm_authprov_ControlFlag") print(lib.bcolors.WARNING + 'Setup Security Realm Auth Providers : [%s]' % sec_realm_authprov_name + lib.bcolors.ENDC) if not sec_realm_authprov_name in ('DefaultAuthenticator', 'DefaultIdentityAsserter'): if lib.check_bool(sec_realm_authprov_name) and lib.check_bool(sec_realm_authprov_type): cd('/SecurityConfiguration/' + domain_name + '/Realms/' + sec_realm_authprov_realm) cmo.createAuthenticationProvider(sec_realm_authprov_name, sec_realm_authprov_type) if lib.check_bool(sec_realm_authprov_ControlFlag): cd('/SecurityConfiguration/' + domain_name + '/Realms/' + sec_realm_authprov_realm + '/AuthenticationProviders/' + sec_realm_authprov_name) cmo.setControlFlag(sec_realm_authprov_ControlFlag) else: if lib.check_bool(sec_realm_authprov_ControlFlag): cd('/SecurityConfiguration/' + domain_name + '/Realms/' + sec_realm_authprov_realm + '/AuthenticationProviders/' + sec_realm_authprov_name) cmo.setControlFlag(sec_realm_authprov_ControlFlag) for key in settings_sec_realm_rolemapp: sec_realm_rolemapp_realm = settings_sec_realm_rolemapp[key]['realm'] sec_realm_rolemapp_name = settings_sec_realm_rolemapp[key]['name'] sec_realm_rolemapp_type = settings_sec_realm_rolemapp[key]['type'] print(lib.bcolors.BOLD + 'sec_realm_rolemapp_realm : [%s]' % sec_realm_rolemapp_realm + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'sec_realm_rolemapp_name : [%s]' % sec_realm_rolemapp_name + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'sec_realm_rolemapp_type : [%s]' % sec_realm_rolemapp_type + lib.bcolors.ENDC) lib.check_value(sec_realm_rolemapp_realm, "sec_realm_rolemapp_realm") lib.check_value(sec_realm_rolemapp_name, "sec_realm_rolemapp_name") lib.check_value(sec_realm_rolemapp_type, "sec_realm_rolemapp_type") print(lib.bcolors.WARNING + 'Setup Security Realm Role Mapping : [%s]' % sec_realm_rolemapp_name + lib.bcolors.ENDC) # When you created new Role Mapper with type weblogic.security.providers.authorization.DefaultRoleMapper (as in this example),at weblogic startup there will be the following issue # <BEA-099503> <Evaluation of policy associated with role :Admin failed because the policy expression contains unregistered predicate: weblogic.entitlement.rules.AdministrativeGroup.> # Reason dublicated Global Roles in Home >myrealm >Providers >ExampleAuthenticator >Providers >ExampleRoleMapper >Summary of Deployments >Summary of JDBC Data Sources >Summary of Security Realms >myrealm >Realm Roles # This issue can be ignored (in test only). if not sec_realm_rolemapp_name in ('XACMLRoleMapper'): if lib.check_bool(sec_realm_rolemapp_name) and lib.check_bool(sec_realm_rolemapp_type): cd('/SecurityConfiguration/' + domain_name + '/Realms/' + sec_realm_authprov_realm) cmo.createRoleMapper(sec_realm_rolemapp_name, sec_realm_rolemapp_type) save() activate(block = 'true') shutdown(block = 'true') disconnect() # WLST Offline - AdministrationPort enable if lib.check_bool(administration_port_enabled): readDomain(domain_path) cd('/') # cmo.setAdministrationPortEnabled(false) cmo.setAdministrationPortEnabled(true) updateDomain() closeDomain() except Exception, ex: # print ex.toString() print('Error: %s' % ex) dumpStack() cancelEdit('y') sys.exit(1)
def main(): properties = False try: opts, args = getopt.getopt(sys.argv[1:], 'p:', ['properties=']) except getopt.GetoptError: pass # print('argv: ', sys.argv[1:]) # print('opts: ', opts) try: for opt, arg in opts: if opt in ('-p', '--properties'): if os.path.isfile(arg): properties = arg except NameError: pass if not properties: print('modify-wls-domain.py -p <path-to-properties-file>') sys.exit(1) # print('properties:', properties) pars_base = lib.ConfigParserClass(file_value=properties, keys_value=KEYS_VALUE, section_value=SECTION_VALUE_BASE) settings_base = pars_base.settings if not settings_base: print('Error: %s' % settings_base) sys.exit(1) for key in settings_base: domain_name = settings_base[key]['domain_name'] admin_name = settings_base[key]['admin_name'] admin_listen_port = int(settings_base[key]['admin_listen_port']) production_mode = settings_base[key]['production_mode'] administration_port_enabled = settings_base[key]['administration_port_enabled'] administration_port = int(settings_base[key]['administration_port']) admin_console_enabled = settings_base[key]['admin_console_enabled'] pars_sec = lib.ConfigParserClass(file_value=properties, keys_value=KEYS_VALUE, section_value=SECTION_VALUE_SEC) settings_sec = pars_sec.settings if not settings_sec: print('Error: %s' % settings_sec) sys.exit(1) for key in settings_sec: username = settings_sec[key]['username'] password = settings_sec[key]['password'] domain_path = '/u01/oracle/user_projects/domains/%s' % domain_name domain_template = '/u01/oracle/wlserver/common/templates/wls/wls.jar' print(lib.bcolors.BOLD + 'domain_name : [%s]' % domain_name + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'admin_name : [%s]' % admin_name + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'admin_listen_port : [%s]' % admin_listen_port + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'production_mode : [%s]' % production_mode + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'administration_port_enabled : [%s]' % administration_port_enabled + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'administration_port : [%s]' % administration_port + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'admin_console_enabled : [%s]' % admin_console_enabled + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'username : [%s]' % "******" + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'password : [%s]' % "******" + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'domain_path : [%s]' % domain_path + lib.bcolors.ENDC) print(lib.bcolors.BOLD + 'domain_template : [%s]' % domain_template + lib.bcolors.ENDC) lib.check_value(domain_name, "domain_name") lib.check_value(admin_name, "admin_name") lib.check_value(admin_listen_port, "admin_listen_port") lib.check_value(production_mode, "production_mode") lib.check_value(administration_port_enabled, "administration_port_enabled") lib.check_value(administration_port, "administration_port") lib.check_value(admin_console_enabled, "admin_console_enabled") lib.check_value(username, "username") lib.check_value(password, "password") lib.check_value(domain_path, "domain_path") lib.check_value(domain_template, "domain_template") try: # Open default domain template # ============================ readTemplate(domain_template) set('Name', domain_name) setOption('DomainName', domain_name) # Set Administration Port # ======================= if administration_port_enabled != "false": set('AdministrationPort', administration_port) set('AdministrationPortEnabled', 'true') # Disable Admin Console # -------------------- if admin_console_enabled != "true": cmo.setConsoleEnabled(false) # Configure the Administration Server and SSL port. # ================================================= cd('/Servers/AdminServer') set('Name', admin_name) set('ListenAddress', '') set('ListenPort', admin_listen_port) if administration_port_enabled != "false": create('AdminServer','SSL') cd('SSL/AdminServer') set('Enabled', 'True') # Define the user password for weblogic # ===================================== cd(('/Security/%s/User/weblogic') % domain_name) cmo.setName(username) cmo.setPassword(password) # Write the domain and close the domain template # ============================================== setOption('OverwriteDomain', 'true') setOption('ServerStartMode',production_mode) # Create Node Manager # =================== #cd('/NMProperties') #set('ListenAddress','') #set('ListenPort',5556) #set('CrashRecoveryEnabled', 'true') #set('NativeVersionEnabled', 'true') #set('StartScriptEnabled', 'false') #set('SecureListener', 'false') #set('LogLevel', 'FINEST') # Set the Node Manager user name and password # =========================================== #cd('/SecurityConfiguration/%s' % domain_name) #set('NodeManagerUsername', username) #set('NodeManagerPasswordEncrypted', password) # Write Domain # ============ writeDomain(domain_path) closeTemplate() # Exit WLST # ========= # exit() except Exception, ex: # print ex.toString() print('Error: %s' % ex) dumpStack() cancelEdit('y') sys.exit(1)