-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Changes from 1 commit
28cfbeb
c83d7e0
9256cd5
3fbd3f4
6765d06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = ""): | ||
if type(data) is dict: | ||
data = OrderedDict(natsorted(data.items())) | ||
|
||
if find_key != "": | ||
newData = {} | ||
for key in data.keys(): | ||
if ((type(key) is unicode and find_key == key) or (type(key) is tuple and find_key in key)): | ||
newData[ConfigDBConnector.serialize_key(key)] = data.pop(key) | ||
break | ||
return newData | ||
|
||
for key in data.keys(): | ||
new_key = ConfigDBConnector.serialize_key(key) | ||
if new_key != key: | ||
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the difference between --var-json. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. then, why not use -k, --key option which is more specific? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -K There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. Let me change that! |
||
args = parser.parse_args() | ||
|
||
platform = get_platform_info(get_machine_info()) | ||
|
@@ -261,7 +272,10 @@ def main(): | |
print(template.render(data)) | ||
|
||
if args.var_json != None: | ||
print(json.dumps(FormatConverter.to_serialized(data[args.var_json]), indent=4, cls=minigraph_encoder)) | ||
if args.find != None: | ||
print(json.dumps(FormatConverter.to_serialized(data[args.var_json], args.find), indent=4, cls=minigraph_encoder)) | ||
else: | ||
print(json.dumps(FormatConverter.to_serialized(data[args.var_json]), indent=4, cls=minigraph_encoder)) | ||
|
||
if args.write_to_db: | ||
configdb = ConfigDBConnector(**db_kwargs) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> lookup_key = None