def setup_heartbeat_file(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = SetupMountablePrimaryStorageHeartbeatResponse() for hb in cmd.heartbeatFilePaths: hb_dir = os.path.dirname(hb) mount_path = os.path.dirname(hb_dir) if not linux.is_mounted(mount_path): rsp.error = '%s is not mounted, setup heartbeat file[%s] failed' % ( mount_path, hb) rsp.success = False return jsonobject.dumps(rsp) for hb in cmd.heartbeatFilePaths: t = self.heartbeat_timer.get(hb, None) if t: t.cancel() hb_dir = os.path.dirname(hb) if not os.path.exists(hb_dir): os.makedirs(hb_dir, 0755) t = thread.timer(cmd.heartbeatInterval, self._heartbeat_func, args=[hb], stop_on_exception=False) t.start() self.heartbeat_timer[hb] = t logger.debug('create heartbeat file at[%s]' % hb) return jsonobject.dumps(rsp)
def setup_heartbeat_file(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = SetupMountablePrimaryStorageHeartbeatResponse() for hb in cmd.heartbeatFilePaths: hb_dir = os.path.dirname(hb) mount_path = os.path.dirname(hb_dir) if not linux.is_mounted(mount_path): rsp.error = '%s is not mounted, setup heartbeat file[%s] failed' % (mount_path, hb) rsp.success = False return jsonobject.dumps(rsp) for hb in cmd.heartbeatFilePaths: t = self.heartbeat_timer.get(hb, None) if t: t.cancel() hb_dir = os.path.dirname(hb) if not os.path.exists(hb_dir): os.makedirs(hb_dir, 0755) t = thread.timer(cmd.heartbeatInterval, self._heartbeat_func, args=[hb], stop_on_exception=False) t.start() self.heartbeat_timer[hb] = t logger.debug('create heartbeat file at[%s]' % hb) return jsonobject.dumps(rsp)