Monday, July 26, 2010

KVM configuration file example & explanation

1. KVM configuration file

KVM configuration file is normally placed under /etc/libvirt/qemu




osmgmt02
c533fb5c-71b7-2e4c-8b9a-7742ba3ada03
20971520
20971520
4

hvm








destroy
restart
restart

/usr/libexec/qemu-kvm





































Tuesday, July 20, 2010

Setting up a network bridge to enable NIC sharing between VM's in KVM

1. Configure a bridge device

Here we will setup a br1 device and have it connected to eth1 device.

a. Set up eth1

[root@nebskcc001 local]# cd /etc/sysconfig/network-scripts/
[root@nebskcc001 local]# vi ifcfg-eth1

DEVICE=eth1
BOOTPROTO=static
HWADDR=F4:CE:46:87:D1:B6 # YOUR MAC ADDRESS MAY VARY
ONBOOT=yes
TYPE=Ethernet
IPV6INIT=no
BRIDGE=br1 # Bridge name to be connected to.


b. Set up br1

[root@nebskcc001 local]# vi ifcfg-br1

DEVICE=br1
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes



c. Restart the network service

[root@nebskcc001 local]# service network restart



2. Modify KVM configuration file.

a. change kvm configuration file.



Here we add the bridge device and have it used by the VM.
[root@nebskcc008 imgs]# cd /etc/libvirt/qemu
[root@nebskcc008 qemu]# vim bpm.xml



b. start vm.

Tuesday, July 13, 2010

Thrift Python Module Path Problem

By default, Thrift python module is installed under /usr/lib/python2.x/site-pacakges, if you went through the typical "./configure -> make -> make install" steps to install Thrift.

If your python cannot locate thrift module (e.g. you installed a newer version of Python like Python 2.7), you might add "export PYTHONPATH=/path/to/python/site-packages".

[tkang@neb005 py-impl]$ vi /etc/profile



# add following lines
export PYTHONPATH=/usr/lib/python2.7/site-packages

Thrift Server-Client in Python

1. Write Thrift stub code

[tkang@neb005 thrift]$ vi helloworld.thrift


const string HELLO_IN_KOREAN = "an-nyoung-ha-se-yo"
const string HELLO_IN_FRENCH = "bonjour!"
const string HELLO_IN_JAPANESE = "konichiwa!"

service HelloWorld {
void ping(),
i32 sayHello(),
i32 sayMsg(1:string msg)
}


2. Generate python code

[tkang@neb005 thrift]$ thrift --gen py helloworld.thrift

Generated codes will be saved under "gen-py" directory.
[tkang@neb005 thrift]$ ls
gen-py helloworld.thrift

3. Fill in Server code

[tkang@neb005 thrift]$ mkdir py-impl
[tkang@neb005 thrift]$ cd py-impl
[tkang@neb005 py-impl]$ vi PythonServer.py


#!/usr/bin/env python

import sys
sys.path.append('../gen-py')

from helloworld import HelloWorld
from helloworld.ttypes import *

from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer

import socket

class HelloWorldHandler:
def __init__(self):
self.log = {}

def ping(self):
print "ping()"

def sayHello(self):
print "sayHello()"
return "say hello from " + socket.gethostbyname(socket.gethostname())

def sayMsg(self, msg):
print "sayMsg(" + msg + ")"
return "say " + msg + " from " + socket.gethostbyname(socket.gethostname())

handler = HelloWorldHandler()
processor = HelloWorld.Processor(handler)
transport = TSocket.TServerSocket(30303)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()

server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)

print "Starting python server..."
server.serve()
print "done!"


4. Write Client code to connect to server

[tkang@neb005 py-impl]$ vi PythonClient.py


#!/usr/bin/env python

import sys
sys.path.append('../gen-py')

from helloworld import HelloWorld
from helloworld.ttypes import *
from helloworld.constants import *

from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

try:
# Make socket
transport = TSocket.TSocket('localhost', 30303)

# Buffering is critical. Raw sockets are very slow
transport = TTransport.TBufferedTransport(transport)

# Wrap in a protocol
protocol = TBinaryProtocol.TBinaryProtocol(transport)

# Create a client to use the protocol encoder
client = HelloWorld.Client(protocol)

# Connect!
transport.open()

client.ping()
print "ping()"

msg = client.sayHello()
print msg
msg = client.sayMsg(HELLO_IN_KOREAN)
print msg

transport.close()

except Thrift.TException, tx:
print "%s" % (tx.message)

Monday, July 12, 2010

Thrift Installation


1. Download Source
- Download Tar From : http://incubator.apache.org/thrift/download/


2. Install all the required components

- Install pkgs with yum
[root@neb005 thrift-0.2.0]# yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel

- Install autoconf version > 2.61 from : http://ftp.gnu.org/gnu/autoconf/autoconf-2.66.tar.gz

- build it and copy "libtool" binary to thrift build directory.

3. Install Thrift
- To install under /usr/local/thrift/
[root@localhost src]# gunzip thrift-0.2.0-incubating.tar.gz
[root@localhost src]# tar xvf thrift-0.2.0-incubating.tar
.....
[root@localhost src]# cd thrift-0.2.0
[root@neb005 thrift-0.2.0]# ./bootstrap.sh
[root@neb005 thrift-0.2.0]# ./configure
[root@neb005 thrift-0.2.0]# make
[root@neb005 thrift-0.2.0]# make install