1
1
from .cli import Flag , cli
2
+ from .exceptions import CliWarning
2
3
from .history import history
3
- from .log import cli_error , cli_info , cli_warning
4
- from .util import (
5
- format_mac ,
6
- get_list ,
7
- host_info_by_name ,
8
- is_valid_ip ,
9
- is_valid_mac ,
10
- patch ,
11
- )
4
+ from .log import cli_info , cli_warning
5
+ from .util import format_mac , get_list , host_info_by_name , is_valid_ip , is_valid_mac , patch
12
6
13
7
#################################
14
8
# Add the main command 'dhcp' #
@@ -45,7 +39,11 @@ def _dhcp_get_ip_by_arg(arg):
45
39
)
46
40
)
47
41
if len (info ["ipaddresses" ]) == 0 :
48
- cli_error ("{} doesn't have any ip addresses." .format (arg ))
42
+ cli_warning (
43
+ "{} doesn't have any ip addresses." .format (arg ),
44
+ raise_exception = True ,
45
+ exception = CliWarning ,
46
+ )
49
47
ip = info ["ipaddresses" ][0 ]
50
48
return ip
51
49
@@ -64,8 +62,7 @@ def assoc_mac_to_ip(mac, ip, force=False):
64
62
ips = ", " .join ([i ["ipaddress" ] for i in macs ])
65
63
if len (macs ) and not force :
66
64
cli_warning (
67
- "mac {} already in use by: {}. "
68
- "Use force to add {} -> {} as well." .format (
65
+ "mac {} already in use by: {}. Use force to add {} -> {} as well." .format (
69
66
mac , ips , ip ["ipaddress" ], mac
70
67
)
71
68
)
@@ -78,9 +75,7 @@ def assoc_mac_to_ip(mac, ip, force=False):
78
75
return
79
76
elif old_mac and not force :
80
77
cli_warning (
81
- "ip {} has existing mac {}. Use force to replace." .format (
82
- ip ["ipaddress" ], old_mac
83
- )
78
+ "ip {} has existing mac {}. Use force to replace." .format (ip ["ipaddress" ], old_mac )
84
79
)
85
80
86
81
# Update Ipaddress with a mac
@@ -141,9 +136,7 @@ def disassoc(args):
141
136
history .record_patch (path , new_data = {"macaddress" : "" }, old_data = ip )
142
137
patch (path , macaddress = "" )
143
138
cli_info (
144
- "disassociated mac address {} from ip {}" .format (
145
- ip ["macaddress" ], ip ["ipaddress" ]
146
- ),
139
+ "disassociated mac address {} from ip {}" .format (ip ["macaddress" ], ip ["ipaddress" ]),
147
140
print_msg = True ,
148
141
)
149
142
else :
0 commit comments