From Libvirt Wiki
Revision as of 00:09, 3 May 2009 by Goldfish (talk | contribs) (Installation)
Jump to: navigation, search


libvirt-qpid is currently available in Fedora 10 repositories so you can install it using yum

# yum -y install libvirt-qpid qpidd python-qpid
# chkconfig libvirt-qpid on
# chkconfig qpidd on
# service libvirt-qpid start
# service qpidd start

Testing that it is running

We can check that it is running using qpid-tool and the list command

# qpid-tool 
Management Tool for QPID
qpid: list
Management Object Types:
   ObjectType                 Active  Deleted
   com.redhat.libvirt:domain  6       0
   com.redhat.libvirt:node    1       0
   com.redhat.libvirt:pool    1       0

Simple cLient in python

Now that we have it running lets make a simple client to get information from it. To do this I use python. The following is a simple script that does some of the basics

#!/usr/bin/env python

from qmf.console import Session
from yaml import dump

sess = Session() # defaults to synchronous-only operation. It also defaults to user-management of connections. 

# attempt to connect to a broker
    broker = sess.addBroker('amqp://localhost:5672')
    print "Connection Success"
    print "Connection Failed"

domains = sess.getObjects(_class='domain', _package='com.redhat.libvirt.domain')

# Print a list of the domains
for d in domains:
    print d

# Select the first domain
domain = domains[0]

# Print a list of the properties of the domain
print 'Properties:'
props = domain.getProperties()
for prop in props:
    print "\t",prop

# Access a value of a property and print it 

# Print a list of the methods of the domain
print 'Methods:'
meths = domain.getMethods()
for meth in meths:
    print "\t",meth

# Ca method of the domain and print it 
xmldesc =  domain.getXMLDesc()

# Call another method of the domain and print the result
if domain.state == 'running':
    result = domain.shutdown()
    print result
    result = domain.create()
    print result

# Disconnect from the broker (otherwise we hang the terminal