def save_host(self, host: str) -> None: j: Dict[str, Any] = { 'daemons': {}, 'devices': [], 'osdspec_previews': [], 'daemon_config_deps': {}, } if host in self.last_daemon_update: j['last_daemon_update'] = datetime_to_str(self.last_daemon_update[host]) if host in self.last_device_update: j['last_device_update'] = datetime_to_str(self.last_device_update[host]) for name, dd in self.daemons[host].items(): j['daemons'][name] = dd.to_json() for d in self.devices[host]: j['devices'].append(d.to_json()) j['networks'] = self.networks[host] for name, depi in self.daemon_config_deps[host].items(): j['daemon_config_deps'][name] = { 'deps': depi.get('deps', []), 'last_config': datetime_to_str(depi['last_config']), } if self.osdspec_previews[host]: j['osdspec_previews'] = self.osdspec_previews[host] if host in self.last_host_check: j['last_host_check'] = datetime_to_str(self.last_host_check[host]) if host in self.last_etc_ceph_ceph_conf: j['last_etc_ceph_ceph_conf'] = datetime_to_str(self.last_etc_ceph_ceph_conf[host]) if self.scheduled_daemon_actions.get(host, {}): j['scheduled_daemon_actions'] = self.scheduled_daemon_actions[host] self.mgr.set_store(HOST_CACHE_PREFIX + host, json.dumps(j))
def save(self, spec): # type: (ServiceSpec) -> None if spec.preview_only: self.spec_preview[spec.service_name()] = spec return None self.specs[spec.service_name()] = spec self.spec_created[spec.service_name()] = datetime.datetime.utcnow() self.mgr.set_store( SPEC_STORE_PREFIX + spec.service_name(), json.dumps({ 'spec': spec.to_json(), 'created': datetime_to_str(self.spec_created[spec.service_name()]), }, sort_keys=True), ) self.mgr.events.for_service(spec, OrchestratorEvent.INFO, 'service was created')
def to_json(self) -> dict: out: Dict[str, Any] = dict() out['osd_id'] = self.osd_id out['started'] = self.started out['draining'] = self.draining out['stopped'] = self.stopped out['replace'] = self.replace out['force'] = self.force out['hostname'] = self.hostname # type: ignore for k in [ 'drain_started_at', 'drain_stopped_at', 'drain_done_at', 'process_started_at' ]: if getattr(self, k): out[k] = datetime_to_str(getattr(self, k)) else: out[k] = getattr(self, k) return out