def start(_id, flags=0): ''' Author : LHearen E-mail : [email protected] Time : 2015-12-15 15 : 44 Description : Used to start the VM pointed by uuid; ''' dom = conn.lookupByUUIDString(_id) try: dom.createWithFlags(int(flags)) except Exception, e: log.error("Started dom %s failed! Message: %s" % (_id, e)) return None
def define_VM_by_xml(xml_config): ''' added by LHearen E-mail: [email protected] Used to define a VM by a xml configuration file, dump its automatically generated internal xml configuration file and initialize the extra configuration file for latter use. ''' # log.debug(xml_config) # log.error(xml_config) try: dom = conn.defineXML(xml_config) except Exception: log.error("VM creation failed!") return None return dom.UUIDString()
def shutdown(_id, flags=0): ''' Author : LHearen E-mail : [email protected] Time : 2015-12-16 13 : 49 Description : Shutdown the VM specified by uuid if it cannot shutdown as usual, destroy it after a certain delay; ''' delay = 3 dom = conn.lookupByUUIDString(_id) if dom: try: dom.shutdownFlags(int(flags)) while delay > 0: sleep(1) if not dom.isActive(): return True delay -= 1 if dom.isActive(): dom.destroyFlags(int(flags)) if not dom.isActive(): return True except Exception, e: log.error("VM %s shutdown failed! Message: %s" % (_id, e))
dom = None try: dom = conn.lookupByUUIDString(_id) except Exception, e: logNotFound("VM", _id, e) return None if dom: if dom.isActive(): dom.destroyFlags(int(flags)) try: dom.undefineFlags(int(flags)) except Exception, e: log.debug("VM %s deletion failed! Message: %s" % (_id, e)) try: conn.lookupByUUIDString(_id) except Exception, e: log.error("VM %s deletion failed! Message: %s" % (_id, e)) filterDict = {"_id": _id} ret = VMHelper.remove(filterDict) if ret['ok'] > 0: return True else: log.debug("mongodb deletion failed!") return None return None def reboot(_id, flags=0): ''' Author : LHearen E-mail : [email protected] Time : 2015-12-16 14 : 00 Description : waiting for a period of time until vm is off,