PYTHON LIBVIRT DOMAIN CONFIGURATION
So in my last article I talked a little bit about using libvirt to start and stop QEMU domains.
In this article I would like to go over how domains are created. QEMU uses XML files for each domain configuration, and using libvirt we can access that data.
First off lets connect to our local running QEMU instance:
>>> import libvirt
>>> conn = libvirt.open('qemu:///system')
Next lets look for and link to a running domain:
CONSUMING JENKINS API USING PYTHON
Lately I’ve been using Jenkins as a central hub for automated task across multiple machines, think a central cron system with a slick web interface.
In a nutshell Jenkins CI is the leading open-source continuous integration server. Built with Java, it provides over 400 plugins to support building and testing virtually any project.
One thing that is very nice about Jenkins is the easy to use REST JSON API .
Since our Jenkins system is used internally I’ve allowed the anonymous user full read access, this allows our API read call operations in without the need to use an API KEY.
DIABLO III API
So I was doing a bit of research on a Diablo III API, and stumbled across this article: http://us.battle.net/d3/en/forum/topic/4877377752 It seems they are still in the early stages, but there is a Character Calculator API, and it is in JSON.
First off we need to load in our Python libraries:
>>> from urllib2 import urlopen
>>> from json import loads
We can make our request using common URL methods:
>>> res = urlopen('http://us.battle.net/d3/en/data/calculator/monk').read()
>>> monk = loads(res)
Now we are given a simple Python dictionary:
BYTES, NIBBLES, AND BITS IN PYTHON
Binary
Binary is nothing more than a base 2 numbering system using the numbers 0 and 1.
Bit
A Bit is merely a single number of either 1 and 0 within the binary.
Byte
A Byte consists of 8 bits. A byte containing all 0s will be the integer 0, while a byte containing all 1s will be the integer of 255.
Nibble
A Nibble consits of 4 bits. A nibble containing all 0s will be the iteger 0, while a nibble containing all 1s will be the integer 15 (very useful for hex numbers).
WORKING WITH LIBVIRT USING PYTHON
Today I decide to toy around with a KVM server we have running in house for testing. I started by using the libvirt Documentation, but it was very limited and I had to do some trial and error. I will go over a few basic things I learned using the libvirt Python module:
Normally we us virt-manager to connect to our KVM instances, and the authentication is tunnled over SSH (using SSH Keys) and QEMU . First things first I had to learn how to connect with the same method we used in virt-manager :
LINE EQUATIONS IN PYTHON
The other day I was playing with some Python challenges found on a popular sites, this challenge worked with xy coordinates on a 2D plane.
I wanted to show some of the code I wrote and how they work.
The Plane
Being the data is a tuple of x, y coordinates we will use the Cartesian Coordinate System .
I started my code off as a simple Python class:
class Line(object):
def __init__(self, data):
self.first, self.second = data
Using this Class I can input two points in a tuple like this: