Example #1
0
    def __init__(self,
                 connection_string="qemu:///system",
                 storage_pool_name="default",
                 stp=True, hpet=True, use_host_cpu=True):
        """libvirt driver

        :param use_host_cpu: When creating nodes, should libvirt's
            CPU "host-model" mode be used to set CPU settings. If set to False,
            default mode ("custom") will be used.  (default: True)
        """
        libvirt.virInitialize()
        self.conn = libvirt.open(connection_string)
        self.xml_builder = LibvirtXMLBuilder(self)
        self.stp = stp
        self.hpet = hpet
        self.capabilities = None
        self.allocated_networks = None
        self.storage_pool_name = storage_pool_name
        self.reboot_timeout = None
        self.use_host_cpu = use_host_cpu
        self.use_hugepages = settings.USE_HUGEPAGES

        if settings.VNC_PASSWORD:
            self.vnc_password = settings.VNC_PASSWORD

        if settings.REBOOT_TIMEOUT:
            self.reboot_timeout = settings.REBOOT_TIMEOUT
Example #2
0
    def __init__(self,
                 connection_string="qemu:///system",
                 storage_pool_name="default"):
        libvirt.virInitialize()
        self.conn = libvirt.open(connection_string)
        self.xml_builder = LibvirtXMLBuilder(self)
        self.capabilities = None
        self.allocated_networks = None
        self.storage_pool_name = storage_pool_name

        if settings.VNC_PASSWORD:
            self.vnc_password = settings.VNC_PASSWORD
Example #3
0
    def __init__(self,
                 connection_string="qemu:///system",
                 storage_pool_name="default",
                 stp=True, hpet=True):
        libvirt.virInitialize()
        self.conn = libvirt.open(connection_string)
        self.xml_builder = LibvirtXMLBuilder(self)
        self.stp = stp
        self.hpet = hpet
        self.capabilities = None
        self.allocated_networks = None
        self.storage_pool_name = storage_pool_name
        self.reboot_timeout = None

        if settings.VNC_PASSWORD:
            self.vnc_password = settings.VNC_PASSWORD

        if settings.REBOOT_TIMEOUT:
            self.reboot_timeout = settings.REBOOT_TIMEOUT
Example #4
0
    def __init__(self):
        self.lock = threading.RLock()
        try:
            # try to use libvirt
            import libvirt
            libvirt.virInitialize()
            globals()["libvirt"] = libvirt
            
            # register an ErrorCallback
            def errHandler(ctx, error):
                # log.debug("backend error: %s" % (error,))
                pass
            libvirt.registerErrorHandler(errHandler, None)

            self.con = libvirt.open(None)
            log.info("backend connected to libvirt")
        except:
            log.error("could not connect to xen backend!")
            raise
Example #5
0
 def __init__(self):
     libvirt.virInitialize()
     self.connections = {}
Example #6
0
 def __init__(self, connection_string="qemu:///system"):
     libvirt.virInitialize()
     self.conn = libvirt.open(connection_string)
     self.xml_builder = LibvirtXMLBuilder(self)
     self.capabilities = None
     self.allocated_networks = None
Example #7
0
 def __init__(self):
     libvirt.virInitialize()
     self.connections = {}
Example #8
0
def build(srcpkg, outdir, package, jobid, logfile, arch):
    logging.info('building %s to %s' % (os.path.basename(srcpkg), outdir))

    steptimer.start()
    vmid = 'buildvm_%d' % jobid

    # open a libvirt connection to hypervisor
    libvirt.virInitialize()
    libvirt.virEventRegisterDefaultImpl()
    conn = libvirt.open('qemu:///system')
    if conn == None:
        logging.error('Failed to open connection to the hypervisor')
        return False

    # create VM
    clone_storage = clone(conn, BASE_VMID[arch], vmid)
    steptimer.mark('clone vm')

    domain = conn.lookupByName(vmid)

    # start vm, automatically clean up when we are done, unless debugging
    domain.createWithFlags(libvirt.VIR_DOMAIN_START_AUTODESTROY if not debug else 0)

    # wait for vm to boot up
    wait_for_guest_agent(conn, domain, 5*60)
    guestPing(domain)

    steptimer.mark('boot')

    # ensure directory exists and is empty
    guestExec(domain, 'cmd', ['/C', 'rmdir', '/S', '/Q', r'C:\\vm_in\\'])
    guestExec(domain, 'cmd', ['/C', 'mkdir', r'C:\\vm_in\\'])

    # install build instructions and source
    for f in ['build.sh', 'wrapper.sh', srcpkg]:
        guestFileCopyTo(domain, f, r'C:\\vm_in\\' + os.path.basename(f))

    if package.depends:
        guestFileWrite(domain, r'C:\\vm_in\\depends', bytes(package.depends, 'ascii'))

    steptimer.mark('put')

    # attempt the build
    success = guestExec(domain, bash_path[arch], ['-l','/cygdrive/c/vm_in/wrapper.sh', os.path.basename(srcpkg), r'C:\\vm_out', package.script, package.kind])
    steptimer.mark('build')

    # XXX: guest-agent doesn't seem to be capable of capturing output of cygwin
    # process (for some strange reason), so we arrange to redirect it to a file
    # and collect it here...
    guestFileCopyFrom(domain, r'C:\\vm_in\\output', logfile)
    logging.info('build logfile is %s' % (logfile))

    # if the build was successful, fetch build products from VM
    if success:
        os.makedirs(outdir, exist_ok=True)
        manifest = os.path.join(outdir, 'manifest')
        guestFileCopyFrom(domain, r'C:\\vm_out\\manifest', manifest)

        with open(manifest) as f:
            for l in f:
                l = l.strip()
                fn = os.path.join(outdir, l)
                os.makedirs(os.path.dirname(fn), exist_ok=True)
                winpath = l.replace('/',r'\\')
                guestFileCopyFrom(domain, r'C:\\vm_out\\' + winpath, fn)

    steptimer.mark('fetch')

    if not debug:
        # terminate the VM.  Don't bother giving it a chance to shut down
        # cleanly since we won't be using it again
        domain.destroy()

        # clean up VM
        domain.undefineFlags(libvirt.VIR_DOMAIN_UNDEFINE_MANAGED_SAVE |
                             libvirt.VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA |
                             libvirt.VIR_DOMAIN_UNDEFINE_NVRAM)
        os.remove(clone_storage)
        steptimer.mark('destroy vm')

    status = 'succeeded' if success else 'failed'
    logging.info('build %s, %s' % (status, steptimer.report()))

    return success
Example #9
0
 def __init__(self, connection_string="qemu:///system"):
     libvirt.virInitialize()
     self.conn = libvirt.open(connection_string)
     self.xml_builder = LibvirtXMLBuilder(self)
     self.capabilities = None
     self.allocated_networks = None