Sparkler: A KVM based virtual machine monitor
Welcome to Sparkler, a virtual machine monitor and a tiny "operating system" to go with it. When you start Sparkler, it creates a virtual machine using the Linux's KVM API. It is written in C and emulates the following devices:
- Console: This is the serial console via which the VM can read the keyboard and write to the screen
- Twitter device: Reads the latest tweet from Command Line Magic's Twitter account
- Weather device: Fetches the weather for a few cities
- Air Quality device: Fetches the air quality readings for a few cities
Accompanying article
Please read this companion article for details on how Sparkler works.
Sparkler architecture
Building
Please install GCC and NASM packages for your Linux distribution before you build. Change into the Sparkler directory and type "make". That's all there is to it.
Running
Just run ./sparkler
and that should start a Sparkler VM. You can then play around with the options the VM presents. Some distributions need the user to be part of a kvm
group if you want to run this as a regular user. Else just prefix the command with sudo
.
A sample Sparkler session
The Sparkler web service
Although we use libcurl
to fetch content off the internet and use json-parser
to parse JSON, doing this is a real pain from C. This is very apparent if youโre like me and youโve for exposed to the simplicity of handling this kind of stuff with higher-level languages. And so, I wrote a quick-and-dirty Sparkler Web Service that outputs JSON that is easily parsable from C. Also, it lets you try out Sparkler in its full glory without you first having to register for a Twitter developer account for you to access the Twitter API, to be able to fetch the tweet. This NodeJS service runs on the excellent Heroku platform for free. You can check out some JSON it outputs by clicking on these links here:
As you can see, Iโve made output from these different APIs structurally similar while removing a whole lot of JSON data weโll never use. This lets us handle this with C fairly easily. When the monitor program requests for information from the sparkler
program, it makes a request to the web service, parses that information and returns it to the monitor program.