def _createFromGivenImage(cls, index, requirement, image1, bootFromNetwork): name = cls._nameFromIndex(index) image2 = os.path.join(config.DISK_IMAGES_DIRECTORY, name + "_disk2.qcow2") serialLog = os.path.join(config.SERIAL_LOGS_DIRECTORY, name + ".serial.txt") if not os.path.isdir(os.path.dirname(serialLog)): os.makedirs(os.path.dirname(serialLog)) hardwareConstraints = requirement['hardwareConstraints'] imagecommands.create(image=image2, sizeGB=hardwareConstraints['minimumDisk2SizeGB']) mani = manifest.Manifest.create( name=name, memoryMB=int(1024 * hardwareConstraints['minimumRAMGB']), vcpus=hardwareConstraints['minimumCPUs'], disk1Image=image1, disk2Image=image2, primaryMACAddress=network.primaryMACAddressFromVMIndex(index), secondaryMACAddress=network.secondMACAddressFromVMIndex(index), networkName=network.NAME, serialOutputFilename=serialLog, bootFromNetwork=bootFromNetwork) with libvirtsingleton.it().lock(): domain = libvirtsingleton.it().libvirt().defineXML(mani.xml()) domain.create() return cls(index=index, domain=domain, requirement=requirement, manifest=mani, disk1SizeGB=hardwareConstraints['minimumDisk1SizeGB'], disk2SizeGB=hardwareConstraints['minimumDisk2SizeGB'])
def _createFromGivenImage(cls, index, requirement, image1, bootFromNetwork): name = cls._nameFromIndex(index) image2 = os.path.join(config.DISK_IMAGES_DIRECTORY, name + "_disk2.qcow2") serialLog = os.path.join(config.SERIAL_LOGS_DIRECTORY, name + ".serial.txt") if not os.path.isdir(os.path.dirname(serialLog)): os.makedirs(os.path.dirname(serialLog)) hardwareConstraints = requirement["hardwareConstraints"] imagecommands.create(image=image2, sizeGB=hardwareConstraints["minimumDisk2SizeGB"]) mani = manifest.Manifest.create( name=name, memoryMB=int(1024 * hardwareConstraints["minimumRAMGB"]), vcpus=hardwareConstraints["minimumCPUs"], disk1Image=image1, disk2Image=image2, primaryMACAddress=network.primaryMACAddressFromVMIndex(index), secondaryMACAddress=network.secondMACAddressFromVMIndex(index), networkName=network.NAME, serialOutputFilename=serialLog, bootFromNetwork=bootFromNetwork, ) with libvirtsingleton.it().lock(): domain = libvirtsingleton.it().libvirt().defineXML(mani.xml()) domain.create() return cls( index=index, domain=domain, requirement=requirement, manifest=mani, disk1SizeGB=hardwareConstraints["minimumDisk1SizeGB"], disk2SizeGB=hardwareConstraints["minimumDisk2SizeGB"], )
def setUp(): with libvirtsingleton.it().lock(): libvirt = libvirtsingleton.it().libvirt() try: libvirt.networkLookupByName(NAME) logging.info("Libvirt network is already set up") except: _create(libvirt) logging.info("Libvirt network created") _openFirewall()
def setUp(): with libvirtsingleton.it().lock(): libvirt = libvirtsingleton.it().libvirt() try: libvirt.networkLookupByName(NAME) logging.info("Libvirt network is already set up") except: _create(libvirt) logging.info("Libvirt network created") _openFirewall()
def destroy(self): with libvirtsingleton.it().lock(): self._domain.destroy() self._domain.undefine() if os.path.exists(self._manifest.disk1Image()): os.unlink(self._manifest.disk1Image()) os.unlink(self._manifest.disk2Image())
def destroy(self): with libvirtsingleton.it().lock(): self._domain.destroy() self._domain.undefine() if os.path.exists(self._manifest.disk1Image()): os.unlink(self._manifest.disk1Image()) os.unlink(self._manifest.disk2Image())
def _cleanupDomains(): logging.info("Cleaning up previous rackattack nodes") cleaned = 0 ignored = 0 with libvirtsingleton.it().lock(): libvirt = libvirtsingleton.it().libvirt() for domain in libvirt.listAllDomains(0xFF): if not domain.name().startswith(config.DOMAIN_PREFIX): ignored += 1 continue if domain.isActive(): domain.destroy() domain.undefine() cleaned += 1 logging.info( "Done cleaning up previous rackattack nodes. %(cleaned)d cleaned, " "%(ignored)d ignored", dict(cleaned=cleaned, ignored=ignored))
def setUp(): with libvirtsingleton.it().lock(): libvirt = libvirtsingleton.it().libvirt() try: logging.info("Looking for Rackattack Virtual's libvirt network '%s'" % (NAME,)) libvirt.networkLookupByName(NAME) logging.info("Libvirt network is already set up") except: logging.info("Libvirt network was not found. Removing the bridge...") try: subprocess.check_call(["ifconfig", _BRIDGE_NAME, "down"]) except: pass try: subprocess.check_call(["brctl", "delbr", _BRIDGE_NAME]) except: pass logging.info("Libvirt network was not found. Creating it...") _create(libvirt) logging.info("Libvirt network created") _openFirewall()
def coldRestart(self): with libvirtsingleton.it().lock(): self._domain.destroy() self._domain.create()
def coldRestart(self): with libvirtsingleton.it().lock(): self._domain.destroy() self._domain.create()