Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sonic-cfggen]: add --key option to show a specific key #3248

Merged
merged 5 commits into from
Aug 6, 2019

Conversation

vasant17
Copy link
Contributor

@vasant17 vasant17 commented Jul 31, 2019

Signed-off-by: Vasant Patil vapatil@linkedin.com

This will help to dispy config DB with more granularity.
For example:
show runningconfiguration interface Ethernet0
show runningconfiguration interfaces Ethernet0

Testing done:

[[admin@lnos-x1-a-csw06:~$ show runningconfiguration interfaces
{
    "Ethernet0|10.0.0.0/31": {
        "family": "IPv4", 
        "scope": "global"
    }, 
    "Ethernet4|10.0.0.2/31": {}, 
    "Ethernet8|10.0.0.4/31": {}, 
    "Ethernet12|10.0.0.6/31": {}, 
    "Ethernet16|10.0.0.8/31": {}, 
    "Ethernet20|10.0.0.10/31": {}, 
    "Ethernet24|10.0.0.12/31": {}, 
    "Ethernet28|10.0.0.14/31": {}, 
    "Ethernet32|10.0.0.16/31": {}, 
    "Ethernet36|10.0.0.18/31": {}, 
    "Ethernet40|10.0.0.20/31": {}, 
    "Ethernet44|10.0.0.22/31": {}, 
    "Ethernet48|10.0.0.24/31": {}, 
    "Ethernet52|10.0.0.26/31": {}, 
    "Ethernet56|10.0.0.28/31": {}, 
    "Ethernet60|10.0.0.30/31": {}, 
    "Ethernet64|10.0.0.32/31": {}, 
    "Ethernet68|10.0.0.34/31": {}, 
    "Ethernet72|10.0.0.36/31": {}, 
    "Ethernet76|10.0.0.38/31": {}, 
    "Ethernet80|10.0.0.40/31": {}, 
    "Ethernet84|10.0.0.42/31": {}, 
    "Ethernet88|10.0.0.44/31": {}, 
    "Ethernet92|10.0.0.46/31": {}, 
    "Ethernet96|10.0.0.48/31": {}, 
    "Ethernet100|10.0.0.50/31": {}, 
    "Ethernet104|10.0.0.52/31": {}, 
    "Ethernet108|10.0.0.54/31": {}, 
    "Ethernet112|10.0.0.56/31": {}, 
    "Ethernet116|10.0.0.58/31": {}, 
    "Ethernet120|10.0.0.60/31": {}, 
    "Ethernet124|10.0.0.62/31": {}
}
admin@lnos-x1-a-csw06:~$ show runningconfiguration interface
{
    "Ethernet0": {
        "admin_status": "up", 
        "alias": "Eth1", 
        "index": "1", 
        "lanes": "65,66,67,68", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet4": {
        "admin_status": "up", 
        "alias": "Eth2", 
        "index": "2", 
        "lanes": "69,70,71,72", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet8": {
        "admin_status": "up", 
        "alias": "Eth3", 
        "index": "3", 
        "lanes": "73,74,75,76", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet12": {
        "admin_status": "up", 
        "alias": "Eth4", 
        "index": "4", 
        "lanes": "77,78,79,80", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet16": {
        "admin_status": "up", 
        "alias": "Eth5", 
        "index": "5", 
        "lanes": "33,34,35,36", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet20": {
        "admin_status": "up", 
        "alias": "Eth6", 
        "index": "6", 
        "lanes": "37,38,39,40", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet24": {
        "admin_status": "up", 
        "alias": "Eth7", 
        "index": "7", 
        "lanes": "41,42,43,44", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet28": {
        "admin_status": "up", 
        "alias": "Eth8", 
        "index": "8", 
        "lanes": "45,46,47,48", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet32": {
        "admin_status": "up", 
        "alias": "Eth9", 
        "index": "9", 
        "lanes": "49,50,51,52", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet36": {
        "admin_status": "up", 
        "alias": "Eth10", 
        "index": "10", 
        "lanes": "53,54,55,56", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet40": {
        "admin_status": "up", 
        "alias": "Eth11", 
        "index": "11", 
        "lanes": "57,58,59,60", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet44": {
        "admin_status": "up", 
        "alias": "Eth12", 
        "index": "12", 
        "lanes": "61,62,63,64", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet48": {
        "admin_status": "up", 
        "alias": "Eth13", 
        "index": "13", 
        "lanes": "81,82,83,84", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet52": {
        "admin_status": "up", 
        "alias": "Eth14", 
        "index": "14", 
        "lanes": "85,86,87,88", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet56": {
        "admin_status": "up", 
        "alias": "Eth15", 
        "index": "15", 
        "lanes": "89,90,91,92", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet60": {
        "admin_status": "up", 
        "alias": "Eth16", 
        "index": "16", 
        "lanes": "93,94,95,96", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet64": {
        "admin_status": "up", 
        "alias": "Eth17", 
        "index": "17", 
        "lanes": "97,98,99,100", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet68": {
        "admin_status": "up", 
        "alias": "Eth18", 
        "index": "18", 
        "lanes": "101,102,103,104", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet72": {
        "admin_status": "up", 
        "alias": "Eth19", 
        "index": "19", 
        "lanes": "105,106,107,108", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet76": {
        "admin_status": "up", 
        "alias": "Eth20", 
        "index": "20", 
        "lanes": "109,110,111,112", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet80": {
        "admin_status": "up", 
        "alias": "Eth21", 
        "index": "21", 
        "lanes": "1,2,3,4", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet84": {
        "admin_status": "up", 
        "alias": "Eth22", 
        "index": "22", 
        "lanes": "5,6,7,8", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet88": {
        "admin_status": "up", 
        "alias": "Eth23", 
        "index": "23", 
        "lanes": "9,10,11,12", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet92": {
        "admin_status": "up", 
        "alias": "Eth24", 
        "index": "24", 
        "lanes": "13,14,15,16", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet96": {
        "admin_status": "up", 
        "alias": "Eth25", 
        "index": "25", 
        "lanes": "17,18,19,20", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet100": {
        "admin_status": "up", 
        "alias": "Eth26", 
        "index": "26", 
        "lanes": "21,22,23,24", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet104": {
        "admin_status": "up", 
        "alias": "Eth27", 
        "index": "27", 
        "lanes": "25,26,27,28", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet108": {
        "admin_status": "up", 
        "alias": "Eth28", 
        "index": "28", 
        "lanes": "29,30,31,32", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet112": {
        "admin_status": "up", 
        "alias": "Eth29", 
        "index": "29", 
        "lanes": "113,114,115,116", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet116": {
        "admin_status": "up", 
        "alias": "Eth30", 
        "index": "30", 
        "lanes": "117,118,119,120", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet120": {
        "admin_status": "up", 
        "alias": "Eth31", 
        "index": "31", 
        "lanes": "121,122,123,124", 
        "mtu": "9100", 
        "speed": "100000"
    }, 
    "Ethernet124": {
        "admin_status": "up", 
        "alias": "Eth32", 
        "index": "32", 
        "lanes": "125,126,127,128", 
        "mtu": "9100", 
        "speed": "100000"
    }
}
admin@lnos-x1-a-csw06:~$ show runningconfiguration interface Ethernet4
{
    "Ethernet4": {
        "index": "2", 
        "lanes": "69,70,71,72", 
        "mtu": "9100", 
        "alias": "Eth2", 
        "admin_status": "up", 
        "speed": "100000"
    }
}
admin@lnos-x1-a-csw06:~$ show runningconfiguration interface Ethernet40
{
    "Ethernet40": {
        "index": "11", 
        "lanes": "57,58,59,60", 
        "mtu": "9100", 
        "alias": "Eth11", 
        "admin_status": "up", 
        "speed": "100000"
    }
}
admin@lnos-x1-a-csw06:~$ show runningconfiguration interfaces Ethernet4
{
    "Ethernet4|10.0.0.2/31": {}
}
admin@lnos-x1-a-csw06:~$ show runningconfiguration interfaces Ethernet40
{
    "Ethernet40|10.0.0.20/31": {}
}
admin@lnos-x1-a-csw06:~$](url)

](url)

- What I did

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

…y config DB with more granularity.

Signed-off-by: Vasant Patil <vapatil@linkedin.com>
@@ -181,6 +190,8 @@ def main():
group.add_argument("-w", "--write-to-db", help="write config into configdb", action='store_true')
group.add_argument("--print-data", help="print all data", action='store_true')
group.add_argument("--preset", help="generate sample configuration from a preset template", choices=get_available_config())
group = parser.add_mutually_exclusive_group()
group.add_argument("-f", "--find", help="Find/Search for a specific key")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the difference between --var-json.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--var-json is used to query one level higher keys. For example: BGP_NEIGHBOR, DEVICE_METADATA, INTERFACE, PORT, etc.. where as --find is used query one level down. For example Ethernet0 under PORT.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then, why not use -k, --key option which is more specific?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though so as well, since -k is taken by hwSKU, I used -f. Please suggest if you have any other better alternative.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-K

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Let me change that!

@@ -124,9 +124,18 @@ TODO(taoyl): Current version of config db only supports BGP admin states.
return db_data

@staticmethod
def to_serialized(data):
def to_serialized(data, find_key = ""):
Copy link
Collaborator

@lguohan lguohan Aug 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> lookup_key = None

@lguohan
Copy link
Collaborator

lguohan commented Aug 5, 2019

when you add new function, please add sonic-cfggen unit test.

@vasant17
Copy link
Contributor Author

vasant17 commented Aug 5, 2019

Added 2 unit test cases. Below lines are copied from log file.
test_additional_json_data_level1_key (test_cfggen.TestCfgGen) ... ok
test_additional_json_data_level2_key (test_cfggen.TestCfgGen) ... ok

@lguohan lguohan changed the title Adding --find option to sonic-cfggen script. Adding --key option to sonic-cfggen script. Aug 6, 2019
@lguohan lguohan changed the title Adding --key option to sonic-cfggen script. Adding --key option to sonic-cfggen to show a specific key Aug 6, 2019
@lguohan lguohan changed the title Adding --key option to sonic-cfggen to show a specific key [sonic-cfggen]: add --key option to show a specific key Aug 6, 2019
@lguohan lguohan merged commit 63b5e0e into sonic-net:master Aug 6, 2019
zhenggen-xu pushed a commit to zhenggen-xu/sonic-buildimage that referenced this pull request Oct 17, 2019
* Adding --key option to sonic-cfggen script. This will help to display config DB with more granularity.

Signed-off-by: Vasant Patil <vapatil@linkedin.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants