Posts about programming, code, and languages.
At my last job I was asked to consolidate and automate the de-provisioning of enterprise infrastructure, primarily Virtual Machines. I believe that web apps are the way of the future, so I decided to achieve this feat with a “simple” Django application, but considering the requirements (listed below), it would be anything but simple.
- Authenticate users against Active Directory
- Live search VMware vSphere for Virtual Machines
- Automatically remove user-specified VMs
- Clean up records of deleted VMs in other systems
- Allow additional tasks to be added at a later date
- Allow users to search for in-progress and completed decommissions
- Have a full-featured API
- Be fast
- Python 3.6
- Django Rest Framework
- Django Channels
Here’s a quick run down of functionality:
The user is authenticated against AD via a custom Django Authentication Backend. The backend also checks that the authenticated user has permission to modify certain objects in vSphere.
The primary purpose of the application is to allow users to build “Decommission Requests”. A Decommission Request is composed of one or more VMs and associated options. Users can search vCenter for VMs to add to the Request. For safety checks, the application will display additional information about the VM including the machine’s IP Address and Operating System.
After submitting the request, the application will queue the Decommission Request and redirect the user to the “Your Requests” page.
Decommissions are dequeued and performed by Task Workers which are additional python processes that run in a different container. By default, five workers are spawned per Worker container, but this value can be modified with environment variables and the Worker container can be scaled up seamlessly.
A single worker can decommission one VM at a time, so if there are few enough VMs in a Decommission Request, all VMs can be decommissioned concurrently. Decommissions are built and executed as a series of steps that is dependent on what OS the VM is running.
As a Worker process is executing a decommission, the status of that decommission is displayed, live, on the UI via WebSockets. If there are warnings or errors during a step, these are also displayed.
At any time, a user can immediately cancel a decommission, but steps that have already been performed are not rolled back.