In this learning and sharing today created a server using Jython script.
The basic needs to create a App Server in WebSphere environemnt is to have Node and it should be added to the Cell.
The script would perormed with the help of the NodeID to create the server. create is the simple command method on the AdminConfig object.
CreateServer.py
This above script has print statement that actually calling AdminConfig.create() method. As we have discussed in the previous post that a Jython function/method that has return statement that can be called in assignment, expression, or in a output statement liek print. In this case last option selected. Ofcourse this print is optional. now lets evaluate our script by executing as follows:
Validating the script configuration on the Admin console given me as follows:
The basic needs to create a App Server in WebSphere environemnt is to have Node and it should be added to the Cell.
The script would perormed with the help of the NodeID to create the server. create is the simple command method on the AdminConfig object.
CreateServer.py
import sys # import system libraries #interactive method, type server & node name servername=raw_input("Enter server name:") nodename=raw_input("Enter Node name:") # get the config id of the node print "getting config id of node .." nodeid=AdminConfig.getid('/Node:'+nodename+'/') # verify whether the entered node exist or not try : if nodeid=='': print "entered correct node", nodename except: print " the node does not exist, please enter a valid node" # get the config id of the node #print "getting config id of node .." #nodeid=AdminConfig.getid('/Node:'+nodename+'/') #define attributes like servername & etc print "defining attributes .." att=[['name' , servername]] print "creating servers .." print AdminConfig.create('Server' , nodeid , att ) print "saving config .." AdminConfig.save()
This above script has print statement that actually calling AdminConfig.create() method. As we have discussed in the previous post that a Jython function/method that has return statement that can be called in assignment, expression, or in a output statement liek print. In this case last option selected. Ofcourse this print is optional. now lets evaluate our script by executing as follows:
wsadmin>execfile('/home/krish/jython/createServer.py') Enter server name:server2 Enter Node name:AppSrvNode getting config id of node .. defining attributes .. creating servers .. server2(cells/DmgrCell05/nodes/AppSrvNode/servers/server2|server.xml#Server_1409381645239) saving config ..
Validation of Script
Validating the script configuration on the Admin console given me as follows: