Automated provisioning in an LXD/LXC server virtualization solution using API

I like instant coffee. Why? Because its “instant”! No waiting around. Fast feels good, especially when it comes to using services such as telephone services, web hosting, etc. For instance, in VPS hosting, customers now expect their accounts to be provisioned as soon as they place an order. To make this possible, VPS providers are now increasingly turning to automated provisioning solutions.

Provisioning a new VPS includes installing various applications based on the VPS plan, optimizing them and securing the server. This is a time-consuming process, if done manually. Recently when we helped a customer build a competitive VPS hosting service using LXC containers, we automated these tasks for quick provisioning.

To automate provisioning of VPS instances in our server virtualization solution, we used LXC API. The API allowed creation of a portal for customers to quickly deploy new VPS accounts, manage those accounts and scale them up easily. The major features we automated using the portal included VPS creation, management, backups, scaling up and stats.

Automated provisioning via Customer portal

VPS creation

Using the customer portal, users could quickly create VPS instances for the plans they ordered. Whenever a new order was placed, the billing portal processed it and enabled the user to create a VPS corresponding to his plan. The ‘create container’ function was executed by the ‘Create’ button in the portal, with the parameters such as the VPS name, plan, configuration etc.

The script would test the configuration settings of the new container and start it. The newly created VPS was then listed in the user’s account. The following snippet shows that a new VPS named ‘Ubuntu-04’ was created successfully.

Managing the VPSs

To provide users with the ability to start and stop their VPSs, we configured functions in the customer portal, using the following parameters.

{
'action': "stop", # State change action (stop, start, restart, freeze or unfreeze)
'timeout': 30, # A timeout after which the state change is considered as failed
'force': true # Force the state change (currently only valid for stop and restart where it means killing the container)
}

VPS backups

VPS backups are maintained in the form of snapshots of the containers. The container backup (aka ‘snapshot’) contained all the information of the container at any moment. Using this snapshot, we could restore the container at a later stage.

Our backup script was configured to stop each container at off-peak hours, take its snapshot, start the container and verify its running fine. The backups were labelled with appropriate identifiers and copied over to our external backup server for redundancy.

{
'name': "Ubuntu-01-snap0", # Name of the snapshot
'stateful': true # Whether to include state too
}

The ‘Backups’ feature was also provided with options for users to configure automatic VPS backups on a daily, weekly and monthly basis.

Along with the above features, users were also given option to ‘scale’ up their VPS instances to add more resources such as storage, IP address, network, memory etc. ‘Reports’ tab gave summary reports of the VPS performance and resource usage to users over a period of time.