def clone(name, source, *varargs, **kwargs): ''' Clone a VM (qvm-clone). ''' # Return if VM already exists exists_status = Status(**_state_action('qvm.check', name, *['exists'])) if exists_status.passed(): message = "A VM with the name '{0}' already exists.".format(name) status = Status()._format(prefix='[SKIP] ', message=message) return vars(status._finalize(test_mode=__opts__['test'])) return _state_action('qvm.clone', source, name, *varargs, **kwargs)
def kill(name, *varargs, **kwargs): ''' Kill vmname (qvm-kill). ''' # Return if VM already halted (stderr will contain message if VM absent) halted_status = Status(**_state_action('qvm.state', name, *['halted'])) if halted_status.passed(): message = halted_status.stderr or "'{0}' is already halted.".format( name) status = Status()._format(prefix='[SKIP] ', message=message) return vars(status._finalize(test_mode=__opts__['test'])) return _state_action('qvm.kill', name, *varargs, **kwargs)
def absent(name, *varargs, **kwargs): ''' Make sure the named VM is absent. VM will be deleted (removed) if present (qvm-absent). ''' # Return if VM already absent missing_status = Status(**_state_action('qvm.check', name, *['missing'])) if missing_status.passed(): message = "The VM with the name '{0}' is already missing.".format(name) status = Status()._format(prefix='[SKIP] ', message=message) return vars(status._finalize(test_mode=__opts__['test'])) return _state_action('qvm.remove', name, *varargs, **kwargs)
def present(name, *varargs, **kwargs): ''' Make sure the named VM is present. VM will be created if missing (qvm-present). ''' # Return if VM already exists exists_status = Status(**_state_action('qvm.check', name, *['exists'])) if exists_status.passed(): message = "A VM with the name '{0}' already exists.".format(name) status = Status()._format(prefix='[SKIP] ', message=message) return vars(status._finalize(test_mode=__opts__['test'])) return _state_action('qvm.create', name, *varargs, **kwargs)
def status(self): ''' Returns finalized merged 'data' status. ''' status = Status() status_mode = 'last' if 'last' in self.defaults.status_mode else 'all' debug_mode = True if 'debug' in self.defaults.status_mode else False # pylint: disable=W0212 return status._finalize(data=self._data, status_mode=status_mode, cli_mode=self.defaults.cli_mode, debug_mode=debug_mode, test_mode=__opts__['test'])
def halted(name, *varargs, **kwargs): ''' Return True is vmname is halted (qvm-halted). ''' varargs = list(varargs) varargs.append('halted') # Return if VM already halted (stderr will contain message if VM absent) halted_status = Status( **_state_action('qvm.state', name, *varargs, **kwargs)) if halted_status.passed() or halted_status.stderr: message = halted_status.stderr or "'{0}' is already halted.".format( name) status = Status()._format(prefix='[SKIP] ', message=message) return vars(status._finalize(test_mode=__opts__['test'])) return _state_action('qvm.state', name, *varargs, **kwargs)
def halted(name, *varargs, **kwargs): ''' Return True is vmname is halted (qvm-halted). ''' varargs = list(varargs) varargs.append('halted') # Return if VM already halted (stderr will contain message if VM absent) halted_status = Status(**_state_action('qvm.state', name, *varargs, **kwargs)) if halted_status.passed() or halted_status.stderr: message = halted_status.stderr or "'{0}' is already halted.".format( name) status = Status()._format(prefix='[SKIP] ', message=message) return vars(status._finalize(test_mode=__opts__['test'])) return _state_action('qvm.state', name, *varargs, **kwargs)
def status(self): ''' Returns finalized merged 'data' status. ''' status = Status() status_mode = 'last' if 'last' in self.defaults.status_mode else 'all' debug_mode = True if 'debug' in self.defaults.status_mode else False # pylint: disable=W0212 return status._finalize( data=self._data, status_mode=status_mode, cli_mode=self.defaults.cli_mode, debug_mode=debug_mode, test_mode=__opts__['test'] )