Пример #1
0
 def resize(self, dbg, sr, key, new_size):
     new_size = int(new_size)
     u = urlparse.urlparse(sr)
     path = os.path.join(u.path, key)
     if not (os.path.exists(path)):
         raise xapi.storage.api.volume.Volume_does_not_exist(key)
     size = os.stat(path).st_size
     if new_size < size:
         # Raise SMAPIv1 error VDISize
         raise xapi.XenAPIException(
             "SR_BACKEND_FAILURE_79",
             ["VDI Invalid size", "shrinking not allowed"])
     elif new_size == size:
         # No action needed
         pass
     elif new_size > size:
         # Expand the virtual disk
         try:
             fd = os.open(path, os.O_EXCL | os.O_WRONLY)
             os.lseek(fd, new_size - 1, os.SEEK_SET)
             os.write(fd, "\000")
             os.close(fd)
         except OSError:
             # ToDo: we ought to raise something more meaningful here
             raise
     return None
Пример #2
0
def create_storage_error(error_code, params):
    """
    Create an externally consumable error

    In most cases these will need to be equivalent to legacy
    storage errors so that external handlers remain compatible
    """
    import xapi
    return xapi.XenAPIException(error_code, params)
Пример #3
0
    def resize(self, dbg, sr, key, new_size):
        new_size = int(new_size)
        current_size = self._current_size(key)

        if new_size == current_size:
            return
        if new_size < current_size:
            # Raise SMAPIv1 error VDISize
            raise xapi.XenAPIException(
                "SR_BACKEND_FAILURE_79",
                ["VDI Invalid size", "shrinking not allowed"])
        cfg = ConfigHelper._get_config()
        res = linstor.Resource(key, cfg.controller)
        res.volumes[0].size = current_size
Пример #4
0
def validate_and_round_vhd_size(size):
    """ Take the supplied vhd size, in bytes, and check it is positive and less
    that the maximum supported size, rounding up to the next block boundary
    """
    if size < 0 or size > MAX_VHD_SIZE:
        raise xapi.XenAPIException('VDISize',
                                   ['VDI size must be between %d MB and %d MB' %
                                    ((MIN_VHD_SIZE / 1024 / 1024), (MAX_VHD_SIZE / 1024 / 1024))])

    if size < MIN_VHD_SIZE:
        size = MIN_VHD_SIZE

    size = roundup(VHD_BLOCK_SIZE, size)

    return size
Пример #5
0
 def detach(self, dbg, sr):
     u = urlparse.urlparse(sr)
     code = subprocess.call(["umount", u.path])
     if code != 0:
         raise xapi.XenAPIException("DAVE", ["IS", "COOL"])
     return