-
Notifications
You must be signed in to change notification settings - Fork 388
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
base: main
Are you sure you want to change the base?
Hvrp display configuration dhcp #779
Conversation
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.
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
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, | ||
}, | ||
} |
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.
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.
# 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" |
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.
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.
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: