Skip to content

Commit 913a62c

Browse files
rodnymolinalguohan
authored andcommitted
[configdb]: Sorting all json config-elements residing in config_db.json (#1454)
Just a simple change to make sonic's user life a little bit easier. Displaying the multiple elements of config_db.json in an orderly fashion allows a more intuitive user-experience. For this change i'm simply intercepting the config-state that is about to be dumped to config_db.json, and i'm placing it in an ordered-dictionary, so that information is pushed to file in natural/alphanumerical ordering. Example: admin@lnos-x1-a-csw01:~$ sudo sonic-cfggen -m /etc/sonic/minigraph.xml --print-data { ... "PORT": { "Ethernet0": { "alias": "Eth1/1", "lanes": "65" }, "Ethernet1": { "alias": "Eth1/2", "lanes": "66" }, "Ethernet2": { "alias": "Eth1/3", "lanes": "67" }, "Ethernet3": { "alias": "Eth1/4", "lanes": "68" }, "Ethernet4": { "alias": "Eth2/1", "lanes": "69" }, ... ... "INTERFACE": { "Ethernet0|10.0.0.0/31": {}, "Ethernet1|10.0.0.2/31": {}, "Ethernet2|10.0.0.4/31": {}, "Ethernet3|10.0.0.6/31": {}, "Ethernet4|10.0.0.8/31": {},
1 parent e6278c1 commit 913a62c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

dockers/docker-config-engine/Dockerfile.j2

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ ENV DEBIAN_FRONTEND=noninteractive
55

66
RUN apt-get update
77

8-
# Dependencies for sonic-cfggen
9-
RUN apt-get install -y python-lxml python-yaml python-bitarray python-pip python-dev
8+
# Dependencies for sonic-cfggen
9+
RUN apt-get install -y python-lxml python-yaml python-bitarray python-pip python-dev python-natsort
1010

1111
RUN pip install --upgrade pip
1212

src/sonic-config-engine/sonic-cfggen

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ from sonic_platform import get_machine_info
3030
from sonic_platform import get_platform_info
3131
from sonic_platform import get_system_mac
3232
from swsssdk import ConfigDBConnector
33+
from collections import OrderedDict
34+
from natsort import natsorted
3335

3436
def is_ipv4(value):
3537
if not value:
@@ -99,6 +101,7 @@ TODO(taoyl): Current version of config db only supports BGP admin states.
99101
def to_serialized(data):
100102
for table in data:
101103
if type(data[table]) is dict:
104+
data[table] = OrderedDict(natsorted(data[table].items()))
102105
for key in data[table].keys():
103106
new_key = ConfigDBConnector.serialize_key(key)
104107
if new_key != key:

0 commit comments

Comments
 (0)