It is very easy to extend XL Deploy with Jython scripts. There many ways you can use Jython scripts to extend XL Deploy. Today I will demonstrate how you can use Jython to create a control task to check the filesystem of a host for the largest files. As an administrator it is frequently necessary to look for the largest files on a system and possibility remove unneeded ones.
To create our control task we need to define it in the synthetic.xml file as follows:
description="Look for biggest files on file system" task-description="Look for biggest files on file system" delegate="jython" script="custom/host/hog.py">
Lets examine what is happening in this snippet of synthetic.xml. The first thing I do is indicate I will be adding something to overthere.SshHosts. When this is done you will see a new option when you right click on a overthere.SshHost. The name of this new command is going to be “hog“. There are some other parameters to further define this new task and the location of the script. We can pass parameters to this task and these are defined with the parameter tag. XL Deploy supports a variety of parameter kinds. In this example I am using string and integer kinds. Next lets look at the Jython script.
1 import os
3 path = parameters["path"]
5 # Windows and linux slashes go in opposite directions.
6 # Uncomment the slash appropriate for your system.
7 systemslash= parameters["slash"]
10 maxfiles = parameters["maxfiles"]
11 def get_list_of_files(inDirectory, container=):
14 for entry in os.listdir(inDirectory):
15 entry = inDirectory+systemslash+entry
16 if os.path.isdir(entry):
19 filesize = os.path.getsize(entry)
20 fileandsize = (filesize, entry)
22 return container
23 # End for
26 # End try
27 # End def
29 Final_List_of_Files = get_list_of_files(path)
33 for obj in Final_List_of_Files:
34 context.logOutput("%12d - %s" % (obj, obj))
35 fileCount = fileCount + 1
36 if fileCount >= maxfiles:
38 # End for
This little script gets the parameters collected from the user in the GUI and passes them to the script. Notice lines 3, 7 & 10. This script gets called with a variable called “parameters” defined with all of the parameters we identified in our synthetic.xml file. With these two files defined in the XL Deploy ext folder we can now restart our XL Deploy server and see the new control task execute. Bellow is are two screen shots of the new control task as it appears in XL Deploy. Once the parameters are entered and the task is executed the output can be seen in the UI as follows: We could package our control task as a plugin as well. In order to package our control task we need to move all of our changes out of the ext folder. Then we need to replicate the files we created in another directory and add a plugin-version.properties file. For this plugin my file is as follows:
1 plugin=custom-hog-plugin 2 version=1.0.0
We can then zip the files as a jar file. The files in our jar file is as follows:
Archive: /tmp/custom-hog-plugin-1.0.0.jar testing: custom/ OK testing: custom/host/ OK testing: custom/host/hog.py OK testing: plugin-version.properties OK testing: synthetic.xml OK
Then we can copy the new plugin file to the XL Deploy plugin folder and restart the server. The hog control task is running as a plugin. Extending XL Deploy with Jython is very easy and flexible, your imagination is the the only limit on the ways XL Deploy and be extended with Jython. The little control task that I developed for this blog post is simple, but the techniques can be use for much more complicated tasks. The source code for this example is available on GitHub custom-hog-plugin
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.