Laur IVAN

Delete Executions in Rundeck – Wrapping it all Up

Posted by in IT, Software, Tutorial

The previous posts have built the components to allow us to get projects, jobs, executions and remove executions from a Rundeck instance via its API. Now, we can just wrap them up :) The list of packages we need is:

For convenience, I’ve declared a bunch of constants we can use throughout the project:

As we already have all the helper functions defined, we only need to wrap them in a convenient execution command:

The logis is fairly simple: Get the list of projects For each project,…read more

Remove Executions in Rundeck

Posted by in IT, Tutorial

TL;DR: You have to get the executions’ list and remove the appropriate ones using hte API. Once we’ve managed to get the list of job executions, we can use the API to remove the relevant executions. The command is rather simple:

This method requires: server – the Rundeck’s server address port – the port on which we can connect to the Rundeck server api_key – the API key execution_ids – an array of valid execution IDs The function will try to remove all execution IDs in one go, since…read more

List Rundeck Jobs for a Project

Posted by in IT, Software, Tutorial

Now that we Rundeck have a list of project names, we might want to see which jobs were created for each project. To do this, we need: The Rundeck instance’s address (server, port) The API key (api_key) A project’s name (project_name) First, we need to get the list of jobs for a project:

The result is also an XML, just like the one for the projects. Therefore, we need to parse it:

At the end of this exercise, we’ll have a list of job names (IDs). HTH, A…read more

List Rundeck Projects

Posted by in IT, Software, Tutorial

The other day I found out that Rundeck has an API which allows it to be controlled remotely by scripts. I’ve decided to write a script to list all the projects defined in a rundeck instance. Prerequisites Before you start, you need: The instance’s URL (server and port) An api key for the user Make sure the user has enough credentials to list the projects The code I’ve picked up Python as language for the task just because I’m more familiar with it in this context. Therefore, another dependency is…read more

Build Update Statements with Oracle SQL Developer and Python

Posted by in Software, Tutorial

By default, SQL Developer can only export INSERT statements. This is quite unfortunate when one needs to build UPDATE statements because their syntax is different. I’ve tried to use regexp to convert the statements but I didn’t find it not straight forward at all. So, I cam up with the following strategy: Export the data as JSON Use a python script (below) to write the statements The python script We first need to specify things like the DB Schema, table and the primary key:

Subsequently, I’ve defined a wrapper…read more

Initialise Python with GoCD

Posted by in IT, Tutorial

Following the deployment of a python-aware agent, we can start creating a pipeline. The first stage would be to: Clean up any previous data Create a virtual environment for python Install all dependencies from a requirements.txt file in our project Note: we assume the global pipeline settings and the Materials are properly set up (e.g. out project will be checked out in ./project). Since the above operations must be executed in order, I’ve set up a Setup stage with a job named virtualenv. The job has three tasks: rm virtualenv…read more

Create a Python-friendly GoCD Agent in Docker

Posted by in IT, Tutorial

I’ve got two requirements to make GoCD useful: Run both the server and agent(s) in Docker Make it python-friendly Fortunately, GoCD offers Docker images (and Dockerfiles) for both, so it’s just a matter of extending it:

Unfortunately, pip is not quite adequate, so we re-install it from source. In the Dockerfile we add:

Now we have a fully functional Docker file capable of building python applications and we can actually build the image. In the directory where we have the Dockerfile, execute:

Then, you can run it…read more

Handler for Global Logger in Python

Posted by in Software, Tutorial

While writing a command line tool, I’ve stumbled upon a strange situation: Some logs were written to a file while some others were printed to console. Quite annoying, particularly since every module I use has its own logger via logging.getLogger(__name__). After some investigation I found out you can access the global logger via logging.getLogger() (note the lack of parameters). So, my new setup is:

Simple. HTH, A little experiment: If you find this post and ad below useful, please check the ad out :-)

DRF: What is ‘source’ in Fields?

Posted by in Software, Tutorial

For a couple of days I’ve been trying to de-serialise a JSON to a model. My problem is the model and the JSON have different fields, mainly to keep the model pythonic and independent of a specific JSON source. So… I’ve been trying to use the source parameter for each Field in my serialiser to map to the JSON. E.g. if my Django Model field would be named timestamp and my JSON would be named time, I would have a serialiser Field like this:

THIS IS WRONG! It’s actually…read more

Timestamp to DateTime Serializer Field for DRF

Posted by in Software, Tutorial

I’m currently trying to deserialize JSON data to a Django model. This is quite straight forward for most numeric fields, but I have a DateTime field which is stored as a timestamp in the original JSON. At first, I thought I should read the timestamp as an integer and convert it through post-processing. Then, after reading more of the DRF docs, it became evident I needed a custom field. The code is below:

The idea is that to_representation converts a DateTime field into a timestamp value for serialisation and…read more