Skip to main content
DevOps icon showing cogs

This post is from the XebiaLabs blog and has not been updated since the original publish date.

Last Updated Oct 26, 2015 — DevOps Expert

Creating an XL Deploy CLI Extension

DevOps

In the newer versions of XL Deploy (5.x) there is a new feature that allows you to put the XL Deploy server in maintenance mode. This allows you to prevent users from making changes to the repository while the administrators are trying to work with the repository or to cleanly restart the server. One of our customers noticed that we did not have a CLI way to put the XL Deploy server in maintenance mode. That seemed inconvenient, so in this blog I'm going to show you how to extend the XL Deploy CLI with a new object that will provide all of the ServerService methods from the REST API in the CLI.

Just like the XL Deploy server, the XL Deploy CLI has a few ways it can be extended. If you start writing CLI scripts that get complicated, they well become longer. You will likely want to start breaking these CLI scripts up into smaller parts or modules. The CLI tool is an implementation of Jython with extensions for XL Deploy. You can use this fact to create modules that can be reused to make your scripts more powerful. To figure out where you can put your custom modules in the CLI, start the CLI and do the following:admin > import sys admin > sys.path PyList: ['/opt/xebialabs/xl-deploy-5.0.1-cli/lib/Lib', '/opt/xebialabs/xl-deploy-5.0.1-cli/lib/jython-standalone-2.5.3.jar/Lib', '__classpath__', '__pyclasspath__/'] admin >  This is the list of places the CLI is looking for modules. To check this out let's make a custom module. Since I like pizza I'm going to make a little Pizza class and put it in a Pizza (Pizza.py) module as follows: class Pizza:   def __init__(self, size, toppings = []):      self.size = size      self.toppings = toppings   def getSize(self):      return self.size   def setSize( self, size ):      self.size = size   def addToppings( self, topping ):      self.toppings.append( topping )   def getToppings( self ):      return self.toppings   def listToppings( self ):      for topping in self.toppings:          print topping      # End foreach# End Class  We will save this module file in /opt/xebialabs/xl-deploy-5.0.1-cli/lib/Lib/Pizza.py. Now when we run the CLI, this module will be available to us. We can see how that might work as follows:admin > import Pizza admin > p = Pizza.Pizza( 12, ["peperoni", "mushrooms", "sausage", "cheese", "green peper", "onion"] ) admin > print p.getSize() 12 admin > p.listToppings() peperoni mushrooms sausage cheese green peper onion admin >  That is the first way you can extend the XL Deploy CLI. Another interesting way of extending the CLI is to put scripts in the ext folder. This is the use case that I was initially interested in. When we start the CLI there are several objects that are loaded to allow the CLI to interact with the XL Deploy server. When you start the CLI you can get a list of these objects by running the help() command as follows:admin > help() XL Deploy Objects available on the CLI:* deployit: The main gateway to interfacing with XL Deploy. * deployment: Perform tasks related to setting up deployments * factory: Helper that can construct Configuration Items (CI) and Artifacts * repository: Gateway to doing CRUD operations on all types of CIs * security: Access to the security settings of XL Deploy. * task2: Access to the task block engine of XL Deploy. * tasks: Access to the task engine of XL Deploy. !Deprecated! Use task2 instead.To know more about a specific object, type .help() To get to know more about a specific method of an object, type .help("")admin >  This is useful, but we are missing the serverService object from the REST API. Instead of building a REST client in my scripts, I want this to be a part of my CLI. To do this we can create another module with a new ServerService class and create an instance of that class that will be available to all of our scripts.  The source code for this module is available on Gist.  With this file saved in our ext folder we can start the CLI and interact with the serverService object just like other XL Deploy objects in the CLI.  Some examples of how we can use this module are as follows:admin > serverService.help() * state * shutdown * maintenanceStop * maintenanceStart * licenseReload * info * gcadmin > serverService.maintenanceStop()RUNNINGadmin > serverService.help() * state * shutdown * maintenanceStop * maintenanceStart * licenseReload * info * gcadmin > serverService.help("maintenanceStart")Put server into MAINTENANCE mode (prepare for shutdown).admin > serverService.maintenanceStart()MAINTENANCEadmin > serverService.state()MAINTENANCEadmin > serverService.maintenanceStop()RUNNINGadmin >  There are plenty of possibilities for customizing the CLI with these techniques.  XebiaLabs develops enterprise-scale Continuous Delivery and DevOps software, providing companies with the visibility, automation and control to deliver software faster and with less risk. Learn how… 

More from the Blog

View more
Ascension Launch Banner
Apr 26, 2022

Get ready for peak performance with Digital.ai’s newest AI-Powered DevOps Platform Ascension Release

DevOps
Today, Digital.ai is excited to announce our latest AI-Powered DevOps ...
Read More
Jan 24, 2022

Digital.ai Value Stream Delivery for SAFe®: The key to amazing business outcomes

DevOps
The Scaled Agile Framework (SAFe) is the world’s leading framework for ...
Read More
Dec 09, 2021

How SaaS and cloud-based solutions helped the U.S. Department of Veterans Affairs achieve digital transformation

DevOps
Modernizing legacy systems was an ongoing goal for the U.S. Department ...
Read More
Nov 29, 2021

Increase velocity and reduce risk with AI and machine learning

DevOps
Artificial Intelligence (AI) and machine learning (ML) have proven use ...
Read More
Contact Us