OvzCP#3: OpenVZ API

One of my design goal for OvzCP is to write a OpenVZ abstraction API but not a complete abstraction, just only what OvzCP use.

When I think about getting a number (such as memory available) from OpenVZ, an idea poped in my mind about using getter/setter so I modelled the API that way.

This is how you would get and set current disk space in OvzCP’s API.

import openvz

vm=openvz.VM(101)
print vm.diskinfo # return [total, used, free]

vm.diskinfo = 1024 * 1000 # Set available VM space to 1GB

(Note: currently getter/setter aren’t cached but seems that OvzCP’s f

One of my design goal for OvzCP is to write a OpenVZ abstraction API but not a complete abstraction, just only what OvzCP use.

When I think about getting a number (such as memory available) from OpenVZ, an idea poped in my mind about using getter/setter so I modelled the API that way.

This is how you would get and set current disk space in OvzCP’s API.

import openvz

vm=openvz.VM(101)
print vm.diskinfo # return [total, used, free]

vm.diskinfo = 1024 * 1000 # Set available VM space to 1GB

(Note: currently getter/setter aren’t cached but seems that OvzCP’s first page is served about 60 req/s according to Apache benchmark)

OvzCP#2: Billing

Hi, this is the second chapter of engineering OvzCP.

One of OvzCP’s goal is that it should be “hosting” control panel so it must have billing system while allow me to use for free.

First, I think that the user should be billed monthly with the amount they use, but seems that if user reduce the amount at the last day of month, they will be billed less than normal. I think about this for about 2 days and got the idea: game-like credit system.

I just commited this feature in. It took me about an hour to make it.

Hi, this is the second chapter of engineering OvzCP.

One of OvzCP’s goal is that it should be “hosting” control panel so it must have billing system while allow me to use for free.

First, I think that the user should be billed monthly with the amount they use, but seems that if user reduce the amount at the last day of month, they will be billed less than normal. I think about this for about 2 days and got the idea: game-like credit system.

I just commited this feature in. It took me about an hour to make it. Each VM will consume credit depending on memory and disk space setup in each cron run. If a user reached zero credit all VM that’s running will be stopped. Also, when a user have less than 100 credit he can’t start any more VM.

That solution seems to be great, but some user think it make they hard to calculate time left until credit runs out. I remedy this by value one real-world currency to many credit that equal to the amount of minutes in a month so if VM’s billing said they need 200 credit to run this VM per minute, they will pay 200 in real world.

(Note: Credit per real world currency rate can be adjusted in the configuration. The only number that’s hard coded here is 100 credit requirement to start VM)

With this feature online, I now run OvzCP as one of system’s daemon now. Of course, my credit is 1 trillion (1×1012) and it will be depleted in about 350199 days.