Пример #1
0
 def __init__(self, m, min_, target, max_):
     self._m = m
     self._min = units.parse_binary(min_)
     self._size = units.parse_binary(target)
     self._target = self._size
     self._max = units.parse_binary(max_)
     self._actual = self._max
     self._safeguard = 0
Пример #2
0
    def __call__(self, size, wait=True, wait_post=True):
        if isinstance(size, str) and size and size[0] in '+-':
            new_size = self.size + units.parse_binary(size)
        elif isinstance(size, str) and size and size.startswith('>='):
            new_size = max(self.size, units.parse_binary(size[2:]))
        else:
            new_size = units.parse_binary(size)

        old_size = self.size
        if wait:
            self.size = new_size
        else:
            self.set_size_async(new_size)
        yield
        if wait_post:
            self.size = old_size
        else:
            self.set_size_async(old_size)
Пример #3
0
def has_space(how_much='2G', reserve_fraction=.5, where=None):
    where = where or tempfile.gettempdir()
    how_much = units.parse_binary(how_much)
    total, _, free = shutil.disk_usage(where)
    if not free >= how_much:
        log.warning(f'{where} does not have {how_much} of free space')
    if not free >= total * reserve_fraction:
        log.warning(f'{where} is {int((1 - reserve_fraction) * 100)}% full')
    return free >= how_much and free >= total * reserve_fraction
Пример #4
0
 def balloon(self, target_size):
     target_size = units.parse_binary(target_size)
     if self.vm.ram._actual != target_size:
         with self._command_execution_lock:
             self.vm.log.debug('sending a request to balloon to '
                               f'{units.binary(target_size)} from '
                               f'{units.binary(self.vm.ram._actual)}')
             self._execute(f'balloon', **{'value': target_size})
             self._expect({'return': {}})
     else:
         self.vm.log.debug('no ballooning needed, '
                           f'already at {units.binary(target_size)}')
Пример #5
0
 def min(self, new):
     new = units.parse_binary(new)
     if new < self._safeguard:
         self._m.log.warning(f"won't set ram.min to {units.binary(new)}, "
                             'clipping to ram.safeguard '
                             f'({units.binary(self._safeguard)})')
         new = self._safeguard
     if new > self._max:
         self._m.log.warning(f'cannot set ram.min to {units.binary(new)}, '
                             'clipping to ram.max '
                             f'({units.binary(self._max)})')
         new = self._max
     self._m.log.debug(f'setting ram.min to {units.binary(new)}')
     self._min = new
     if self._target < new:
         self._m.log.debug(f'bumping ram.size to {units.binary(new)} '
                           'along with ram.min')
         self.size = new
Пример #6
0
 def set_size_async(self, new):
     new = units.parse_binary(new)
     if new < self._min:
         self._m.log.warning(f'cannot set ram.size to {units.binary(new)}, '
                             'clipping to ram.min '
                             f'({units.binary(self._min)})')
         new = self._min
     if new < self._safeguard:
         self._m.log.warning(f"won't set ram.size to {units.binary(new)}, "
                             'clipping to ram.safeguard '
                             f'({units.binary(self._safeguard)})')
         new = self._safeguard
     if new > self._max:
         self._m.log.warning(f'cannot set ram.size to {units.binary(new)}, '
                             'clipping to ram.max '
                             f'({units.binary(self._max)})')
         new = self._max
     self._target = new
     if self._m.qemu.live and self._actual != new:
         self._m.log.debug(f'going to balloon to {units.binary(new)} '
                           f'from {units.binary(self._m.ram._actual)}')
         self._m.qemu.monitor._ram_target_changed.set()
Пример #7
0
 def safeguard(self, new):
     self._safeguard = units.parse_binary(new)