Skip to content

Commit 26866a2

Browse files
committed
Move mgmt handling to hostcfgd
Signed-off-by: Yevhen Fastiuk <[email protected]>
1 parent 39cb45c commit 26866a2

File tree

1 file changed

+2
-49
lines changed

1 file changed

+2
-49
lines changed

config/main.py

+2-49
Original file line numberDiff line numberDiff line change
@@ -2820,22 +2820,6 @@ def warm_restart_bgp_eoiu(ctx, enable):
28202820
db = ctx.obj['db']
28212821
db.mod_entry('WARM_RESTART', 'bgp', {'bgp_eoiu': enable})
28222822

2823-
def mvrf_restart_services():
2824-
"""Restart interfaces-config service and NTP service when mvrf is changed"""
2825-
"""
2826-
When mvrf is enabled, eth0 should be moved to mvrf; when it is disabled,
2827-
move it back to default vrf. Restarting the "interfaces-config" service
2828-
will recreate the /etc/network/interfaces file and restart the
2829-
"networking" service that takes care of the eth0 movement.
2830-
NTP service should also be restarted to rerun the NTP service with or
2831-
without "cgexec" accordingly.
2832-
"""
2833-
cmd="service ntp stop"
2834-
os.system (cmd)
2835-
cmd="systemctl restart interfaces-config"
2836-
os.system (cmd)
2837-
cmd="service ntp start"
2838-
os.system (cmd)
28392823

28402824
def vrf_add_management_vrf(config_db):
28412825
"""Enable management vrf in config DB"""
@@ -2845,22 +2829,7 @@ def vrf_add_management_vrf(config_db):
28452829
click.echo("ManagementVRF is already Enabled.")
28462830
return None
28472831
config_db.mod_entry('MGMT_VRF_CONFIG', "vrf_global", {"mgmtVrfEnabled": "true"})
2848-
mvrf_restart_services()
2849-
"""
2850-
The regular expression for grep in below cmd is to match eth0 line in /proc/net/route, sample file:
2851-
$ cat /proc/net/route
2852-
Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
2853-
eth0 00000000 01803B0A 0003 0 0 202 00000000 0 0 0
2854-
"""
2855-
cmd = r"cat /proc/net/route | grep -E \"eth0\s+00000000\s+[0-9A-Z]+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+202\" | wc -l"
2856-
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
2857-
output = proc.communicate()
2858-
if int(output[0]) >= 1:
2859-
cmd="ip -4 route del default dev eth0 metric 202"
2860-
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
2861-
proc.communicate()
2862-
if proc.returncode != 0:
2863-
click.echo("Could not delete eth0 route")
2832+
28642833

28652834
def vrf_delete_management_vrf(config_db):
28662835
"""Disable management vrf in config DB"""
@@ -2870,7 +2839,7 @@ def vrf_delete_management_vrf(config_db):
28702839
click.echo("ManagementVRF is already Disabled.")
28712840
return None
28722841
config_db.mod_entry('MGMT_VRF_CONFIG', "vrf_global", {"mgmtVrfEnabled": "false"})
2873-
mvrf_restart_services()
2842+
28742843

28752844
@config.group(cls=clicommon.AbbreviationGroup)
28762845
@click.pass_context
@@ -4106,20 +4075,6 @@ def _get_all_mgmtinterface_keys():
41064075
config_db.connect()
41074076
return list(config_db.get_table('MGMT_INTERFACE').keys())
41084077

4109-
def mgmt_ip_restart_services():
4110-
"""Restart the required services when mgmt inteface IP address is changed"""
4111-
"""
4112-
Whenever the eth0 IP address is changed, restart the "interfaces-config"
4113-
service which regenerates the /etc/network/interfaces file and restarts
4114-
the networking service to make the new/null IP address effective for eth0.
4115-
"ntp-config" service should also be restarted based on the new
4116-
eth0 IP address since the ntp.conf (generated from ntp.conf.j2) is
4117-
made to listen on that particular eth0 IP address or reset it back.
4118-
"""
4119-
cmd="systemctl restart interfaces-config"
4120-
os.system (cmd)
4121-
cmd="systemctl restart ntp-config"
4122-
os.system (cmd)
41234078

41244079
#
41254080
# 'mtu' subcommand
@@ -4267,7 +4222,6 @@ def add(ctx, interface_name, ip_addr, gw):
42674222
config_db.set_entry("MGMT_INTERFACE", (interface_name, str(ip_address)), {"NULL": "NULL"})
42684223
else:
42694224
config_db.set_entry("MGMT_INTERFACE", (interface_name, str(ip_address)), {"gwaddr": gw})
4270-
mgmt_ip_restart_services()
42714225

42724226
return
42734227

@@ -4307,7 +4261,6 @@ def remove(ctx, interface_name, ip_addr):
43074261

43084262
if interface_name == 'eth0':
43094263
config_db.set_entry("MGMT_INTERFACE", (interface_name, str(ip_address)), None)
4310-
mgmt_ip_restart_services()
43114264
return
43124265

43134266
table_name = get_interface_table_name(interface_name)

0 commit comments

Comments
 (0)