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.

OvzCP#1: Introduction

Back then at #nlcX final round, which was held at the same place as the NSC competition. (National software competition) I plan to enter the next NSC competition so I take a look around for some project idea.

First, I got my own highly innovative idea from my Twitter timeline, I saw a tweet and got a really cool idea about game that runs on Palm webOS. This is very hard to create as I have to learn many new technology and how I can create that game in short time. But when NSC result announced I, standing next to the stage sweared that next year I will do a control panel for @whsgroup.

Back then at #nlcX final round, which was held at the same place as the NSC competition. (National software competition) I plan to enter the next NSC competition so I take a look around for some project idea.

First, I got my own highly innovative idea from my Twitter timeline, I saw a tweet and got a really cool idea about game that runs on Palm webOS. This is very hard to create as I have to learn many new technology and how I can create that game in short time. But when NSC result announced I, standing next to the stage sweared that next year I will do a control panel for @whsgroup. (The winner in student software category is web hosting control from iberrystudio, congrats!)

Why I announce it so loud without fearing other will copy it? Because I have a year of OpenVZ experience and setup on hand. From what I saw OpenVZ is not easy to learn and it’s slightly complicated I don’t think anyone else can make a paravirtualization control panel in time for the contest.

Now on to the story, I have been coding OvzCP for a week now and the basic feature is almost complete except of creating and destroying the virtual machine. The blurry screenshot can be see at the front page of whsgroup.ath.cx (that’s the creation page)

One of the feature of OvzCP is automated Varnish control. Back then, whsgroup.ath.cx’s varnish (reverse proxy) use my hand-written configuration. I use complicated regular expression (like ^(t|os|whs).whsgroup.ath.cx$ because I’m lazy to write many elseifs. Now, OvzCP have come to automated my configuration.

Porting my old configuration is painless. I don’t use many varnish feature such as caching (as this is both development and production environment) so I just write a importer like this:

from models import *
import openvz
for i in openvz.listVM():
if not VM.select(VM.q.veid == i.veid).count():
owner = “manatsawin@gmail.com”
if i.veid == 105:
owner = None
VM(veid=i.veid, owner=owner)
vm = VM.select()
whs=VarnishBackend(name=”whs”, port=80, vm=vm[1])
glo=VarnishBackend(name=”global”, port=80, vm=vm[0])
VarnishCond(hostname=”whs.whsgroup.ath.cx”, varnishBackend=whs)
VarnishCond(hostname=”whsgroup.ath.cx”, subdomain=False, varnishBackend=glo)

(Varnish have backend definition, and vcl_recv condition. OvzCP frontend doesn’t display backend configuration but merge both backend and condition in one easy to configure display while never make duplicate or orphan backend)

Then just run that file. Now my old configuration got imported in. Then I will order OvzCP to regenerate varnish configuration by running varnish.py. It will restart varnish automatically.

I think OvzCP’s API is quite easy to learn but the code isn’t. Currently it’s about 650 lines of Python code and some shell script (for port forwarding) sloccount estimated that I have done 1.5 person-month already. (Note that I don’t use don’t repeat yourself philosophy and copy-pasting whenever I feel suitable)

OvzCP probably be open-sourced during the NSC competition. I hope to finish writing it by the next month. Of course, since I use every project I created I will see many issue while using my software and I will always improve it.

**PS.** I think I really need a new theme for my blog!