Skip to content

Commit c5041a0

Browse files
authored
Merge pull request ceph#62900 from ceph/revert-61786-ns-create-size-fix
Revert "mgr/dashboard: Ns create size fix"
2 parents f2edb72 + 495427b commit c5041a0

File tree

5 files changed

+5
-276
lines changed

5 files changed

+5
-276
lines changed

src/pybind/ceph_argparse.py

Lines changed: 1 addition & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
1010
LGPL-2.1 or LGPL-3.0. See file COPYING.
1111
"""
12-
from abc import ABC, abstractmethod
1312
import copy
1413
import enum
1514
import math
16-
import itertools
1715
import json
1816
import os
1917
import pprint
@@ -25,11 +23,7 @@
2523
import uuid
2624

2725
from collections import abc
28-
from typing import cast, Any, Callable, Dict, Generic, List, Optional, Sequence, Tuple, Union, \
29-
Annotated, Generic, TypeVar
30-
31-
S = TypeVar('S') # Input type
32-
T = TypeVar('T') # Output type
26+
from typing import cast, Any, Callable, Dict, Generic, List, Optional, Sequence, Tuple, Union
3327

3428
if sys.version_info >= (3, 8):
3529
from typing import get_args, get_origin
@@ -119,20 +113,6 @@ class JsonFormat(Exception):
119113
pass
120114

121115

122-
class Converter(ABC, Generic[S, T]):
123-
@abstractmethod
124-
def convert(self, value: S) -> T: pass
125-
126-
127-
def _get_annotation_metadata(tp):
128-
if get_origin(tp) is Annotated:
129-
annotated_args = get_args(tp)
130-
try:
131-
return annotated_args[1]
132-
except IndexError:
133-
return None
134-
135-
136116
class CephArgtype(object):
137117
"""
138118
Base class for all Ceph argument types
@@ -213,10 +193,6 @@ def to_argdesc(tp, attrs, has_default=False, positional=True):
213193
attrs['req'] = 'false'
214194
if not positional:
215195
attrs['positional'] = 'false'
216-
if annotation := _get_annotation_metadata(tp):
217-
if isinstance(annotation, CephArgtype):
218-
return annotation.argdesc(attrs)
219-
220196
CEPH_ARG_TYPES = {
221197
str: CephString,
222198
int: CephInt,
@@ -256,10 +232,6 @@ def _cast_to_compound_type(tp, v):
256232

257233
@staticmethod
258234
def cast_to(tp, v):
259-
if annotation := _get_annotation_metadata(tp):
260-
if isinstance(annotation, Converter):
261-
return annotation.convert(v)
262-
263235
PYTHON_TYPES = (
264236
str,
265237
int,
@@ -392,72 +364,6 @@ def argdesc(self, attrs):
392364
return super().argdesc(attrs)
393365

394366

395-
class CephSizeBytes(CephArgtype, Converter[str, int]):
396-
"""
397-
Size in bytes. e.g. 1024, 1KB, 100MB, etc..
398-
"""
399-
MULTIPLES = ['', "K", "M", "G", "T", "P"]
400-
UNITS = {
401-
f"{prefix}{suffix}": 1024 ** mult
402-
for mult, prefix in enumerate(MULTIPLES)
403-
for suffix in ['', 'B', 'iB']
404-
if not (prefix == '' and suffix == 'iB')
405-
}
406-
407-
def __init__(self, units_types: set = None):
408-
self.units = set(CephSizeBytes.UNITS.keys())
409-
if units_types :
410-
self.units &= units_types
411-
self.re_exp = re.compile(f"r'^\d+({'|'.join(self.units)})?$'")
412-
self.number_re_exp = re.compile(r'^\d+')
413-
self.num_and_unit_re_exp = re.compile(r'(\d+)([A-Za-z]*)$')
414-
415-
416-
def valid(self, s: str, partial: bool = False) -> None:
417-
if not s:
418-
raise ArgumentValid("Size string not provided.")
419-
420-
number_str = ''.join(itertools.takewhile(str.isdigit, s))
421-
if not number_str:
422-
raise ArgumentFormat("Size must start with a positive number.")
423-
424-
unit = s[len(number_str):]
425-
if unit and not unit.isalpha():
426-
raise ArgumentFormat("Invalid format. Expected format: <number>[KB|MB|GB] (e.g., 100MB, 10KB, 1000).")
427-
428-
if unit and unit not in self.units:
429-
raise ArgumentValid(f'{unit} is not a valid size unit. Supported units: {self.units}')
430-
self.val = s
431-
432-
def __str__(self) -> str:
433-
b = '|'.join(self.units)
434-
return '<sizebytes({0})>'.format(b)
435-
436-
def argdesc(self, attrs):
437-
return super().argdesc(attrs)
438-
439-
@staticmethod
440-
def _convert_to_bytes(size: Union[int, str], default_unit=None):
441-
if isinstance(size, int):
442-
number = size
443-
size = str(size)
444-
else:
445-
num_str = ''.join(filter(str.isdigit, size))
446-
number = int(num_str)
447-
unit_str = ''.join(filter(str.isalpha, size))
448-
if not unit_str:
449-
if not default_unit:
450-
raise ValueError("No size unit was provided")
451-
unit_str = default_unit
452-
453-
if unit_str in CephSizeBytes.UNITS:
454-
return number * CephSizeBytes.UNITS[unit_str]
455-
raise ValueError(f"Invalid unit: {unit_str}")
456-
457-
def convert(self, value: str) -> int:
458-
return CephSizeBytes._convert_to_bytes(value, default_unit="B")
459-
460-
461367
class CephSocketpath(CephArgtype):
462368
"""
463369
Admin socket path; check that it's readable and S_ISSOCK

src/pybind/mgr/dashboard/controllers/nvmeof.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# -*- coding: utf-8 -*-
22
import logging
3-
from typing import Annotated, Any, Dict, Optional
3+
from typing import Any, Dict, Optional
44

55
import cherrypy
6-
from ceph_argparse import CephSizeBytes
76
from orchestrator import OrchestratorError
87

98
from .. import mgr
@@ -386,8 +385,8 @@ def create(
386385
rbd_image_name: str,
387386
rbd_pool: str = "rbd",
388387
create_image: Optional[bool] = True,
389-
size: Optional[int] = None,
390-
rbd_image_size: Optional[Annotated[int, CephSizeBytes()]] = None,
388+
size: Optional[int] = 1024,
389+
rbd_image_size: Optional[int] = None,
391390
trash_image: Optional[bool] = False,
392391
block_size: int = 512,
393392
load_balancing_group: Optional[int] = None,

src/pybind/mgr/dashboard/openapi.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9111,6 +9111,7 @@ paths:
91119111
description: RBD pool name
91129112
type: string
91139113
size:
9114+
default: 1024
91149115
description: RBD image size
91159116
type: integer
91169117
traddr:

src/pybind/mgr/tests/test_ceph_argtypes.py

Lines changed: 0 additions & 144 deletions
This file was deleted.

src/pybind/mgr/tests/test_cli_command.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)