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 Feb 08, 2015 — DevOps Expert

How To Use The CLI And API To Find All Applications Deployed To All Environments In A Specific Folder

DevOps

There are many possibilities for scripting with XL-Deploy.  XL-Deploy keeps a lot of information about the applications deployed in your environments.  With the CLI scripting tool that comes with XL-Deploy we can get access to this data, write custom reports, automate deployments and a host of other tasks.  As an example of some of the things that can be done to collect information out of XL-Deploy lets look at finding all of the applications deployed under an Environments folder.

Environments_FoldersXL-Deploy organizes environments in folders.  There can be many folders to organize an environment.  For each environment defined there can be several applications deployed.  XL-Deploy keeps track of all of the applications deployed to each environment.  We can create a script that can search through all of the environments to find all of the applications that match a given criteria.  Since this will be a CLI tool we can define some command line options to control the script.  For this script I will be defining the command line options as follows:Find a Deployed Application in a Folder.  Command line options are as follows:  --verbose -v  Debug mode  --folder -f   The folders to look in.  The 'Environments/' will be added  --app -a      A pattern to search for in the application nameTo implement the switching we can use the GNU getopt library.  I my script I have done this as follows:try:   optList, argList = getopt.getopt(sys.argv[1:], 'vf:a:', ['verbose', 'folder=', 'app='])except getopt.GetoptError, err:   help()   sys.exit(2)#End tryAfter the script collects the command line options.  We can search the XL-Deploy repository for applications that match our requirements for folders and application names as follows:depApp = repository.search("udm.DeployedApplication") for app in depApp:   if re.match( folder, app ) :      if re.search( appName, app ) :         theApp = repository.read(app)         name = re.sub("^.*/", "", app)         version = re.sub("^.*/", "", theApp.version)         print "------------------------------------------"         print "Application = " + name         print "Version     = " + version         print "Environment = " + theApp.environment         print "Deployeds:"         for deployed in theApp.deployeds :            print "   * " + deployed         # End for         print "------------------------------------------"         print " "      # End if   # End if# End forThe output of the final script is as follows:$cli.sh -q -f `pwd`/script.py -- --verbose --folder=Dev/TEST ------------------------------------------ Application = PetClinic-ear Version     = 1.0 Environment = Environments/Dev/TEST Deployeds: * Infrastructure/Dev/Appserver-1/JBoss/PetClinic ------------------------------------------------------------------------------------ Application = PetPortal Version     = 2.0 Environment = Environments/Dev/TEST Deployeds: * Infrastructure/Dev/Webserver-1/Apache/PetPortal-to-PetClinic-ProxyPass * Infrastructure/Dev/Webserver-1/TestRunner/Check-PetPortal-to-PetClinic-ProxyPass-Test * Infrastructure/Dev/Database-1/MySql/sql * Infrastructure/Dev/Appserver-1/JBoss/PetClinic-ds-on-jboss * Infrastructure/Dev/Webserver-1/TestRunner/Check-PetPortal-On-Webserver-Test * Infrastructure/Dev/Webserver-1/Apache/webContent * Infrastructure/Dev/Webserver-1/TestRunner/Check-PetClinic-On-Appserver-Test * Infrastructure/Dev/Appserver-1/JBoss/PetClinic-ear ------------------------------------------  The source code is available on github.  

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