+ @staticmethod
+ def dom_details (dom):
+ output = ""
+ output += " id={} - OSType={}".format(dom.ID(), dom.OSType())
+ # calling state() seems to be working fine
+ (state, reason) = dom.state()
+ output += " state={}, reason={}".format(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: state={}, maxmem = {}, mem = {}, ncpu = {}, cputime = {}]"\
+ .format(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 {}".format(self.name)
+ dom = self.dom
+ if dom is None:
+ output += " [no attached dom ?!?]"
+ else:
+ output += Sliver_Libvirt.dom_details (dom)
+ return output
+
+ # Thierry : I am not quite sure if /etc/libvirt/lxc/<>.xml holds a reliably up-to-date
+ # copy of the sliver XML config; I feel like issuing a virsh dumpxml first might be safer
+ def repair_veth(self):
+ # See workaround email, 2-14-2014, "libvirt 1.2.1 rollout"
+ xmlfilename = "/etc/libvirt/lxc/{}.xml".format(self.name)
+ with open(xmlfilename) as xmlfile:
+ xml = xmlfile.read()
+ veths = re.findall("<target dev='veth[0-9]*'/>", xml)
+ veths = [x[13:-3] for x in veths]
+ for veth in veths:
+ command = ["ip", "link", "delete", veth]
+ logger.log_call(command)
+
+ logger.log("trying to redefine the VM")
+ command = [ "virsh", "define", xmlfilename ]
+ logger.log_call(command)
+