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-cli-gen] first phase implementation of the SONiC CLI Auto-generation tool #1644

Merged
merged 83 commits into from
Nov 17, 2021

Conversation

vadymhlushko-mlnx
Copy link
Contributor

What I did

Implemented the sonic-cli-gen according to the SONiC CLI Auto-generation HLD

How I did it

How the sonic-cli-gen works:

  1. Parse provided YANG model to the intermediate representation - python dictionary (you can find the structure in the sonic_cli_gen/yang_parser.py file).
  2. Pass the python dictionary to the appropriate j2 template (config or show) and generate the CLI plugin.
  3. Put the auto-generated CLI plugin to an appropriate location, where it can be discovered by SONiC CLI.

How to verify it

Check the file with unit tests - tests/cli_autogen_yang_parser_test.py

Command output

admin@sonic: sonic-cli-gen generate config sonic-acl
Loaded below Yang Models
['sonic-acl', 'sonic-breakout_cfg', 'sonic-crm', 'sonic-device_metadata', 'sonic-device_neighbor', 'sonic-extension', 'sonic-flex_counter', 'sonic-interface', 'sonic-loopback-interface', 'sonic-port', 'sonic-portchannel', 'sonic-types', 'sonic-versions', 'sonic-vlan', 'sonic-vrf']
Note: Below table(s) have no YANG models:
COPP_GROUP, COPP_TRAP, FEATURE, KDUMP, MGMT_INTERFACE, SNMP, SNMP_COMMUNITY, WJH, WJH_CHANNEL, 
INFO:sonic-cli-gen: Auto-generation successful! Location: /usr/local/lib/python3.7/dist-packages/config/plugins/auto/sonic-acl_yang.py
admin@sonic: sonic-cli-gen remove config sonic-acl
/usr/local/lib/python3.7/dist-packages/config/plugins/auto/sonic-acl_yang.py was removed.

vadymhlushko-mlnx and others added 30 commits April 28, 2021 10:04
Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
…e_metadata.yang DONE

Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
…s - get_leafs(), get_leaf_lists(), get_choices(), get_uses_grouping()

Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
Signed-off-by: Stepan Blyschak <stepanb@mellanox.com>
Signed-off-by: Stepan Blyschak <stepanb@mellanox.com>
Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
Signed-off-by: Stepan Blyschak <stepanb@mellanox.com>
Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
Signed-off-by: Stepan Blyschak <stepanb@mellanox.com>
Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
…ion comments

Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
…nged constructor for YangParser

Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
Signed-off-by: Vadym Hlushko <vadymh@nvidia.com>
@stepanblyschak
Copy link
Contributor

@praveen-li Please check latest changes. Added type annotations in docstring.

sonic_cli_gen/yang_parser.py Show resolved Hide resolved
sonic_cli_gen/yang_parser.py Show resolved Hide resolved
sonic_cli_gen/yang_parser.py Show resolved Hide resolved
sonic_cli_gen/yang_parser.py Show resolved Hide resolved
Signed-off-by: Stepan Blyshchak <stepanb@nvidia.com>
@renukamanavalan
Copy link
Contributor

Code changes under sonic-utilities-data, looks good.

Signed-off-by: Stepan Blyshchak <stepanb@nvidia.com>
Signed-off-by: Stepan Blyshchak <stepanb@nvidia.com>
…original cfg

Signed-off-by: Stepan Blyshchak <stepanb@nvidia.com>
@vadymhlushko-mlnx
Copy link
Contributor Author

Hi @renukamanavalan and @praveen-li, did you finish the review?

@stepanblyschak
Copy link
Contributor

@renukamanavalan @praveen-li Could you please also review the second part of the feature in sonic-package-manager - #1650 ?

sonic_cli_gen/generator.py Outdated Show resolved Hide resolved
sonic_cli_gen/generator.py Show resolved Hide resolved
@renukamanavalan
Copy link
Contributor

renukamanavalan commented Nov 11, 2021

@renukamanavalan @praveen-li Could you please also review the second part of the feature in sonic-package-manager - #1650 ?

I am done with the review of this PR with few minor comments. I would like approval from Praveen, before we merge.
I am looking at 1650. @praveen-li, can you please help review too ?

praveen-li
praveen-li previously approved these changes Nov 16, 2021
Copy link

@praveen-li praveen-li left a comment

Choose a reason for hiding this comment

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

LGTM now,

sonic_cli_gen/yang_parser.py Show resolved Hide resolved
sonic_cli_gen/yang_parser.py Show resolved Hide resolved
sonic_cli_gen/yang_parser.py Show resolved Hide resolved
sonic_cli_gen/yang_parser.py Show resolved Hide resolved
sonic_cli_gen/generator.py Show resolved Hide resolved
Signed-off-by: Vadym Hlushko <vadymh@nvidia.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.