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
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))
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))
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):