Last Updated May 18, 2015 — DevOps Expert
DevOps

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

USE CASE

Our use case is to create an environment and add the infrastructure to that environmentEnvironment(to be created) Id Environments/myEnvInfrastructure (Existing ) NameInfrastructure/windows/server1Infrastructure (Existing ) NameInfrastructure/windowsCredentials : admin/admin

ABOUT

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).
 

Using REST API 

URL : http://192.168.1.10:4516/deployit/repository/ci/Environments/myEnv

Method : POST
Headers :  authorization:Basic YWRtaW46YWRtaW4= and content-type:application/xml
Body :
   
     
     
   
   
   
 
Output :
 
   
   
 
 
 

 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"

Using CLI Scripting

member1 = repository.read("Infrastructure/windows/server1")member2 = repository.read("Infrastructure/windows")env = factory.configurationItem("Environments/myEnv", "udm.Environment")newMembers = [member1.id, member2.id]env.members = newMembersrepository.create(env)print str(env.id) + "Created" 

Where to Try each of the options

 For REST API :

  • 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
  • Finally, you can make these connections through html/javascript,  java or any other language to setup dashboards, perform tasks on both pc and mobile.

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

For Jython Scripting :

Are you ready to scale your enterprise?

Explore

What's New In The World of Digital.ai

August 4, 2023

Why Financial Services Need DevSecOps More Than Ever

With Digital.ai DevSecOps solutions, financial organizations can improve their security posture, meet regulatory requirements and focus on delivering innovative financial products.

Learn More
June 23, 2023

Governance and Compliance for DevOps at Scale

Implement a Software Chain of Custody in DevOps for compliance, traceability, and cost reduction. Gain visibility and automate processes with Digital.ai Release & Deploy.

Learn More
April 10, 2023

Continuous Delivery Implementation Done Right: Learn from National Broadband Ireland Story

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.

Learn More