def create_cache(): if not os.path.exists(VDSM_CACHE_DIR): os.makedirs(VDSM_CACHE_DIR) for path in find_all_schemas(): with io.open(path, 'rb') as f: loaded_schema = _load_yaml_file(f) pickle_schema_path = os.path.join(VDSM_CACHE_DIR, _get_pickle_schema_path(path)) if (os.path.exists(pickle_schema_path) and round(os.stat(path).st_mtime, 2) == round( os.stat(pickle_schema_path).st_mtime, 2)): logging.info( 'Pickled schema {} already exists and up to date'.format( os.path.basename(pickle_schema_path))) continue logging.info('Writing new schema {}'.format( os.path.basename(pickle_schema_path))) with io.open(pickle_schema_path, 'wb') as pickled_schema: pickle.dump(loaded_schema, pickled_schema, protocol=pickle.HIGHEST_PROTOCOL) mod_time = os.stat(path).st_mtime os.utime(pickle_schema_path, (mod_time, mod_time)) os.chmod(pickle_schema_path, 0o444)
def _finishSuccessfully(self, machineParams): with self._lock: self._progress = 100 if not self.hibernating: # TODO: We could use a timeout on the wait to be more robust # against "impossible" failures. But we don't have a good value to # use here now. self._vm.stopped_migrated_event_processed.wait() self._vm.setDownStatus(NORMAL, vmexitreason.MIGRATION_SUCCEEDED) self.status['status']['message'] = 'Migration done' if self._vm.post_copy == PostCopyPhase.RUNNING: self._vm.destroy() else: # don't pickle transient params for ignoreParam in ('displayIp', 'display', 'pid'): if ignoreParam in machineParams: del machineParams[ignoreParam] fname = self._vm.cif.prepareVolumePath(self._dstparams) try: # Use r+ to avoid truncating the file, see BZ#1282239 with io.open(fname, "r+b") as f: # protocol=2 is needed for clusters < 4.4 # (for Python 2 host compatibility) pickle.dump(machineParams, f, protocol=2) finally: self._vm.cif.teardownVolumePath(self._dstparams) self._vm.setDownStatus(NORMAL, vmexitreason.SAVE_STATE_SUCCEEDED) self.status['status']['message'] = 'SaveState done'
def _dump_pickled_schema(schema_path, pickled_schema_path): with io.open(schema_path, 'rb') as f: loaded_schema = _load_yaml_file(f) with io.open(pickled_schema_path, 'wb') as pickled_schema: pickle.dump(loaded_schema, pickled_schema, protocol=pickle.HIGHEST_PROTOCOL)
def _finishSuccessfully(self): with self._lock: self._progress = 100 if not self.hibernating: # TODO: We could use a timeout on the wait to be more robust # against "impossible" failures. But we don't have a good value to # use here now. self._vm.stopped_migrated_event_processed.wait() self._vm.setDownStatus(NORMAL, vmexitreason.MIGRATION_SUCCEEDED) self.status['status']['message'] = 'Migration done' if self._vm.post_copy == PostCopyPhase.RUNNING: self._vm.destroy() else: # don't pickle transient params for ignoreParam in ('displayIp', 'display', 'pid'): if ignoreParam in self._machineParams: del self._machineParams[ignoreParam] fname = self._vm.cif.prepareVolumePath(self._dstparams) try: # Use r+ to avoid truncating the file, see BZ#1282239 with open(fname, "r+") as f: pickle.dump(self._machineParams, f) finally: self._vm.cif.teardownVolumePath(self._dstparams) self._vm.setDownStatus(NORMAL, vmexitreason.SAVE_STATE_SUCCEEDED) self.status['status']['message'] = 'SaveState done'
def _dump_pickled_schema(schema_path, pickled_schema_path): with io.open(schema_path, 'rb') as f: loaded_schema = _load_yaml_file(f) with io.open(pickled_schema_path, 'wb') as pickled_schema: pickle.dump(loaded_schema, pickled_schema, protocol=pickle.HIGHEST_PROTOCOL)
def _dump(self, data): with tempfile.NamedTemporaryFile( dir=constants.P_VDSM_RUN, delete=False ) as f: pickle.dump(data, f) os.rename(f.name, self._path)
def _dump(self, data): with tempfile.NamedTemporaryFile( dir=constants.P_VDSM_RUN, delete=False ) as f: pickle.dump(data, f) os.rename(f.name, self._path)