def load_temp(self): temp_file = os.path.join(utils.get_instance_dir(self.domain), CONF.temp_file_name) if os.path.exists(temp_file): try: LOG.debug("Loading temp file from %s" % temp_file) with open(temp_file, 'r') as f: temp_data = json.loads(f.read()) elapse = long(time.time()) - temp_data['timestamp'] if (elapse >= 0 and elapse <= CONF.monitor_delay + CONF.temp_file_timeout): for k,v in temp_data.iteritems(): if k in self.temp: self.temp[k] = v LOG.debug("Loaded temp file: %s" % self.temp) return True else: LOG.debug("Temp file is time out") return False except (KeyError, TypeError, AttributeError, ValueError) as e: LOG.warn("Loaded temp file at %s failed, exception: %s" % (temp_file, e)) return False else: LOG.warn("Temp file not found at %s" % temp_file) return False
def save_temp(self): temp_file = os.path.join(utils.get_instance_dir(self.domain), CONF.temp_file_name) LOG.debug("Saving temp data of instance %s to %s: %s" % (utils.get_domain_uuid(self.domain), temp_file, self.temp)) with open(temp_file, 'w') as f: self.temp['timestamp'] = long(time.time()) f.write(json.dumps(self.temp))