networka 0.1.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- network_toolkit/__about__.py +4 -0
- network_toolkit/__init__.py +8 -0
- network_toolkit/__main__.py +10 -0
- network_toolkit/builtin_sequences/arista_eos/common.yml +53 -0
- network_toolkit/builtin_sequences/mikrotik_routeros/common.yml +52 -0
- network_toolkit/cli.py +265 -0
- network_toolkit/commands/__init__.py +8 -0
- network_toolkit/commands/backup.py +441 -0
- network_toolkit/commands/complete.py +172 -0
- network_toolkit/commands/config.py +1068 -0
- network_toolkit/commands/diff.py +485 -0
- network_toolkit/commands/download.py +197 -0
- network_toolkit/commands/firmware.py +780 -0
- network_toolkit/commands/info.py +377 -0
- network_toolkit/commands/list.py +345 -0
- network_toolkit/commands/routerboard_upgrade.py +204 -0
- network_toolkit/commands/run.py +839 -0
- network_toolkit/commands/schema_unified.py +91 -0
- network_toolkit/commands/sequence.py +17 -0
- network_toolkit/commands/ssh.py +540 -0
- network_toolkit/commands/ssh_engines.py +0 -0
- network_toolkit/commands/ssh_fallback.py +97 -0
- network_toolkit/commands/ssh_platform.py +120 -0
- network_toolkit/commands/upload.py +237 -0
- network_toolkit/commands/vendor_config_backup.py +378 -0
- network_toolkit/common/color_magic.py +177 -0
- network_toolkit/common/command.py +135 -0
- network_toolkit/common/command_base.py +135 -0
- network_toolkit/common/command_helpers.py +214 -0
- network_toolkit/common/credentials.py +86 -0
- network_toolkit/common/defaults.py +17 -0
- network_toolkit/common/errors.py +130 -0
- network_toolkit/common/interactive_confirmation.py +144 -0
- network_toolkit/common/logging.py +47 -0
- network_toolkit/common/output.py +594 -0
- network_toolkit/common/output_clean.py +244 -0
- network_toolkit/common/paths.py +86 -0
- network_toolkit/common/resolver.py +207 -0
- network_toolkit/common/styles.py +199 -0
- network_toolkit/common/table_generator.py +169 -0
- network_toolkit/common/table_providers.py +716 -0
- network_toolkit/config.py +1506 -0
- network_toolkit/credentials.py +288 -0
- network_toolkit/device.py +1658 -0
- network_toolkit/device_transfers.py +170 -0
- network_toolkit/exceptions.py +78 -0
- network_toolkit/ip_device.py +241 -0
- network_toolkit/platforms/__init__.py +21 -0
- network_toolkit/platforms/base.py +267 -0
- network_toolkit/platforms/cisco_ios/__init__.py +6 -0
- network_toolkit/platforms/cisco_ios/constants.py +15 -0
- network_toolkit/platforms/cisco_ios/operations.py +426 -0
- network_toolkit/platforms/cisco_iosxe/__init__.py +6 -0
- network_toolkit/platforms/cisco_iosxe/constants.py +15 -0
- network_toolkit/platforms/cisco_iosxe/operations.py +580 -0
- network_toolkit/platforms/cisco_shared/__init__.py +0 -0
- network_toolkit/platforms/cisco_shared/operations.py +0 -0
- network_toolkit/platforms/factory.py +190 -0
- network_toolkit/platforms/mikrotik_routeros/__init__.py +8 -0
- network_toolkit/platforms/mikrotik_routeros/confirmation_patterns.py +24 -0
- network_toolkit/platforms/mikrotik_routeros/constants.py +31 -0
- network_toolkit/platforms/mikrotik_routeros/operations.py +686 -0
- network_toolkit/results_enhanced.py +364 -0
- network_toolkit/schemas/__init__.py +8 -0
- network_toolkit/sequence_manager.py +239 -0
- network_toolkit/shell_completion/bash_completion_nw.sh +339 -0
- network_toolkit/shell_completion/zsh_completion_nw.zsh +136 -0
- network_toolkit/transport/__init__.py +15 -0
- network_toolkit/transport/factory.py +113 -0
- network_toolkit/transport/interfaces.py +46 -0
- network_toolkit/transport/nornir_inventory.py +173 -0
- network_toolkit/transport/nornir_netmiko.py +277 -0
- network_toolkit/transport/scrapli_sync.py +36 -0
- network_toolkit/tui/__init__.py +18 -0
- network_toolkit/tui/app.py +1275 -0
- network_toolkit/tui/clipboard.py +46 -0
- network_toolkit/tui/compat.py +111 -0
- network_toolkit/tui/constants.py +111 -0
- network_toolkit/tui/controller.py +550 -0
- network_toolkit/tui/data.py +149 -0
- network_toolkit/tui/dialogs.py +196 -0
- network_toolkit/tui/helpers.py +55 -0
- network_toolkit/tui/keymap.py +31 -0
- network_toolkit/tui/layout.py +111 -0
- network_toolkit/tui/models.py +93 -0
- network_toolkit/tui/output_manager.py +372 -0
- network_toolkit/tui/prompt.py +172 -0
- network_toolkit/tui/services.py +285 -0
- networka-0.1.9.dist-info/METADATA +316 -0
- networka-0.1.9.dist-info/RECORD +93 -0
- networka-0.1.9.dist-info/WHEEL +4 -0
- networka-0.1.9.dist-info/entry_points.txt +2 -0
- networka-0.1.9.dist-info/licenses/LICENSE +73 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
|
2
|
+
"""`nw list` command implementation with subcommands."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import TYPE_CHECKING, Annotated
|
|
8
|
+
|
|
9
|
+
import typer
|
|
10
|
+
|
|
11
|
+
from network_toolkit.common.command_helpers import CommandContext
|
|
12
|
+
from network_toolkit.common.defaults import DEFAULT_CONFIG_PATH
|
|
13
|
+
from network_toolkit.common.logging import setup_logging
|
|
14
|
+
from network_toolkit.common.output import OutputMode
|
|
15
|
+
from network_toolkit.common.table_providers import (
|
|
16
|
+
DeviceListTableProvider,
|
|
17
|
+
GlobalSequencesTableProvider,
|
|
18
|
+
GroupListTableProvider,
|
|
19
|
+
SupportedPlatformsTableProvider,
|
|
20
|
+
TransportTypesTableProvider,
|
|
21
|
+
VendorSequencesTableProvider,
|
|
22
|
+
)
|
|
23
|
+
from network_toolkit.config import NetworkConfig, load_config
|
|
24
|
+
from network_toolkit.exceptions import NetworkToolkitError
|
|
25
|
+
from network_toolkit.sequence_manager import SequenceManager, SequenceRecord
|
|
26
|
+
|
|
27
|
+
if TYPE_CHECKING:
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _list_devices_impl(
|
|
32
|
+
config: NetworkConfig, ctx: CommandContext, *, verbose: bool
|
|
33
|
+
) -> None:
|
|
34
|
+
"""Implementation logic for listing devices."""
|
|
35
|
+
if not config.devices:
|
|
36
|
+
ctx.print_warning("No devices configured")
|
|
37
|
+
return
|
|
38
|
+
|
|
39
|
+
provider = DeviceListTableProvider(config=config)
|
|
40
|
+
ctx.render_table(provider, verbose)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _list_groups_impl(
|
|
44
|
+
config: NetworkConfig, ctx: CommandContext, *, verbose: bool
|
|
45
|
+
) -> None:
|
|
46
|
+
"""Implementation logic for listing groups."""
|
|
47
|
+
if not config.device_groups:
|
|
48
|
+
ctx.print_warning("No device groups configured")
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
provider = GroupListTableProvider(config=config)
|
|
52
|
+
ctx.render_table(provider, verbose)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _list_vendor_sequences_impl(
|
|
56
|
+
vendor: str,
|
|
57
|
+
sequences: dict[str, SequenceRecord],
|
|
58
|
+
category_filter: str | None,
|
|
59
|
+
config: NetworkConfig,
|
|
60
|
+
ctx: CommandContext,
|
|
61
|
+
*,
|
|
62
|
+
verbose: bool = False,
|
|
63
|
+
) -> None:
|
|
64
|
+
"""Implementation logic for listing vendor sequences."""
|
|
65
|
+
if not sequences:
|
|
66
|
+
ctx.print_warning(f"No sequences found for vendor '{vendor}'.")
|
|
67
|
+
return
|
|
68
|
+
|
|
69
|
+
filtered_sequences = {
|
|
70
|
+
name: seq
|
|
71
|
+
for name, seq in sequences.items()
|
|
72
|
+
if category_filter is None or seq.category == category_filter
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if not filtered_sequences:
|
|
76
|
+
ctx.print_warning(f"No sequences found for category '{category_filter}'.")
|
|
77
|
+
return
|
|
78
|
+
|
|
79
|
+
provider = VendorSequencesTableProvider(
|
|
80
|
+
config=config, vendor_filter=vendor, verbose=verbose
|
|
81
|
+
)
|
|
82
|
+
ctx.render_table(provider, verbose)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _show_all_vendor_sequences(
|
|
86
|
+
sequences: dict[str, dict[str, SequenceRecord]],
|
|
87
|
+
category_filter: str | None,
|
|
88
|
+
config: NetworkConfig,
|
|
89
|
+
ctx: CommandContext,
|
|
90
|
+
*,
|
|
91
|
+
verbose: bool = False,
|
|
92
|
+
) -> None:
|
|
93
|
+
"""Show sequences for all vendors."""
|
|
94
|
+
provider = VendorSequencesTableProvider(config=config, verbose=verbose)
|
|
95
|
+
ctx.render_table(provider, verbose)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _show_global_sequences(
|
|
99
|
+
config: NetworkConfig,
|
|
100
|
+
ctx: CommandContext,
|
|
101
|
+
*,
|
|
102
|
+
verbose: bool = False,
|
|
103
|
+
) -> None:
|
|
104
|
+
"""Display global sequences."""
|
|
105
|
+
provider = GlobalSequencesTableProvider(config=config, verbose=verbose)
|
|
106
|
+
ctx.render_table(provider, verbose)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _show_supported_types_impl(ctx: CommandContext, *, verbose: bool) -> None:
|
|
110
|
+
"""Implementation logic for showing supported device types."""
|
|
111
|
+
# Show transport types first
|
|
112
|
+
transport_provider = TransportTypesTableProvider()
|
|
113
|
+
ctx.render_table(transport_provider, verbose=False)
|
|
114
|
+
|
|
115
|
+
ctx.output_manager.print_blank_line()
|
|
116
|
+
|
|
117
|
+
# Show supported device types
|
|
118
|
+
platforms_provider = SupportedPlatformsTableProvider()
|
|
119
|
+
ctx.render_table(platforms_provider, verbose)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _list_sequences_impl(
|
|
123
|
+
config: NetworkConfig,
|
|
124
|
+
ctx: CommandContext,
|
|
125
|
+
vendor: str | None,
|
|
126
|
+
category: str | None,
|
|
127
|
+
*,
|
|
128
|
+
verbose: bool,
|
|
129
|
+
) -> None:
|
|
130
|
+
"""Implementation logic for listing sequences."""
|
|
131
|
+
sm = SequenceManager(config)
|
|
132
|
+
|
|
133
|
+
# Vendor sequences (built-in + repo + user + config)
|
|
134
|
+
if vendor:
|
|
135
|
+
vendor_seqs = sm.list_vendor_sequences(vendor)
|
|
136
|
+
_list_vendor_sequences_impl(
|
|
137
|
+
vendor, vendor_seqs, category, config, ctx, verbose=verbose
|
|
138
|
+
)
|
|
139
|
+
else:
|
|
140
|
+
all_vendor = sm.list_all_sequences()
|
|
141
|
+
if all_vendor:
|
|
142
|
+
_show_all_vendor_sequences(
|
|
143
|
+
all_vendor, category, config, ctx, verbose=verbose
|
|
144
|
+
)
|
|
145
|
+
else:
|
|
146
|
+
ctx.print_warning("No vendor-specific sequences found.")
|
|
147
|
+
|
|
148
|
+
# Show global sequences
|
|
149
|
+
if config.global_command_sequences:
|
|
150
|
+
ctx.output_manager.print_blank_line()
|
|
151
|
+
_show_global_sequences(config, ctx, verbose=verbose)
|
|
152
|
+
else:
|
|
153
|
+
ctx.print_warning("No global sequences found.")
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def register(app: typer.Typer) -> None:
|
|
157
|
+
"""Register the list command group with the Typer app."""
|
|
158
|
+
|
|
159
|
+
# Create the list subcommand group
|
|
160
|
+
list_app = typer.Typer(
|
|
161
|
+
name="list",
|
|
162
|
+
help="List network devices, groups, sequences, and platform information",
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
@list_app.command("devices")
|
|
166
|
+
def devices(
|
|
167
|
+
config_file: Annotated[
|
|
168
|
+
Path, typer.Option("--config", "-c", help="Configuration file path")
|
|
169
|
+
] = DEFAULT_CONFIG_PATH,
|
|
170
|
+
output_mode: Annotated[
|
|
171
|
+
OutputMode | None,
|
|
172
|
+
typer.Option(
|
|
173
|
+
"--output-mode",
|
|
174
|
+
"-o",
|
|
175
|
+
help="Output decoration mode: default, light, dark, no-color, raw",
|
|
176
|
+
show_default=False,
|
|
177
|
+
),
|
|
178
|
+
] = None,
|
|
179
|
+
verbose: Annotated[
|
|
180
|
+
bool, typer.Option("--verbose", "-v", help="Enable verbose logging")
|
|
181
|
+
] = False,
|
|
182
|
+
) -> None:
|
|
183
|
+
"""List all configured network devices."""
|
|
184
|
+
setup_logging("DEBUG" if verbose else "INFO")
|
|
185
|
+
|
|
186
|
+
ctx = CommandContext(
|
|
187
|
+
config_file=config_file,
|
|
188
|
+
verbose=verbose,
|
|
189
|
+
output_mode=output_mode,
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
try:
|
|
193
|
+
config = load_config(config_file)
|
|
194
|
+
|
|
195
|
+
if not config.devices:
|
|
196
|
+
ctx.print_warning("No devices configured.")
|
|
197
|
+
return
|
|
198
|
+
|
|
199
|
+
# Use the local implementation
|
|
200
|
+
_list_devices_impl(config, ctx, verbose=verbose)
|
|
201
|
+
|
|
202
|
+
except NetworkToolkitError as e:
|
|
203
|
+
ctx.print_error(str(e))
|
|
204
|
+
if verbose and e.details:
|
|
205
|
+
ctx.print_error(f"Details: {e.details}")
|
|
206
|
+
raise typer.Exit(1) from None
|
|
207
|
+
except typer.Exit:
|
|
208
|
+
# Allow clean exits (e.g., user cancellation) to pass through
|
|
209
|
+
raise
|
|
210
|
+
except Exception as e: # pragma: no cover - unexpected
|
|
211
|
+
ctx.print_error(f"Unexpected error: {e}")
|
|
212
|
+
raise typer.Exit(1) from None
|
|
213
|
+
|
|
214
|
+
@list_app.command("groups")
|
|
215
|
+
def groups(
|
|
216
|
+
config_file: Annotated[
|
|
217
|
+
Path, typer.Option("--config", "-c", help="Configuration file path")
|
|
218
|
+
] = DEFAULT_CONFIG_PATH,
|
|
219
|
+
output_mode: Annotated[
|
|
220
|
+
OutputMode | None,
|
|
221
|
+
typer.Option(
|
|
222
|
+
"--output-mode",
|
|
223
|
+
"-o",
|
|
224
|
+
help="Output decoration mode: default, light, dark, no-color, raw",
|
|
225
|
+
show_default=False,
|
|
226
|
+
),
|
|
227
|
+
] = None,
|
|
228
|
+
verbose: Annotated[
|
|
229
|
+
bool, typer.Option("--verbose", "-v", help="Show detailed information")
|
|
230
|
+
] = False,
|
|
231
|
+
) -> None:
|
|
232
|
+
"""List all configured device groups and their members."""
|
|
233
|
+
setup_logging("DEBUG" if verbose else "INFO")
|
|
234
|
+
|
|
235
|
+
ctx = CommandContext(
|
|
236
|
+
config_file=config_file,
|
|
237
|
+
verbose=verbose,
|
|
238
|
+
output_mode=output_mode,
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
try:
|
|
242
|
+
config = load_config(config_file)
|
|
243
|
+
|
|
244
|
+
if not config.device_groups:
|
|
245
|
+
ctx.print_warning("No device groups configured.")
|
|
246
|
+
return
|
|
247
|
+
|
|
248
|
+
# Use the local implementation
|
|
249
|
+
_list_groups_impl(config, ctx, verbose=verbose)
|
|
250
|
+
|
|
251
|
+
except NetworkToolkitError as e:
|
|
252
|
+
ctx.print_error(str(e))
|
|
253
|
+
if verbose and e.details:
|
|
254
|
+
ctx.print_error(f"Details: {e.details}")
|
|
255
|
+
raise typer.Exit(1) from None
|
|
256
|
+
except typer.Exit:
|
|
257
|
+
# Allow clean exits (e.g., user cancellation) to pass through
|
|
258
|
+
raise
|
|
259
|
+
except Exception as e: # pragma: no cover - unexpected
|
|
260
|
+
ctx.print_error(f"Unexpected error: {e}")
|
|
261
|
+
raise typer.Exit(1) from None
|
|
262
|
+
|
|
263
|
+
@list_app.command("sequences")
|
|
264
|
+
def sequences(
|
|
265
|
+
config_file: Annotated[
|
|
266
|
+
Path, typer.Option("--config", "-c", help="Configuration file path")
|
|
267
|
+
] = DEFAULT_CONFIG_PATH,
|
|
268
|
+
vendor: Annotated[
|
|
269
|
+
str | None,
|
|
270
|
+
typer.Option("--vendor", "-v", help="Filter by vendor platform"),
|
|
271
|
+
] = None,
|
|
272
|
+
category: Annotated[
|
|
273
|
+
str | None,
|
|
274
|
+
typer.Option("--category", help="Filter by sequence category"),
|
|
275
|
+
] = None,
|
|
276
|
+
output_mode: Annotated[
|
|
277
|
+
OutputMode | None,
|
|
278
|
+
typer.Option(
|
|
279
|
+
"--output-mode",
|
|
280
|
+
"-o",
|
|
281
|
+
help="Output decoration mode: default, light, dark, no-color, raw",
|
|
282
|
+
show_default=False,
|
|
283
|
+
),
|
|
284
|
+
] = None,
|
|
285
|
+
verbose: Annotated[
|
|
286
|
+
bool, typer.Option("--verbose", help="Show detailed information")
|
|
287
|
+
] = False,
|
|
288
|
+
) -> None:
|
|
289
|
+
"""List all available command sequences, optionally filtered by vendor
|
|
290
|
+
or category."""
|
|
291
|
+
setup_logging("DEBUG" if verbose else "INFO")
|
|
292
|
+
|
|
293
|
+
ctx = CommandContext(
|
|
294
|
+
config_file=config_file,
|
|
295
|
+
verbose=verbose,
|
|
296
|
+
output_mode=output_mode,
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
try:
|
|
300
|
+
config = load_config(config_file)
|
|
301
|
+
|
|
302
|
+
# Use the local implementation
|
|
303
|
+
_list_sequences_impl(config, ctx, vendor, category, verbose=verbose)
|
|
304
|
+
|
|
305
|
+
except NetworkToolkitError as e:
|
|
306
|
+
ctx.print_error(str(e))
|
|
307
|
+
if verbose and e.details:
|
|
308
|
+
ctx.print_error(f"Details: {e.details}")
|
|
309
|
+
raise typer.Exit(1) from None
|
|
310
|
+
except typer.Exit:
|
|
311
|
+
# Allow clean exits (e.g., user cancellation) to pass through
|
|
312
|
+
raise
|
|
313
|
+
except Exception as e: # pragma: no cover - unexpected
|
|
314
|
+
ctx.print_error(f"Unexpected error: {e}")
|
|
315
|
+
raise typer.Exit(1) from None
|
|
316
|
+
|
|
317
|
+
@list_app.command("supported-types")
|
|
318
|
+
def supported_types(
|
|
319
|
+
verbose: Annotated[
|
|
320
|
+
bool, typer.Option("--verbose", "-v", help="Show detailed information")
|
|
321
|
+
] = False,
|
|
322
|
+
) -> None:
|
|
323
|
+
"""Show supported device types and platform information."""
|
|
324
|
+
setup_logging("DEBUG" if verbose else "INFO")
|
|
325
|
+
|
|
326
|
+
ctx = CommandContext()
|
|
327
|
+
|
|
328
|
+
try:
|
|
329
|
+
# Use the local implementation
|
|
330
|
+
_show_supported_types_impl(ctx, verbose=verbose)
|
|
331
|
+
|
|
332
|
+
except NetworkToolkitError as e:
|
|
333
|
+
ctx.print_error(str(e))
|
|
334
|
+
if verbose and e.details:
|
|
335
|
+
ctx.print_error(f"Details: {e.details}")
|
|
336
|
+
raise typer.Exit(1) from None
|
|
337
|
+
except typer.Exit:
|
|
338
|
+
# Allow clean exits (e.g., user cancellation) to pass through
|
|
339
|
+
raise
|
|
340
|
+
except Exception as e: # pragma: no cover - unexpected
|
|
341
|
+
ctx.print_error(f"Unexpected error: {e}")
|
|
342
|
+
raise typer.Exit(1) from None
|
|
343
|
+
|
|
344
|
+
# Register the list command group with the main app
|
|
345
|
+
app.add_typer(list_app, name="list", rich_help_panel="Info & Configuration")
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
|
2
|
+
"""`nw routerboard-upgrade` command implementation (device or group).
|
|
3
|
+
|
|
4
|
+
Platform-agnostic BIOS/firmware upgrade using vendor-specific implementations.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from importlib import import_module
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Annotated, Any, cast
|
|
12
|
+
|
|
13
|
+
import typer
|
|
14
|
+
|
|
15
|
+
from network_toolkit.common.command_helpers import CommandContext
|
|
16
|
+
from network_toolkit.common.defaults import DEFAULT_CONFIG_PATH
|
|
17
|
+
|
|
18
|
+
# For backward compatibility with tests
|
|
19
|
+
from network_toolkit.common.logging import setup_logging
|
|
20
|
+
from network_toolkit.config import load_config
|
|
21
|
+
from network_toolkit.exceptions import NetworkToolkitError
|
|
22
|
+
from network_toolkit.platforms import UnsupportedOperationError, get_platform_operations
|
|
23
|
+
|
|
24
|
+
MAX_LIST_PREVIEW = 10
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def register(app: typer.Typer) -> None:
|
|
28
|
+
@app.command(rich_help_panel="Remote Operations")
|
|
29
|
+
def routerboard_upgrade( # pyright: ignore[reportUnusedFunction]
|
|
30
|
+
target_name: Annotated[
|
|
31
|
+
str,
|
|
32
|
+
typer.Argument(
|
|
33
|
+
help="Device or group name from configuration",
|
|
34
|
+
metavar="<device|group>",
|
|
35
|
+
),
|
|
36
|
+
],
|
|
37
|
+
*,
|
|
38
|
+
precheck_sequence: Annotated[
|
|
39
|
+
str,
|
|
40
|
+
typer.Option(
|
|
41
|
+
"--precheck-sequence",
|
|
42
|
+
help=("Sequence to run before upgrade (default: 'pre_maintenance')"),
|
|
43
|
+
),
|
|
44
|
+
] = "pre_maintenance",
|
|
45
|
+
skip_precheck: Annotated[
|
|
46
|
+
bool,
|
|
47
|
+
typer.Option(
|
|
48
|
+
"--skip-precheck/--no-skip-precheck",
|
|
49
|
+
help="Skip running precheck sequence",
|
|
50
|
+
),
|
|
51
|
+
] = False,
|
|
52
|
+
config_file: Annotated[
|
|
53
|
+
Path, typer.Option("--config", "-c", help="Configuration file path")
|
|
54
|
+
] = DEFAULT_CONFIG_PATH,
|
|
55
|
+
verbose: Annotated[
|
|
56
|
+
bool, typer.Option("--verbose", "-v", help="Enable verbose output")
|
|
57
|
+
] = False,
|
|
58
|
+
) -> None:
|
|
59
|
+
"""Upgrade device BIOS/RouterBOOT and reboot to apply.
|
|
60
|
+
|
|
61
|
+
Uses platform-specific implementations to handle vendor differences
|
|
62
|
+
in BIOS upgrade procedures.
|
|
63
|
+
"""
|
|
64
|
+
setup_logging("DEBUG" if verbose else "INFO")
|
|
65
|
+
|
|
66
|
+
# ACTION command - use global config theme
|
|
67
|
+
ctx = CommandContext(
|
|
68
|
+
config_file=config_file,
|
|
69
|
+
verbose=verbose,
|
|
70
|
+
output_mode=None, # Use global config theme
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
try:
|
|
74
|
+
config = load_config(config_file)
|
|
75
|
+
|
|
76
|
+
module = import_module("network_toolkit.cli")
|
|
77
|
+
device_session = cast(Any, module).DeviceSession
|
|
78
|
+
|
|
79
|
+
devices = config.devices or {}
|
|
80
|
+
groups = config.device_groups or {}
|
|
81
|
+
is_device = target_name in devices
|
|
82
|
+
is_group = target_name in groups
|
|
83
|
+
|
|
84
|
+
if not (is_device or is_group):
|
|
85
|
+
ctx.print_error(
|
|
86
|
+
f"Error: '{target_name}' not found as device or group in configuration"
|
|
87
|
+
)
|
|
88
|
+
if devices:
|
|
89
|
+
dev_names = sorted(devices.keys())
|
|
90
|
+
preview = ", ".join(dev_names[:MAX_LIST_PREVIEW])
|
|
91
|
+
if len(dev_names) > MAX_LIST_PREVIEW:
|
|
92
|
+
preview += " ..."
|
|
93
|
+
ctx.print_info("Known devices: " + preview)
|
|
94
|
+
if groups:
|
|
95
|
+
grp_names = sorted(groups.keys())
|
|
96
|
+
preview = ", ".join(grp_names[:MAX_LIST_PREVIEW])
|
|
97
|
+
if len(grp_names) > MAX_LIST_PREVIEW:
|
|
98
|
+
preview += " ..."
|
|
99
|
+
ctx.print_info("Known groups: " + preview)
|
|
100
|
+
raise typer.Exit(1)
|
|
101
|
+
|
|
102
|
+
def process_device(dev: str) -> bool:
|
|
103
|
+
try:
|
|
104
|
+
with device_session(dev, config) as session:
|
|
105
|
+
# Get platform-specific operations
|
|
106
|
+
try:
|
|
107
|
+
platform_ops = get_platform_operations(session)
|
|
108
|
+
except UnsupportedOperationError as e:
|
|
109
|
+
ctx.print_error(f"Error on {dev}: {e}")
|
|
110
|
+
return False
|
|
111
|
+
|
|
112
|
+
if precheck_sequence and not skip_precheck:
|
|
113
|
+
ctx.print_info(
|
|
114
|
+
f"Running precheck sequence '{precheck_sequence}' on {dev}"
|
|
115
|
+
)
|
|
116
|
+
seq_cmds: list[str] = []
|
|
117
|
+
dcfg = (config.devices or {}).get(dev)
|
|
118
|
+
if (
|
|
119
|
+
dcfg
|
|
120
|
+
and dcfg.command_sequences
|
|
121
|
+
and precheck_sequence in dcfg.command_sequences
|
|
122
|
+
):
|
|
123
|
+
seq_cmds = dcfg.command_sequences[precheck_sequence]
|
|
124
|
+
elif (
|
|
125
|
+
config.global_command_sequences
|
|
126
|
+
and precheck_sequence in config.global_command_sequences
|
|
127
|
+
):
|
|
128
|
+
seq_cmds = config.global_command_sequences[
|
|
129
|
+
precheck_sequence
|
|
130
|
+
].commands
|
|
131
|
+
|
|
132
|
+
for cmd in seq_cmds:
|
|
133
|
+
session.execute_command(cmd)
|
|
134
|
+
|
|
135
|
+
ctx.print_warning(
|
|
136
|
+
f"Upgrading BIOS/RouterBOOT on {dev} and rebooting..."
|
|
137
|
+
)
|
|
138
|
+
try:
|
|
139
|
+
platform_name_obj = platform_ops.get_platform_name()
|
|
140
|
+
platform_name = str(platform_name_obj)
|
|
141
|
+
except Exception: # pragma: no cover - defensive
|
|
142
|
+
platform_name = "unknown"
|
|
143
|
+
ctx.print_info(f"Platform: {platform_name}")
|
|
144
|
+
|
|
145
|
+
# Use platform-specific BIOS upgrade
|
|
146
|
+
ok = platform_ops.bios_upgrade()
|
|
147
|
+
if ok:
|
|
148
|
+
ctx.print_success(
|
|
149
|
+
f"OK BIOS upgrade scheduled; device rebooting: {dev}"
|
|
150
|
+
)
|
|
151
|
+
return True
|
|
152
|
+
ctx.print_error(f"FAIL BIOS upgrade failed to start on {dev}")
|
|
153
|
+
return False
|
|
154
|
+
except NetworkToolkitError as e:
|
|
155
|
+
ctx.print_error(f"Error on {dev}: {e.message}")
|
|
156
|
+
if verbose and e.details:
|
|
157
|
+
ctx.print_error(f"Details: {e.details}")
|
|
158
|
+
return False
|
|
159
|
+
except Exception as e: # pragma: no cover - unexpected
|
|
160
|
+
ctx.print_error(f"Unexpected error on {dev}: {e}")
|
|
161
|
+
return False
|
|
162
|
+
|
|
163
|
+
if is_device:
|
|
164
|
+
ok = process_device(target_name)
|
|
165
|
+
if not ok:
|
|
166
|
+
raise typer.Exit(1)
|
|
167
|
+
return
|
|
168
|
+
|
|
169
|
+
members: list[str] = []
|
|
170
|
+
try:
|
|
171
|
+
members = config.get_group_members(target_name)
|
|
172
|
+
except Exception:
|
|
173
|
+
grp = groups.get(target_name)
|
|
174
|
+
if grp and getattr(grp, "members", None):
|
|
175
|
+
members = grp.members or []
|
|
176
|
+
|
|
177
|
+
if not members:
|
|
178
|
+
ctx.print_error(f"Error: No devices found in group '{target_name}'")
|
|
179
|
+
raise typer.Exit(1)
|
|
180
|
+
|
|
181
|
+
ctx.print_info(
|
|
182
|
+
f"Starting RouterBOARD upgrade for group '{target_name}' ({len(members)} devices)"
|
|
183
|
+
)
|
|
184
|
+
failures = 0
|
|
185
|
+
for dev in members:
|
|
186
|
+
ok = process_device(dev)
|
|
187
|
+
failures += 0 if ok else 1
|
|
188
|
+
|
|
189
|
+
total = len(members)
|
|
190
|
+
# Keep summary formatting consistent with other commands
|
|
191
|
+
ctx.output_manager.print_info(
|
|
192
|
+
f"Completed: {total - failures}/{total} initiated"
|
|
193
|
+
)
|
|
194
|
+
if failures:
|
|
195
|
+
raise typer.Exit(1)
|
|
196
|
+
|
|
197
|
+
except NetworkToolkitError as e:
|
|
198
|
+
ctx.print_error(f"Error: {e.message}")
|
|
199
|
+
if verbose and e.details:
|
|
200
|
+
ctx.print_error(f"Details: {e.details}")
|
|
201
|
+
raise typer.Exit(1) from None
|
|
202
|
+
except Exception as e: # pragma: no cover - unexpected
|
|
203
|
+
ctx.print_error(f"Unexpected error: {e}")
|
|
204
|
+
raise typer.Exit(1) from None
|