-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.py
More file actions
58 lines (48 loc) · 1.61 KB
/
Copy pathdelete.py
File metadata and controls
58 lines (48 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
"""
Delete Command: Used to delete --all-devices or a --single device from Netbox
Usage:
python main.py delete --help
python main.py delete --all-devices --dry-run
python main.py delete --single-device fra-fw-02
python main.py delete -ad
python main.py delete -s fra-fw-02
"""
from typer import Option, Typer, colors, echo, secho
app = Typer(
short_help="delete --all-devices or a --single-device from Netbox. --dry-run available"
)
@app.callback("delete", invoke_without_command=True)
def delete_options(
all_devices: bool = Option(
False,
"--all-devices",
"-a",
help="Delete all devices from Netbox",
),
dry_run: bool = Option(
False,
"--dry-run",
"-d",
help="(Dry-run) Delete all devices from Netbox",
),
single_device: str = Option(
None, "--single-device", "-s", help='Choose a scope: "subnet" OR "devices"'
),
) -> None:
"""Delete all devices or a single device from Netbox. dry-run available"""
if dry_run:
echo("(DRY-RUN): The Devices will NOT be deleted. Ignore the message below:")
if not all_devices and not single_device:
secho(
"ERROR 1: Please use one of the 2 options: --all-devices or --single-device",
fg=colors.RED,
)
exit(1)
if single_device:
echo(f'The device: "{single_device}" has been deleted from Netbox')
exit()
if all_devices:
echo("All devices have been deleted from Netbox")
if __name__ == "__main__":
app()