def _pool_resolve(self, pool_id): osdmap = self.get_sync_object(OsdMap) try: return osdmap.pools_by_id[pool_id] except KeyError: raise NotFound(POOL, pool_id)
def _osd_resolve(self, osd_id): osdmap = self.get_sync_object(OsdMap) try: return osdmap.osds_by_id[osd_id] except KeyError: raise NotFound(OSD, osd_id)
def list(self, object_type, list_filter): """ Get many objects """ osd_map = self.get_sync_object(OsdMap).data if osd_map is None: return [] if object_type == OSD: result = osd_map['osds'] if 'id__in' in list_filter: result = [ o for o in result if o['osd'] in list_filter['id__in'] ] if 'pool' in list_filter: try: osds_in_pool = self.get_sync_object(OsdMap).osds_by_pool[ list_filter['pool']] except KeyError: raise NotFound("Pool {0} does not exist".format( list_filter['pool'])) else: result = [o for o in result if o['osd'] in osds_in_pool] return result elif object_type == POOL: return osd_map['pools'] elif object_type == CRUSH_RULE: return osd_map['crush']['rules'] else: raise NotImplementedError(object_type)
def get_request(self, request_id): """ Get a JSON representation of a UserRequest """ try: return self._dump_request( rest_plugin().requests.get_by_id(request_id)) except KeyError: raise NotFound('request', request_id)
def get_valid_commands(self, object_type, object_ids): """ Determine what commands can be run on OSD object_ids """ if object_type != OSD: raise NotImplementedError(object_type) try: valid_commands = self.get_request_factory( object_type).get_valid_commands(object_ids) except KeyError as e: raise NotFound(object_type, str(e)) return valid_commands
def get_sync_object(self, object_type, path=None): if object_type == OsdMap: data = self.get("osd_map") assert data is not None data['tree'] = self.get("osd_map_tree") data['crush'] = self.get("osd_map_crush") data['crush_map_text'] = self.get("osd_map_crush_map_text") data['osd_metadata'] = self.get("osd_metadata") obj = OsdMap(data['epoch'], data) elif object_type == Config: data = self.get("config") obj = Config(0, data) elif object_type == MonMap: data = self.get("mon_map") obj = MonMap(data['epoch'], data) elif object_type == FsMap: data = self.get("fs_map") obj = FsMap(data['epoch'], data) elif object_type == PgSummary: data = self.get("pg_summary") self.log.debug("JSON: {0}".format(data)) obj = PgSummary(0, data) elif object_type == Health: data = self.get("health") obj = Health(0, json.loads(data['json'])) elif object_type == MonStatus: data = self.get("mon_status") obj = MonStatus(0, json.loads(data['json'])) else: raise NotImplementedError(object_type) # TODO: move 'path' handling up into C++ land so that we only # Pythonize the part we're interested in if path: try: for part in path: if isinstance(obj, dict): obj = obj[part] else: obj = getattr(obj, part) except (AttributeError, KeyError): raise NotFound(object_type, path) return obj
def cancel_request(self, request_id): try: rest_plugin().requests.cancel(request_id) return self.get_request(request_id) except KeyError: raise NotFound('request', request_id)