Esempio n. 1
0
def bootloader(blexec,
               disk,
               dom,
               quiet=False,
               blargs='',
               kernel='',
               ramdisk='',
               kernel_args=''):
    """Run the boot loader executable on the given disk and return a
    config image.
    @param blexec  Binary to use as the boot loader
    @param disk Disk to run the boot loader on.
    @param dom DomainInfo representing the domain being booted.
    @param quiet Run in non-interactive mode, just booting the default.
    @param blargs Arguments to pass to the bootloader."""

    if not os.access(blexec, os.X_OK):
        msg = "Bootloader isn't executable"
        log.error(msg)
        raise VmError(msg)
    if not os.access(disk, os.R_OK):
        msg = "Disk isn't accessible"
        log.error(msg)
        raise VmError(msg)

    mkdir.parents("/var/run/xend/boot/", stat.S_IRWXU)

    while True:
        fifo = "/var/run/xend/boot/xenbl.%s" % (random.randint(0, 32000), )
        try:
            os.mkfifo(fifo, 0600)
        except OSError, e:
            if (e.errno != errno.EEXIST):
                raise
        break
Esempio n. 2
0
def bootloader(blexec, disk, dom, quiet = False, blargs = '', kernel = '',
               ramdisk = '', kernel_args = ''):
    """Run the boot loader executable on the given disk and return a
    config image.
    @param blexec  Binary to use as the boot loader
    @param disk Disk to run the boot loader on.
    @param dom DomainInfo representing the domain being booted.
    @param quiet Run in non-interactive mode, just booting the default.
    @param blargs Arguments to pass to the bootloader."""
    
    if not os.access(blexec, os.X_OK):
        msg = "Bootloader isn't executable"
        log.error(msg)
        raise VmError(msg)
    if not os.access(disk, os.R_OK):
        msg = "Disk isn't accessible"
        log.error(msg)
        raise VmError(msg)

    if os.uname()[0] == "NetBSD" and disk.startswith('/dev/'):
       disk = disk.replace("/dev/", "/dev/r")

    mkdir.parents("/var/run/xend/boot/", stat.S_IRWXU)

    while True:
        fifo = "/var/run/xend/boot/xenbl.%s" %(random.randint(0, 32000),)
        try:
            os.mkfifo(fifo, 0600)
        except OSError, e:
            if (e.errno != errno.EEXIST):
                raise
        break
Esempio n. 3
0
def slurp(infile):
    while 1:
        line = infile.readline()
        if line == "":
            break
        else:
            log.error('%s', line.strip())
Esempio n. 4
0
def read_exact(fd, size, errmsg):
    buf  = '' 
    while size != 0: 
        str = os.read(fd, size)
        if not len(str):
            log.error("read_exact: EOF trying to read %d (buf='%s')" % \
                      (size, buf))
            raise XendError(errmsg)
        size = size - len(str)
        buf  = buf + str
    return buf
Esempio n. 5
0
def bootloader(blexec, disk, quiet=0, vcpus=None, entry=None):
    """Run the boot loader executable on the given disk and return a
    config image.
    @param blexec  Binary to use as the boot loader
    @param disk Disk to run the boot loader on.
    @param quiet Run in non-interactive mode, just booting the default.
    @param vcpus Number of vcpus for the domain.
    @param entry Default entry to boot."""

    if not os.access(blexec, os.X_OK):
        msg = "Bootloader isn't executable"
        log.error(msg)
        raise VmError(msg)
    if not os.access(disk, os.R_OK):
        msg = "Disk isn't accessible"
        log.error(msg)
        raise VmError(msg)

    while True:
        fifo = "/var/lib/xen/xenbl.%s" % (random.randint(0, 32000),)
        if not os.path.exists(fifo):
            break
    os.mkfifo(fifo, 0600)

    child = os.fork()
    if not child:
        args = [blexec]
        if quiet:
            args.append("-q")
        args.append("--output=%s" % (fifo,))
        if entry is not None:
            args.append("--entry=%s" % (entry,))
        args.append(disk)

        try:
            os.execvp(args[0], args)
        except OSError, e:
            print e
            pass
        os._exit(1)
Esempio n. 6
0
def bootloader(blexec, disk, quiet = 0, vcpus = None, entry = None):
    """Run the boot loader executable on the given disk and return a
    config image.
    @param blexec  Binary to use as the boot loader
    @param disk Disk to run the boot loader on.
    @param quiet Run in non-interactive mode, just booting the default.
    @param vcpus Number of vcpus for the domain.
    @param entry Default entry to boot."""
    
    if not os.access(blexec, os.X_OK):
        msg = "Bootloader isn't executable"
        log.error(msg)
        raise VmError(msg)
    if not os.access(disk, os.R_OK):
        msg = "Disk isn't accessible"
        log.error(msg)
        raise VmError(msg)

    while True:
        fifo = "/var/lib/xen/xenbl.%s" %(random.randint(0, 32000),)
        if not os.path.exists(fifo):
            break
    os.mkfifo(fifo, 0600)

    child = os.fork()
    if (not child):
        args = [ blexec ]
        if quiet:
            args.append("-q")
        args.append("--output=%s" %(fifo,))
        if entry is not None:
            args.append("--entry=%s" %(entry,))
        args.append(disk)

        try:
            os.execvp(args[0], args)
        except OSError, e:
            print e
            pass
        os._exit(1)
