Simple Domain Creation – Offline

def createDomain():

    selectTemplate('Base WebLogic Server Domain')
    loadTemplates()
    cd('Servers/AdminServer')
    set('ListenAddress','')
    set('ListenPort', 7001)
    create('AdminServer','SSL')
    cd('SSL/AdminServer')
    set('Enabled', 'True')
    set('ListenPort', 7002)
    cd('/')
    cd('Security/base_domain/User/'+'AdminUserName')
    cmo.setPassword('AdminPassword')
    # Overwrite the domain If the domain already exists
    setOption('OverwriteDomain', 'true')
    # write the domain and close the template
    writeDomain('/domains/mydomain')
    closeTemplate()
    exit()
       
    
    
def main():

     createDomain()
    
if __name__ == "__main__":
    print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    print("SCRIPT BEING RUN DIRECTLY")
    print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    main()
else:
    print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    print("SCRIPT IS BEING IMPORTED IN ANOTHER MODULE AND THEN EXECUTED")
    print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    main()
  

 A Bit Advanced Domain Creation – Offline – More than 1 template

def createDomain():
    # Select the Basic WebLogic domain template
    selectTemplate('Base WebLogic Server Domain')
    # Now select template for WebLogic Advanced Web Services for JAX-RPC Extension
    selectTemplate('WebLogic Advanced Web Services for JAX-RPC Extension')
    loadTemplates()
    cd('Servers/AdminServer')
    set('ListenAddress','')
    set('ListenPort', 7001)
    create('AdminServer','SSL')
    cd('SSL/AdminServer')
    set('Enabled', 'True')
    set('ListenPort', 7002)
    cd('/')
    userName='Weblogic'
    cd('Security/base_domain/User/'+userName)
    cmo.setPassword('password')
    # Overwrite the domain If the domain already exists
    setOption('OverwriteDomain', 'true')
    # write the domain and close the template
    writeDomain('/domains/mydomain')
    closeTemplate()
    exit()

def main():

     createDomain()
    
if __name__ == "__main__":
    print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    print("SCRIPT BEING RUN DIRECTLY")
    print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    main()
else:
    print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    print("SCRIPT IS BEING IMPORTED IN ANOTHER MODULE AND THEN EXECUTED")
    print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    main()
    

Create Domain Remotely (12c) – This basically replaces pack & unpack pain…

def createDomainTemplate():
    
    ''' Generate  the template locally '''
    connect('weblogic','Adm1n31267','uv1267.emea.eu.int:1810')
    templateLocation ='/u01/tmp/wls-domain-template.jar'
    print ("Writing Template...")
    writeTemplate(templateLocation)
    print ("Writing Template...: DONE")
    disconnect()
    
def createDomain(templateLocation):
     
     readTemplate(templateLocation)
    
     ''' For 12.2.1 use,
        selectCustomTemplate('templateLocation')  
        loadTemplates() 
     '''
        
     domainPath='/u01/tmp/domains/my-test-domain'
     print ("Creating domain...")
     writeDomain (domainPath)
     closeTemplate()
     print ("Creating domain...: DONE")
       
       
def main():

     createDomainTemplate()
     templateLocation ='/u01/tmp/wls-domain-template.jar'
     createDomain(templateLocation)
    
if __name__ == "__main__":
    print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    print("SCRIPT BEING RUN DIRECTLY")
    print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    main()
else:
    print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    print("SCRIPT IS BEING IMPORTED IN ANOTHER MODULE AND THEN EXECUTED")
    print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    main()