[Buildbot-devel] LibVirtSlave master snippets?

Neal Chant neal at ethermonkey.net
Wed Feb 23 18:29:00 UTC 2011


On Tue, 2011-02-22 at 22:51 +0100, Frank Marien wrote:

> Trying to use a libvirt buildslave..
> Not getting anywhere with the 2-line example in the docs..
> 
> I can instantiate a Connection object with the parameters found in the
> class docs, using the URL I used in virt-manager,
> that will make an ssh connection, just fine.
> 
> But filling it out as a parameter to the LibVirtSlave constructor
> (_init_) yields an assert.. as well as not using it at all.
> (I can't access the box from here.. no details until thursday)
> 
> My question: does anyone have a snippet of master config where you use
> LibVirtSlave. That would really help me..

Hi,

The below worked in 7.i_forget.

note, if you require instant off there is a timeout setting to change in
buildslave.py. build_wait_timeout

HTH
Neal

============================================================
from twisted.internet import defer, threads
from buildbot.buildslave import AbstractLatentBuildSlave
import libvirt

class VirshBuildSlave(AbstractLatentBuildSlave):
	#def __init__(self, name, password):
	#	self.virsh_name = name
	#	self.host_passwd = password

	#To use, subclass and implement start_instance and stop_instance.
	def start_instance(self):
	        return threads.deferToThread(self._start_instance)

    	def _start_instance(self):
        	# responsible for starting instance that will try to connect
with this
        	# master. Should return deferred. Problems should use an
errback. The
        	# callback value can be None, or can be an iterable of short
strings to
        	# include in the "substantiate success" status message, such as
        	# identifying the instance that started.
		conn = libvirt.open(None)
		if conn == None:
			raise NotImplementedError # Should really raise a better error
		try:
	        	host = conn.lookupByName(self.slavename)
		except:
			raise NotImplementedError # Should really raise a better error

		run_state = host.info()[0]
		
		# Start VM
		#if libvirt.VIR_DOMAIN_SHUTOFF == run_state:
		#	print "In _start_instance()"
		#	host.create() # create _is_ start

		# Resume VM
		if libvirt.VIR_DOMAIN_PAUSED == run_state:
			print "In _start_instance()"		
			host.resume() # resume _is_ take from suspended state

	def stop_instance(self, fast=False):
		return threads.deferToThread(
	            self._stop_instance, fast)
     
	def _stop_instance(self, fast=False):
        	# responsible for shutting down instance. Return a deferred. If
`fast`,
        	# we're trying to shut the master down, so callback as soon as
is safe.
        	# Callback value is ignored.
        	conn = libvirt.open(None)
		if conn == None:
			raise NotImplementedError # Should really raise a better error
		try:
	        	host = conn.lookupByName(self.slavename)
		except:
			raise NotImplementedError # Should really raise a better error

		# Stop VM
		#run_state = host.info()[0]
		#if libvirt.VIR_DOMAIN_RUNNING == run_state:
		#	print "In _stop_instance()"
		#	host.destroy() # destroy _is_ halt

		# Pause VM
		run_state = host.info()[0]
		if libvirt.VIR_DOMAIN_RUNNING == run_state:
			print "In _stop_instance()"
			host.suspend() # suspend

# This is the dictionary that the buildmaster pays attention to. We also
use
# a shorter alias to save typing.
c = BuildmasterConfig = {}

####### BUILDSLAVES

c['slaves'] = [VirshBuildSlave("win7-x64", "APASSWORD")]
============================================================





More information about the devel mailing list