Skip to content

Commit 8b3b405

Browse files
committed
Updated cli.py and yaml
1 parent 3d4addc commit 8b3b405

6 files changed

Lines changed: 62 additions & 25 deletions

File tree

simplyblock_cli/cli-reference-schema.yaml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,28 @@ properties:
295295
x-intellij-html-description: |
296296
The action value parameter. <b>Positional arguments cannot have actions.</b>
297297
choices:
298-
type: array
299-
description: The valid choices of the positional argument or parameter.
300-
x-intellij-html-description: The valid choices of the positional argument or parameter.
301-
items:
302-
minItems: 2
303-
oneOf:
304-
- type: string
305-
- type: integer
298+
type: array
299+
description: The valid choices of the positional argument or parameter.
300+
x-intellij-html-description: The valid choices of the positional argument or parameter.
301+
items:
302+
minItems: 2
303+
oneOf:
304+
- type: string
305+
- type: integer
306+
deprecated:
307+
type: object
308+
required:
309+
- since
310+
properties:
311+
replaced-by:
312+
type: string
313+
description: The replacement of the parameter.
314+
x-intellij-html-description: The replacement of the parameter.
315+
since:
316+
type: string
317+
description: The version of the parameter which deprecates the replacement.
318+
x-intellij-html-description: The version of the parameter which deprecates the replacement.
319+
migration:
320+
type: string
321+
description: The migration function which migrates the old value to the new value..
322+
x-intellij-html-description: The migration function which migrates the old value to the new value.

simplyblock_cli/cli-reference.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ commands:
159159
dest: ifname
160160
type: str
161161
- name: "--journal-partition"
162+
deprecated:
163+
since: "26.1"
164+
replaced-by: "--enable-journal-device"
165+
migration: "migrate_journal_partition"
162166
help: |
163-
**Deprecated:** use `--enable-journal-device` instead.
164-
165-
1: Auto-create small partitions for journal on nvme devices. 0: use a separate (the smallest) nvme device of the node for journal. The journal needs a maximum of 3 percent of total available raw disk space. Default: `1`.
167+
1: auto-create small partitions for journal on nvme devices. 0: use a separate (the smallest) nvme device of the node for journal. The journal needs a maximum of 3% of total available raw disk space."
166168
dest: partitions
167169
type: int
168170
choices:

simplyblock_cli/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def init_storage_node__add_node(self, subparser):
122122
subcommand.add_argument('cluster_id', help='The cluster id.', type=str)
123123
subcommand.add_argument('node_addr', help='Address of storage node api to add, like <node-ip>:5000.', type=str)
124124
subcommand.add_argument('ifname', help='The management interface name.', type=str)
125-
argument = subcommand.add_argument('--journal-partition', help='**Deprecated:** use `--enable-journal-device` instead.1: Auto-create small partitions for journal on nvme devices. 0: use a separate (the smallest) nvme device of the node for journal. The journal needs a maximum of 3 percent of total available raw disk space. Default: `1`.', type=int, dest='partitions', choices=[0,1,])
125+
argument = subcommand.add_argument('--journal-partition', help='**Deprecated since: 26.1** Replaced by: --enable-journal-device\n\n1: auto-create small partitions for journal on nvme devices. 0: use a separate (the smallest) nvme device of the node for journal. The journal needs a maximum of 3%% of total available raw disk space."', type=int, dest='partitions', choices=[0,1,])
126126
argument = subcommand.add_argument('--enable-journal-device', help='Enables the use of a separate (the smallest) NVMe device of the node for the journal. Otherwise, the journal uses a maximum of 3%% of total available raw disk space across all NVMe devices.', default=False, dest='enable_journal_device', action='store_true')
127127
argument = subcommand.add_argument('--format-4k', help='Force format nvme devices with 4K.', dest='format_4k', action='store_true')
128128
if self.developer_mode:
@@ -1094,6 +1094,7 @@ def run(self):
10941094
args.id_device_by_nqn = False
10951095
args.max_snap = 5000
10961096
args.spdk_proxy_image = None
1097+
args = self.migrate_journal_partition(args)
10971098
ret = self.storage_node__add_node(sub_command, args)
10981099
elif sub_command in ['delete']:
10991100
ret = self.storage_node__delete(sub_command, args)

