22
22
from sonic_py_common import device_info , multi_asic
23
23
from sonic_py_common .interface import get_interface_table_name , get_port_table_name , get_intf_longname
24
24
from utilities_common import util_base
25
+ from swsscommon import swsscommon
25
26
from swsscommon .swsscommon import SonicV2Connector , ConfigDBConnector
26
27
from utilities_common .db import Db
27
28
from utilities_common .intf_filter import parse_interface_in_filter
@@ -1884,19 +1885,11 @@ def hostname(new_hostname):
1884
1885
1885
1886
config_db = ConfigDBConnector ()
1886
1887
config_db .connect ()
1887
- config_db .mod_entry ('DEVICE_METADATA' , 'localhost' , {"hostname" : new_hostname })
1888
- try :
1889
- command = "service hostname-config restart"
1890
- clicommon .run_command (command , display_cmd = True )
1891
- except SystemExit as e :
1892
- click .echo ("Restarting hostname-config service failed with error {}" .format (e ))
1893
- raise
1888
+ config_db .mod_entry (swsscommon .CFG_DEVICE_METADATA_TABLE_NAME , 'localhost' ,
1889
+ {'hostname' : new_hostname })
1894
1890
1895
- # Reload Monit configuration to pick up new hostname in case it changed
1896
- click .echo ("Reloading Monit configuration ..." )
1897
- clicommon .run_command ("sudo monit reload" )
1898
-
1899
- click .echo ("Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`." )
1891
+ click .echo ('Please note loaded setting will be lost after system reboot. To'
1892
+ ' preserve setting, run `config save`.' )
1900
1893
1901
1894
#
1902
1895
# 'synchronous_mode' command ('config synchronous_mode ...')
@@ -2837,22 +2830,6 @@ def warm_restart_bgp_eoiu(ctx, enable):
2837
2830
db = ctx .obj ['db' ]
2838
2831
db .mod_entry ('WARM_RESTART' , 'bgp' , {'bgp_eoiu' : enable })
2839
2832
2840
- def mvrf_restart_services ():
2841
- """Restart interfaces-config service and NTP service when mvrf is changed"""
2842
- """
2843
- When mvrf is enabled, eth0 should be moved to mvrf; when it is disabled,
2844
- move it back to default vrf. Restarting the "interfaces-config" service
2845
- will recreate the /etc/network/interfaces file and restart the
2846
- "networking" service that takes care of the eth0 movement.
2847
- NTP service should also be restarted to rerun the NTP service with or
2848
- without "cgexec" accordingly.
2849
- """
2850
- cmd = "service ntp stop"
2851
- os .system (cmd )
2852
- cmd = "systemctl restart interfaces-config"
2853
- os .system (cmd )
2854
- cmd = "service ntp start"
2855
- os .system (cmd )
2856
2833
2857
2834
def vrf_add_management_vrf (config_db ):
2858
2835
"""Enable management vrf in config DB"""
@@ -2862,22 +2839,7 @@ def vrf_add_management_vrf(config_db):
2862
2839
click .echo ("ManagementVRF is already Enabled." )
2863
2840
return None
2864
2841
config_db .mod_entry ('MGMT_VRF_CONFIG' , "vrf_global" , {"mgmtVrfEnabled" : "true" })
2865
- mvrf_restart_services ()
2866
- """
2867
- The regular expression for grep in below cmd is to match eth0 line in /proc/net/route, sample file:
2868
- $ cat /proc/net/route
2869
- Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
2870
- eth0 00000000 01803B0A 0003 0 0 202 00000000 0 0 0
2871
- """
2872
- 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"
2873
- proc = subprocess .Popen (cmd , shell = True , stdout = subprocess .PIPE )
2874
- output = proc .communicate ()
2875
- if int (output [0 ]) >= 1 :
2876
- cmd = "ip -4 route del default dev eth0 metric 202"
2877
- proc = subprocess .Popen (cmd , shell = True , stdout = subprocess .PIPE )
2878
- proc .communicate ()
2879
- if proc .returncode != 0 :
2880
- click .echo ("Could not delete eth0 route" )
2842
+
2881
2843
2882
2844
def vrf_delete_management_vrf (config_db ):
2883
2845
"""Disable management vrf in config DB"""
@@ -2887,7 +2849,7 @@ def vrf_delete_management_vrf(config_db):
2887
2849
click .echo ("ManagementVRF is already Disabled." )
2888
2850
return None
2889
2851
config_db .mod_entry ('MGMT_VRF_CONFIG' , "vrf_global" , {"mgmtVrfEnabled" : "false" })
2890
- mvrf_restart_services ()
2852
+
2891
2853
2892
2854
@config .group (cls = clicommon .AbbreviationGroup )
2893
2855
@click .pass_context
@@ -4123,20 +4085,6 @@ def _get_all_mgmtinterface_keys():
4123
4085
config_db .connect ()
4124
4086
return list (config_db .get_table ('MGMT_INTERFACE' ).keys ())
4125
4087
4126
- def mgmt_ip_restart_services ():
4127
- """Restart the required services when mgmt inteface IP address is changed"""
4128
- """
4129
- Whenever the eth0 IP address is changed, restart the "interfaces-config"
4130
- service which regenerates the /etc/network/interfaces file and restarts
4131
- the networking service to make the new/null IP address effective for eth0.
4132
- "ntp-config" service should also be restarted based on the new
4133
- eth0 IP address since the ntp.conf (generated from ntp.conf.j2) is
4134
- made to listen on that particular eth0 IP address or reset it back.
4135
- """
4136
- cmd = "systemctl restart interfaces-config"
4137
- os .system (cmd )
4138
- cmd = "systemctl restart ntp-config"
4139
- os .system (cmd )
4140
4088
4141
4089
#
4142
4090
# 'mtu' subcommand
@@ -4282,7 +4230,6 @@ def add(ctx, interface_name, ip_addr, gw):
4282
4230
config_db .set_entry ("MGMT_INTERFACE" , (interface_name , str (ip_address )), {"NULL" : "NULL" })
4283
4231
else :
4284
4232
config_db .set_entry ("MGMT_INTERFACE" , (interface_name , str (ip_address )), {"gwaddr" : gw })
4285
- mgmt_ip_restart_services ()
4286
4233
4287
4234
return
4288
4235
@@ -4322,7 +4269,6 @@ def remove(ctx, interface_name, ip_addr):
4322
4269
4323
4270
if interface_name == 'eth0' :
4324
4271
config_db .set_entry ("MGMT_INTERFACE" , (interface_name , str (ip_address )), None )
4325
- mgmt_ip_restart_services ()
4326
4272
return
4327
4273
4328
4274
table_name = get_interface_table_name (interface_name )
0 commit comments