Esempio n. 7
0
def bootloader(blexec,
               disk,
               dom,
               quiet=False,
               blargs='',
               kernel='',
               ramdisk='',
               kernel_args=''):
    """Run the boot loader executable on the given disk and return a
    config image.
    @param blexec  Binary to use as the boot loader
    @param disk Disk to run the boot loader on.
    @param dom DomainInfo representing the domain being booted.
    @param quiet Run in non-interactive mode, just booting the default.
    @param blargs Arguments to pass to the bootloader."""

    if not os.access(blexec, os.X_OK):
        msg = "Bootloader isn't executable"
        log.error(msg)
        raise VmError(msg)

    # domUloader requires '--entry=foo' in blargs, which is derived from
    # 'bootargs' entry in domain configuration file.  Ensure it exists
    # here so a reasonable error message can be returned.
    if blexec.find('domUloader.py') != -1:
        if blargs.find('entry') == -1:
            msg = "domUloader requires specification of bootargs"
            log.error(msg)
            raise VmError(msg)

    avail = False
    for i in xrange(1, 500):
        avail = os.access(disk, os.R_OK)
        if avail:
            break
        time.sleep(.1)

    if not avail:
        msg = "Disk '%s' isn't accessible" % disk
        log.error(msg)
        raise VmError(msg)

    if os.uname()[0] == "NetBSD" and disk.startswith('/dev/'):
        disk = "/r".join(disk.rsplit("/", 1))

    mkdir.parents("/var/run/xend/boot/", stat.S_IRWXU)

    while True:
        fifo = "/var/run/xend/boot/xenbl.%s" % (random.randint(0, 32000), )
        try:
            os.mkfifo(fifo, 0600)
        except OSError, e:
            if (e.errno != errno.EEXIST):
                raise
        break
Esempio n. 8
0
def bootloader(blexec, disk, dom, quiet = False, blargs = '', kernel = '',
               ramdisk = '', kernel_args = ''):
    """Run the boot loader executable on the given disk and return a
    config image.
    @param blexec  Binary to use as the boot loader
    @param disk Disk to run the boot loader on.
    @param dom DomainInfo representing the domain being booted.
    @param quiet Run in non-interactive mode, just booting the default.
    @param blargs Arguments to pass to the bootloader."""
    
    if not os.access(blexec, os.X_OK):
        msg = "Bootloader isn't executable"
        log.error(msg)
        raise VmError(msg)

    # domUloader requires '--entry=foo' in blargs, which is derived from
    # 'bootargs' entry in domain configuration file.  Ensure it exists
    # here so a reasonable error message can be returned.
    if blexec.find('domUloader.py') != -1:
        if blargs.find('entry') == -1:
            msg = "domUloader requires specification of bootargs"
            log.error(msg)
            raise VmError(msg)

    avail = False
    for i in xrange(1, 100):
        avail = os.access(disk, os.R_OK)
        if avail:
            break
        time.sleep(.1)

    if not avail:
        msg = "Disk '%s' isn't accessible" % disk
        log.error(msg)
        raise VmError(msg)

    if os.uname()[0] == "NetBSD" and disk.startswith('/dev/'):
       disk = "/r".join(disk.rsplit("/",1))

    mkdir.parents("/var/run/xend/boot/", stat.S_IRWXU)

    while True:
        fifo = "/var/run/xend/boot/xenbl.%s" %(random.randint(0, 32000),)
        try:
            os.mkfifo(fifo, 0600)
        except OSError, e:
            if (e.errno != errno.EEXIST):
                raise
        break
Esempio n. 9
0
    del outbuf
    os.waitpid(child, 0)
    os.close(r)
    os.close(m2)
    os.close(m1)
    if os.uname()[0] == 'SunOS' or os.uname()[0] == 'NetBSD':
        os.close(s1)
    os.unlink(fifo)

    # Re-acquire the lock to cover the changes we're about to make
    # when we return to domain creation.
    domains.domains_lock.acquire()    

    if dom.bootloader_pid is None:
        msg = "Domain was died while the bootloader was running."
        log.error(msg)
        raise VmError, msg        
        
    dom.bootloader_pid = None

    if len(ret) == 0:
        msg = "Boot loader didn't return any data!"
        log.error(msg)
        raise VmError, msg

    pin = sxp.Parser()
    pin.input(ret)
    pin.input_eof()
    blcfg = pin.val
    return blcfg
Esempio n. 10
0
    del outbuf
    os.waitpid(child, 0)
    os.close(r)
    os.close(m2)
    os.close(m1)
    if os.uname()[0] == 'SunOS' or os.uname()[0] == 'NetBSD':
        os.close(s1)
    os.unlink(fifo)

    # Re-acquire the lock to cover the changes we're about to make
    # when we return to domain creation.
    domains.domains_lock.acquire()

    if dom.bootloader_pid is None:
        msg = "Domain was died while the bootloader was running."
        log.error(msg)
        raise VmError, msg

    dom.bootloader_pid = None

    if len(ret) == 0:
        msg = "Boot loader didn't return any data!"
        log.error(msg)
        raise VmError, msg

    pin = sxp.Parser()
    pin.input(ret)
    pin.input_eof()
    blcfg = pin.val
    return blcfg