Difference between revisions of "Libvirt-qpid"

From Libvirt Wiki
Jump to: navigation, search
 
(De-spam)
 
(7 intermediate revisions by 4 users not shown)
Line 7: Line 7:
 
  # service qpidd start
 
  # service qpidd start
  
 +
== Testing that it is running ==
 
We can check that it is running using ''qpid-tool'' and the list command
 
We can check that it is running using ''qpid-tool'' and the list command
  
Line 19: Line 20:
 
     com.redhat.libvirt:pool    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
 
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
  
Line 33: Line 34:
 
  try:
 
  try:
 
     broker = sess.addBroker('amqp://localhost:5672')
 
     broker = sess.addBroker('amqp://localhost:5672')
     print "Connection Success"
+
     print "Connection Success"
 
  except:
 
  except:
     print "Connection Failed"
+
     print "Connection Failed"
 
   
 
   
 
   
 
   
Line 52: Line 53:
 
  props = domain.getProperties()
 
  props = domain.getProperties()
 
  for prop in props:
 
  for prop in props:
     print "\t",prop
+
     print "\t",prop
 
   
 
   
 
  # Access a value of a property and print it  
 
  # Access a value of a property and print it  
Line 62: Line 63:
 
  meths = domain.getMethods()
 
  meths = domain.getMethods()
 
  for meth in meths:
 
  for meth in meths:
     print "\t",meth
+
     print "\t",meth
 
   
 
   
 
  # Ca method of the domain and print it  
 
  # Ca method of the domain and print it  
Line 77: Line 78:
 
  # Disconnect from the broker (otherwise we hang the terminal
 
  # Disconnect from the broker (otherwise we hang the terminal
 
  sess.delBroker(broker)
 
  sess.delBroker(broker)
 +
 +
== Relevant Links ==
 +
 +
https://cwiki.apache.org/qpid/qmf-python-console-tutorial.html

Latest revision as of 11:40, 25 November 2010

Installation

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
try:
    broker = sess.addBroker('amqp://localhost:5672')
    print "Connection Success"
except:
    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 domain.name


# 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
else:
    result = domain.create()
    print result

# Disconnect from the broker (otherwise we hang the terminal
sess.delBroker(broker)

Relevant Links

https://cwiki.apache.org/qpid/qmf-python-console-tutorial.html