X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sliver_libvirt.py;h=1517ad5631904adb068c7b19d1b74bf77e0bff4e;hb=a41a6c333955a30682573be315561be0030abcaf;hp=6ae8eebf104acb9ca9619d32d906a1e73ffc9263;hpb=89c268a4481d0d93946c61b03f0190c1bcb3ae9d;p=nodemanager.git diff --git a/sliver_libvirt.py b/sliver_libvirt.py index 6ae8eeb..1517ad5 100644 --- a/sliver_libvirt.py +++ b/sliver_libvirt.py @@ -23,6 +23,13 @@ STATES = { libvirt.VIR_DOMAIN_CRASHED: 'crashed', } +REASONS = { + libvirt.VIR_CONNECT_CLOSE_REASON_ERROR: 'Misc I/O error', + libvirt.VIR_CONNECT_CLOSE_REASON_EOF: 'End-of-file from server', + libvirt.VIR_CONNECT_CLOSE_REASON_KEEPALIVE: 'Keepalive timer triggered', + libvirt.VIR_CONNECT_CLOSE_REASON_CLIENT: 'Client requested it', +} + connections = dict() # Common Libvirt code @@ -39,12 +46,6 @@ class Sliver_Libvirt(Account): uri = vtype + '://' return connections.setdefault(uri, libvirt.open(uri)) - @staticmethod - def debuginfo(dom): - ''' Helper method to get a "nice" output of the info struct for debug''' - [state, maxmem, mem, ncpu, cputime] = dom.info() - return '%s is %s, maxmem = %s, mem = %s, ncpu = %s, cputime = %s' % (dom.name(), STATES.get(state, state), maxmem, mem, ncpu, cputime) - def __init__(self, rec): self.name = rec['name'] logger.verbose ('sliver_libvirt: %s init'%(self.name)) @@ -69,6 +70,34 @@ class Sliver_Libvirt(Account): dom = self.conn.lookupByName(self.name) self.dom = dom + @staticmethod + def dom_details (dom): + output="" + output += " id=%s - OSType=%s"%(dom.ID(),dom.OSType()) + # calling state() seems to be working fine + (state,reason)=dom.state() + output += " state=%s, reason=%s"%(STATES.get(state,state),REASONS.get(reason,reason)) + try: + # try to use info() - this however does not work for some reason on f20 + # info cannot get info operation failed: Cannot read cputime for domain + [state, maxmem, mem, ncpu, cputime] = dom.info() + output += " [info: maxmem = %s, mem = %s, ncpu = %s, cputime = %s]" % (STATES.get(state, state), maxmem, mem, ncpu, cputime) + except: + # too bad but libvirt.py prints out stuff on stdout when this fails, don't know how to get rid of that.. + output += " [info: not available]" + return output + + def __repr__(self): + ''' Helper method to get a "nice" output of the domain struct for debug purposes''' + output="Domain %s"%self.name + dom=self.dom + if dom is None: + output += " [no attached dom ?!?]" + else: + output += Sliver_Libvirt.dom_details (dom) + return output + + def start(self, delay=0): ''' Just start the sliver ''' logger.verbose('sliver_libvirt: %s start'%(self.name)) @@ -96,30 +125,14 @@ class Sliver_Libvirt(Account): try: self.dom.destroy() except: - logger.verbose('sliver_libvirt: Domain %s not running ' \ - 'UNEXPECTED: %s'%(self.name, sys.exc_info()[1])) - print 'sliver_libvirt: Domain %s not running ' \ - 'UNEXPECTED: %s'%(self.name, sys.exc_info()[1]) + logger.log_exc("in sliver_libvirt.stop",name=self.name) def is_running(self): ''' Return True if the domain is running ''' - logger.verbose('sliver_libvirt: %s is_running'%self.name) - try: - [state, _, _, _, _] = self.dom.info() - if state == libvirt.VIR_DOMAIN_RUNNING: - logger.verbose('sliver_libvirt: %s is RUNNING'%self.name) - return True - else: - info = Sliver_Libvirt.debuginfo(self.dom) - logger.verbose('sliver_libvirt: %s is ' \ - 'NOT RUNNING...\n%s'%(self.name, info)) - return False - except: - logger.verbose('sliver_libvirt: UNEXPECTED ERROR in ' \ - '%s: %s'%(self.name, sys.exc_info()[1])) - print 'sliver_libvirt: UNEXPECTED ERROR in ' \ - '%s: %s'%(self.name, sys.exc_info()[1]) - return False + (state,_) = self.dom.state() + result = (state == libvirt.VIR_DOMAIN_RUNNING) + logger.verbose('sliver_libvirt.is_running: %s => %s'%(self,result)) + return result def configure(self, rec):