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

Hvrp display configuration dhcp #779

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

nielsvanhooy
Copy link

Description

added new command in hvrp
*DisplayConfigDhcp

Motivation and Context

i needed schema's to extract configuration settings for dhcp

Impact (If any)

no impact.

Checklist:

  • I have updated the changelog.
  • I have updated the documentation (If applicable).
  • I have added tests to cover my changes (If applicable).
  • All new and existing tests passed.
  • All new code passed compilation.

@nielsvanhooy nielsvanhooy requested a review from a team as a code owner August 15, 2023 11:00
Copy link
Contributor

@GerriorL GerriorL left a comment

Choose a reason for hiding this comment

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

Hi! Thanks for the contribution.

I understand what you're trying to accomplish with this contribution but unfortunately this implementation goes against the project's code standards. What I'd recommend is to create a full parser for display current-configuration. Then you can create a genielibs get API, and from that extract specifically the information related to the dhcp config by calling the full parser and only return the desired keys.

Genieparsers are expected to take in a valid device command, and return a complete parsing of the raw output, with minimal editorializing. Genielibs APIs are a bit more flexible

Comment on lines +7 to +35
class DisplayConfigDhcpSchema(MetaParser):
schema = {
Any(): {
Optional("domain"): str,
Optional("gateway"): str,
Optional("netbios_servers"): list,
Optional("dns_servers"): list,
Optional("dhcp_excludes"): {
Any(): {
Optional('end'): str,
Optional('start'): str,
}
},
Optional("networks"): {
Any(): {
Optional('ip'): str,
Optional('subnet_mask'): str,
}
},
Optional("dhcp_options"): {
Any(): {
Optional("option"): str,
Optional("type"): str,
Optional("data"): str,
}
},
Optional("lease_time"): str,
},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Schemas are used to validate the key and value type of the output to ensure it's consistent. For that reason the topmost level key should never be an Any(). It's also best to not have keys set as Optional() unnecessarily. It's best to make every key possible be mandatory.

Comment on lines +38 to +42
# note below command does not exist.
# there is no command that filters all dhcp info (unless regex on cli)
# but that is not a good option. better to leverage python for that
# the real command we will run is display current-configuration.
cli_command = "display dhcp configuration"
Copy link
Contributor

Choose a reason for hiding this comment

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

This implementation proves tricky, because genieparser is built on the assumption that the user is passing a valid IOS command. The mechanism to find the correct parser uses the cli_command to perform the search, and for that reason a cli_command cannot be arbitrary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants