Example #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
Example #2
0
 def probe(self):
     try:
         _dir = os.path.dirname(self.FILENAME)
         mkdir.parents(_dir, stat.S_IRWXU)
     except:
         return False
     return True
Example #3
0
 def decode(encoded_data):
     mkdir.parents("/var/run/xend/boot/", stat.S_IRWXU)
     mediatype, encoding, data_start = scheme_data.parse(encoded_data)
     fd, filename = tempfile.mkstemp(prefix="data_uri_file.", dir="/var/run/xend/boot")
     os.write(fd, base64.b64decode(encoded_data[data_start:]))
     os.close(fd)
     return filename, True
    def daemonize(self):
        # Detach from TTY.

        # Become the group leader (already a child process)
        os.setsid()

        # Fork, this allows the group leader to exit,
        # which means the child can never again regain control of the
        # terminal
        if os.fork():
            os._exit(0)

        # Detach from standard file descriptors, and redirect them to
        # /dev/null or the log as appropriate.
        # We open the log file first, so that we can diagnose a failure to do
        # so _before_ we close stderr.
        try:
            parent = os.path.dirname(XEND_DEBUG_LOG)
            mkdir.parents(parent, stat.S_IRWXU)
            fd = os.open(XEND_DEBUG_LOG, os.O_WRONLY|os.O_CREAT|os.O_APPEND, 0666)
        except Exception, exn:
            print >>sys.stderr, exn
            print >>sys.stderr, ("Xend failed to open %s.  Exiting!" %
                                 XEND_DEBUG_LOG)
            sys.exit(1)
Example #5
0
    def daemonize(self):
        # Detach from TTY.

        # Become the group leader (already a child process)
        os.setsid()

        # Fork, this allows the group leader to exit,
        # which means the child can never again regain control of the
        # terminal
        if os.fork():
            os._exit(0)

        # Detach from standard file descriptors, and redirect them to
        # /dev/null or the log as appropriate.
        # We open the log file first, so that we can diagnose a failure to do
        # so _before_ we close stderr.
        try:
            parent = os.path.dirname(XEND_DEBUG_LOG)
            mkdir.parents(parent, stat.S_IRWXU)
            fd = os.open(XEND_DEBUG_LOG,
                         os.O_WRONLY | os.O_CREAT | os.O_APPEND, 0666)
        except Exception, exn:
            print >> sys.stderr, exn
            print >> sys.stderr, ("Xend failed to open %s.  Exiting!" %
                                  XEND_DEBUG_LOG)
            sys.exit(1)
Example #6
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
 def probe(self):
     try:
         _dir=os.path.dirname(self.FILENAME)
         mkdir.parents(_dir, stat.S_IRWXU)
     except:
         return False
     return True
Example #8
0
 def decode(encoded_data):
     mkdir.parents("/var/run/xend/boot/", stat.S_IRWXU)
     mediatype, encoding, data_start = scheme_data.parse(encoded_data)
     fd, filename = tempfile.mkstemp(
         prefix="data_uri_file.", dir="/var/run/xend/boot")
     os.write(fd, base64.b64decode(encoded_data[data_start:]))
     os.close(fd)
     return filename, True
Example #9
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
Example #10
0
def bind(path):
    """Create a Unix socket, and bind it to the given path.  The socket is
created such that only the current user may access it."""

    parent = os.path.dirname(path)
    mkdir.parents(parent, stat.S_IRWXU, True)
    if os.path.exists(path):
        os.unlink(path)

    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    sock.bind(path)
    return sock
Example #11
0
 def decode(encoded_data):
     mkdir.parents("/var/run/xend/boot/", stat.S_IRWXU)
     mediatype, encoding, data_start = scheme_data.parse(encoded_data)
     fd, filename = tempfile.mkstemp(prefix="data_uri_file.", dir="/var/run/xend/boot")
     # Because of python 2.3 support, there is a need to nest these
     # (see http://www.python.org/doc/2.3/ref/try.html)
     try:
         try:
             os.write(fd, base64.b64decode(encoded_data[data_start:]))
         except TypeError, se:
             raise scheme_error("failed to decode as base64")
     finally:
         os.close(fd)
     return filename, True
Example #12
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
Example #13
0
def bind(path, type = socket.SOCK_STREAM):
    """Create a Unix socket, and bind it to the given path.
    The socket is created such that only the current user may access it."""

    if path[0] == '\0': # Abstract namespace is used for the path
        pass
    else:
        parent = os.path.dirname(path)
        mkdir.parents(parent, stat.S_IRWXU, True)
        if os.path.exists(path):
            os.unlink(path)

    sock = socket.socket(socket.AF_UNIX, type)
    sock.bind(path)
    return sock
Example #14
0
 def decode(encoded_data):
     mkdir.parents("/var/run/xend/boot/", stat.S_IRWXU)
     mediatype, encoding, data_start = scheme_data.parse(encoded_data)
     fd, filename = tempfile.mkstemp(prefix="data_uri_file.",
                                     dir="/var/run/xend/boot")
     # Because of python 2.3 support, there is a need to nest these
     # (see http://www.python.org/doc/2.3/ref/try.html)
     try:
         try:
             os.write(fd, base64.b64decode(encoded_data[data_start:]))
         except TypeError, se:
             raise scheme_error("failed to decode as base64")
     finally:
         os.close(fd)
     return filename, True
Example #15
0
def bind(path, type=socket.SOCK_STREAM):
    """Create a Unix socket, and bind it to the given path.
    The socket is created such that only the current user may access it."""

    if path[0] == '\0':  # Abstract namespace is used for the path
        pass
    else:
        parent = os.path.dirname(path)
        mkdir.parents(parent, stat.S_IRWXU, True)
        if os.path.exists(path):
            os.unlink(path)

    sock = socket.socket(socket.AF_UNIX, type)
    sock.bind(path)
    return sock
 def probe(self):
     _dir = os.path.dirname(self.FILENAME)
     mkdir.parents(_dir, stat.S_IRWXU)
     return True
    def _refresh(self):
        """Internal function that refreshes the state of the disk and
        updates the list of images available.
        """
        self.lock.acquire()
        try:
            mkdir.parents(self.location, stat.S_IRWXU)

            # scan the directory and populate self.images
            virtual_alloc = 0
            physical_used = 0
            seen_images = []
            for filename in os.listdir(self.location):
                if filename[-5:] == XEND_STORAGE_QCOW_FILENAME[-5:]:
                    image_uuid = filename[:-5]
                    seen_images.append(image_uuid)

                    qcow_file = XEND_STORAGE_QCOW_FILENAME % image_uuid
                    cfg_file = XEND_STORAGE_VDICFG_FILENAME % image_uuid
                    qcow_path = os.path.join(self.location, qcow_file)
                    cfg_path = os.path.join(self.location, cfg_file)
                    
                    phys_size = os.stat(qcow_path).st_size
                    virt_size = qcow_virtual_size(qcow_path)
                    
                    # add this image if we haven't seen it before
                    if image_uuid not in self.images:
                        vdi = XendQCoWVDI(image_uuid, self.uuid,
                                          qcow_path, cfg_path,
                                          virt_size, phys_size)
                        
                        if cfg_path and os.path.exists(cfg_path):
                            try:
                                vdi.load_config(cfg_path)
                            except:
                                log.error('Corrupt VDI configuration file %s' %
                                          cfg_path)
                        
                        self.images[image_uuid] = vdi

                    physical_used += phys_size
                    virtual_alloc += virt_size

            # remove images that aren't valid
            for image_uuid in self.images.keys():
                if image_uuid not in seen_images:
                    try:
                        os.unlink(self.images[image_uuid].qcow_path)
                    except OSError:
                        pass
                    del self.images[image_uuid]

            self.virtual_allocation = virtual_alloc
            self.physical_utilisation = physical_used

            # update free storage if we have to track that
            if self.physical_size == XEND_STORAGE_NO_MAXIMUM:
                self.storage_free = self._get_free_space()
            else:
                self.storage_free = self.physical_size - self.virtual_allocation
                        
        finally:
            self.lock.release()
Example #18
0
 def openFileHandler(fname):
     mkdir.parents(os.path.dirname(fname), stat.S_IRWXU)
     return XendRotatingFileHandler(fname, mode = 'a',
                                    maxBytes = MAX_BYTES,
                                    backupCount = BACKUP_COUNT)
    def _refresh(self):
        """Internal function that refreshes the state of the disk and
        updates the list of images available.
        """
        self.lock.acquire()
        try:
            mkdir.parents(self.location, stat.S_IRWXU)

            # scan the directory and populate self.images
            virtual_alloc = 0
            physical_used = 0
            seen_images = []
            for filename in os.listdir(self.location):
                if filename[-5:] == XEND_STORAGE_QCOW_FILENAME[-5:]:
                    image_uuid = filename[:-5]
                    seen_images.append(image_uuid)

                    qcow_file = XEND_STORAGE_QCOW_FILENAME % image_uuid
                    cfg_file = XEND_STORAGE_VDICFG_FILENAME % image_uuid
                    qcow_path = os.path.join(self.location, qcow_file)
                    cfg_path = os.path.join(self.location, cfg_file)

                    phys_size = os.stat(qcow_path).st_size
                    virt_size = qcow_virtual_size(qcow_path)

                    # add this image if we haven't seen it before
                    if image_uuid not in self.images:
                        vdi = XendQCoWVDI(image_uuid, self.uuid, qcow_path,
                                          cfg_path, virt_size, phys_size)

                        if cfg_path and os.path.exists(cfg_path):
                            try:
                                vdi.load_config(cfg_path)
                            except:
                                log.error('Corrupt VDI configuration file %s' %
                                          cfg_path)

                        self.images[image_uuid] = vdi

                    physical_used += phys_size
                    virtual_alloc += virt_size

            # remove images that aren't valid
            for image_uuid in self.images.keys():
                if image_uuid not in seen_images:
                    try:
                        os.unlink(self.images[image_uuid].qcow_path)
                    except OSError:
                        pass
                    del self.images[image_uuid]

            self.virtual_allocation = virtual_alloc
            self.physical_utilisation = physical_used

            # update free storage if we have to track that
            if self.physical_size == XEND_STORAGE_NO_MAXIMUM:
                self.storage_free = self._get_free_space()
            else:
                self.storage_free = self.physical_size - self.virtual_allocation

        finally:
            self.lock.release()
 def openFileHandler(fname):
     mkdir.parents(os.path.dirname(fname), stat.S_IRWXU)
     return XendRotatingFileHandler(fname, mode = 'a',
                                    maxBytes = MAX_BYTES,
                                    backupCount = BACKUP_COUNT)
 def probe(self):
     _dir=os.path.dirname(self.FILENAME)
     mkdir.parents(_dir, stat.S_IRWXU)
     return True