XLD Scripting comparison : Jython vs REST API vs CLI
Last Updated May 18, 2015 — DevOps Expert
I bet all those of you working on XL Deploy for a while might feel overwhelmed by all those different ways you can interact with the server.
There is the GUI interface and then there’s CLI(Command Line Interface). Now if you want to go further, it has the REST API and last but not least, the latest addition of the Jython APIs (Server side scripting) that can be used for XL-Rules and for creation of custom REST Endpoints.
How about we do a comparison of Jython API vs REST API vs CLI tool. It would give you a fine comparison of how to do the same thing using different approaches. We can talk further about each one can be used
Our use case is to create an environment and add the infrastructure to that environmentEnvironment(to be created) Id : Environments/myEnvInfrastructure (Existing ) Name: Infrastructure/windows/server1Infrastructure (Existing ) Name: Infrastructure/windowsCredentials : admin/admin
CLI Scripting – It uses a custom java library and jython to interact with a target XLDeploy server. You can connect to any server as long you can access the server and you have login permissions(in security). You require knowledge of python to work your way with CLI. Objects returned from the server are converted to convenient python objects to work with simple python constructsREST API – This is the easiest interface to work with since its a standard and you can make direct calls through command line tools to connect to any target XLD Server. You can connect to any server as long you can access the server and you have login permissions(in security). It however becomes very tedious since if you are trying to do complex work, you would also have to deal with conversion of xml request/response. You require knowledge about basic usage on how to call REST Services in generalJython API – This is a server side scripting interface so this is definitely the fastest out of three in terms of execution, but it runs on the server itself so it can’t connect to different servers. Because of its server side nature, it carries pre-authenticated objects which hold a users security and permissions information. For this, you require good knowledge of python, working knowledge of jython/java(depending on use cases).
Headers : authorization:Basic YWRtaW46YWRtaW4= and content-type:application/xml
Using Jython API
from com.xebialabs.deployit.plugin.api.reflect import Typefrom java.util import HashSet# Read Membersmember1 = repositoryService.read("Infrastructure/windows/server1")member2 = repositoryService.read("Infrastructure/windows")# Add them to a new HashSet.. Use ._delegate to get a ConfigurationItem objectnewMembers = HashSet([member1._delegate, member2._delegate])# Create a new Environmenttype = Type.valueOf("udm.Environment")env = type.descriptor.newInstance("Environments/myEnv")# Use this to add individual members to environment #env.members.add(member1._delegate)# Add members to environmentenv.members = newMembers# Create environment in repositoryrepositoryService.create(env.id, env)print "Environment " + env.id + " Created"
The simplest way is to use a firefox extension called REST Client , set authorization and content-type headers and try it out
Another way is to use them using curl/wget in linux. You will have to set the user/password using respective flags and also set headers. You can put the body content in a file and pass that file with a suitable flag
Yet another way is to use python with Requests Library or any other http connection library to make connections
For CLI Scripting :
You can simply login in the CLI tool and start typing the commands
You may also put the lines in a file with extension .py. Then use the command line with the -f flag to execute the script
Through NBI’s approach to be the best open-access operator in telecom, they have been supported by key technology partners, with automation capabilities provided by Digital.ai Release and Deploy underpinning integral aspects.
Regardless of where you are on your digital transformation journey, we can help you achieve your strategic outcomes and accelerate value delivery with the right combination of technology, services, and training.