Skip to content

Commit 688c594

Browse files
authored
Handle lack of IP address when using dhcp assoc
Fixes #175
1 parent c043fa6 commit 688c594

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

ci/testsuite-result.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9841,7 +9841,7 @@
98419841
}
98429842
},
98439843
{
9844-
"output": "ERROR: : foo doesn't have any ip addresses."
9844+
"output": "WARNING: : foo doesn't have any ip addresses."
98459845
},
98469846
{
98479847
"command": "host remove foo\n"

mreg_cli/dhcp.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
from .cli import Flag, cli
2+
from .exceptions import CliWarning
23
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
126

137
#################################
148
# Add the main command 'dhcp' #
@@ -45,7 +39,11 @@ def _dhcp_get_ip_by_arg(arg):
4539
)
4640
)
4741
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+
)
4947
ip = info["ipaddresses"][0]
5048
return ip
5149

@@ -64,8 +62,7 @@ def assoc_mac_to_ip(mac, ip, force=False):
6462
ips = ", ".join([i["ipaddress"] for i in macs])
6563
if len(macs) and not force:
6664
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(
6966
mac, ips, ip["ipaddress"], mac
7067
)
7168
)
@@ -78,9 +75,7 @@ def assoc_mac_to_ip(mac, ip, force=False):
7875
return
7976
elif old_mac and not force:
8077
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)
8479
)
8580

8681
# Update Ipaddress with a mac
@@ -141,9 +136,7 @@ def disassoc(args):
141136
history.record_patch(path, new_data={"macaddress": ""}, old_data=ip)
142137
patch(path, macaddress="")
143138
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"]),
147140
print_msg=True,
148141
)
149142
else:

0 commit comments

Comments
 (0)