Last Updated Oct 26, 2015 — DevOps Expert

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 ( 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/ 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 > * state * shutdown * maintenanceStop * maintenanceStart * licenseReload * info * gcadmin > serverService.maintenanceStop()RUNNINGadmin > * state * shutdown * maintenanceStop * maintenanceStart * licenseReload * info * gcadmin >"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… 

Are you ready to scale your enterprise?


What's New In The World of

August 4, 2023

Why Financial Services Need DevSecOps More Than Ever

With 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 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 Release and Deploy underpinning integral aspects.

Learn More