def _crushmap_item_create(self, items, name, ancestor_name=None, ancestor_type=None, depth=0): """Create crush map entry. """ # This is a recursive method. Add a safeguard to prevent infinite # recursion. if depth > constants.CEPH_CRUSH_MAP_DEPTH: raise exception.CephCrushMaxRecursion(depth=depth) root_name = self._format_root_name(name) for i in items: bucket_name = (root_name if i['type'] == 'root' else '%s-%s' % (i['name'], name)) if i['type'] != 'osd': LOG.error("bucket_name = %s, depth = %d" % (bucket_name, depth)) self._crush_bucket_add(bucket_name, i['type']) if 'items' in i: self._crushmap_item_create(i['items'], name, ancestor_name=bucket_name, ancestor_type=i['type'], depth=depth + 1) if ancestor_type: if i['type'] != 'osd': self._crush_bucket_move(bucket_name, ancestor_type, ancestor_name)
def _crushmap_item_delete(self, items, name, ancestor_name=None, ancestor_type=None, depth=0, rollback=False): """Delete a crush map entry. """ # This is a recursive method. Add a safeguard to to prevent infinite # recursion. if depth > constants.CEPH_CRUSH_MAP_DEPTH: return depth root_name = self._format_root_name(name) ret_code = 0 for i in items: if rollback: bucket_name = (root_name if i['type'] == 'root' else '%s-%s' % (i['name'], name)) else: bucket_name = root_name if i['type'] == 'root' else i['name'] if 'items' in i: ret_code = self._crushmap_item_delete(i['items'], name, ancestor_name=bucket_name, ancestor_type=i['type'], depth=depth + 1, rollback=rollback) LOG.error("bucket_name = %s, depth = %d, ret_code = %s" % ( bucket_name, depth, ret_code)) self._crush_bucket_remove(bucket_name) if ret_code != 0 and depth == 0: raise exception.CephCrushMaxRecursion(depth=ret_code) return (ret_code if ret_code else 0)