simplyblock_cli/clibase.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,7 @@ def storage_node__add_node(self, sub_command, args):
161161
namespace = args.namespace
162162
ha_jm_count = args.ha_jm_count
163163
format_4k = args.format_4k
164-
165-
if args.enable_journal_device:
166-
num_partitions_per_dev = 0
167-
else:
168-
# Deprecated but still supported for backward compatibility.
169-
if args.partitions is None:
170-
num_partitions_per_dev = 1
171-
elif args.partitions < 0 or args.partitions > 1:
172-
self.parser.error("partitions must be either 0 or 1")
173-
else:
174-
print("WARNING: --journal-partition is deprecated, use --enable-journal-device instead")
175-
num_partitions_per_dev = args.partitions
164+
num_partitions_per_dev = 0 if args.enable_journal_device else 1
176165

177166
try:
178167
out = storage_ops.add_node(
@@ -1118,3 +1107,11 @@ def _completer_get_cluster_list(self, prefix, parsed_args, **kwargs):
11181107
def _completer_get_sn_list(self, prefix, parsed_args, **kwargs):
11191108
db = db_controller.DBController()
11201109
return (cluster.get_id() for cluster in db.get_storage_nodes() if cluster.get_id().startswith(prefix))
1110+
1111+
def migrate_journal_partition(self, args):
1112+
if args.partitions < 0 or args.partitions > 1:
1113+
self.parser.error("partitions must be either 0 or 1")
1114+
else:
1115+
args.enable_journal_device = True
1116+
del args.partitions
1117+
return args

simplyblock_cli/scripts/cli-wrapper-gen.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ def escape_strings(text):
6565
return text
6666

6767

68+
def apply_deprecated_warning(item):
69+
deprecated = item.get("deprecated")
70+
if not deprecated:
71+
return ""
72+
73+
since = deprecated.get("since")
74+
replaced_by = deprecated.get("replaced-by")
75+
76+
if not since:
77+
raise ValueError("deprecated item must have a since")
78+
79+
return f"**Deprecated since: {since}**{ '' if not replaced_by else f' Replaced by: {replaced_by}'}" + "\\n\\n"
80+
81+
6882
def make_identifier(name):
6983
if name.startswith("--"):
7084
name = name[2:]
@@ -154,6 +168,7 @@ def nargs(item):
154168
environment.filters["get_description"] = get_description
155169
environment.filters["escape_strings"] = escape_strings
156170
environment.filters["make_identifier"] = make_identifier
171+
environment.filters["apply_deprecated_warning"] = apply_deprecated_warning
157172
environment.filters["bool_value"] = bool_value
158173
environment.filters["escape_python_string"] = escape_python_string
159174
environment.filters["nargs"] = nargs

simplyblock_cli/scripts/cli-wrapper.jinja2

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class CLIWrapper(CLIWrapperBase):
7878
, '{{ alias }}'
7979
{%- endfor -%}
8080
{%- endif -%}
81-
, help='{{ parameter.help | escape_strings | escape_python_string }}'
81+
, help='{{ parameter | apply_deprecated_warning }}{{ parameter.help | escape_strings | escape_python_string }}'
8282
{%- if parameter.type is defined and parameter.action is undefined %}, type={{ parameter.type | argument_type }}{% endif %}
8383
{%- if parameter.default is defined %}, default={{ parameter | default_value }}{% endif %}
8484
{%- if parameter.dest is defined %}, dest='{{ parameter.dest }}'{% endif %}
@@ -137,6 +137,11 @@ class CLIWrapper(CLIWrapperBase):
137137
args.{{ parameter.dest }} = {{ parameter | default_value }}
138138
{%- endif -%}
139139
{%- endfor -%}
140+
{%- for parameter in subcommand.parameters -%}
141+
{%- if parameter.deprecated is defined and parameter.deprecated.migration is defined %}
142+
args = self.{{ parameter.deprecated.migration }}(args)
143+
{%- endif %}
144+
{%- endfor -%}
140145
{%- if subcommand.private %}
141146
if not self.developer_mode:
142147
print("This command is private.")

0 commit comments

Comments
 (0)