-
Notifications
You must be signed in to change notification settings - Fork 61
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
Feat(cv_device_v3): Dotted hostname support #680
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.
I am worried about performance on a scaled setup. If you have many devices (hundreds or more), but only run an operation for a single device, you end up parsing the full inventory many times across the code.
if inventory_mode == ModuleOptionValues.INVENTORY_MODE_LOOSE: | ||
# Remove missing devices on CV from inventory (ignore missing) | ||
user_inventory = self.__remove_missing_devices( | ||
user_inventory=user_inventory | ||
) | ||
else: | ||
# Check if all devices are present on CV (fail on missing) | ||
self.__check_devices_exist(user_inventory=user_inventory) | ||
self.__check_devices_exist(cvp_inventory, user_inventory=user_inventory) |
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.
Instead of getting cvp_inventory in every function, just to pass it along to another method of self
, you could just let those functions look up the inventory directly in self.cvp_inventory().
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.
Good idea. I will make that change.
MODULE_LOGGER.warning("Update list is: %s", str(user_result)) | ||
return DeviceInventory(data=user_result) | ||
|
||
def refresh_hostname(self, cvp_inventory: list, user_inventory: DeviceInventory): |
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.
Why do you still need all these "refresh_xxx" when you have all the information already? It would be more efficient to have one function (__refresh_user_inventory
) that updates all missing info on user_inventory
from cvp_inventory
instead of looping through the entire inventory several times.
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.
Makes sense. Will make that change.
Data from CloudVision | ||
""" | ||
return self.__cv_client.api.get_inventory(start=0, end=0) | ||
|
||
# Updated as per issue #365 to set default search with hostname field | ||
@lru_cache | ||
def __get_device(self, search_value: str, search_by: str = Api.device.HOSTNAME): |
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.
Is this function still needed?
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.
Yes. It is being called by a few other functions.
@@ -128,6 +134,16 @@ | |||
"CV-ANSIBLE-EOS01" | |||
] | |||
}, | |||
"hostname": { | |||
"$id": "#/items/anyOf/0/properties/fqdn", |
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.
"$id": "#/items/anyOf/0/properties/fqdn", | |
"$id": "#/items/anyOf/0/properties/hostname", |
"$id": "#/items/anyOf/0/properties/fqdn", | ||
"type": "string", | ||
"title": "The hostname schema", | ||
"description": "An explanation about the purpose of this instance.", |
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.
If we have no good description, just remove the field.
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 15 days |
d85b764
to
a68b70a
Compare
Quality Gate passedIssues Measures |
Not fixing! |
Change Summary
Adding support for hostname with dots(s1-leaf.1.aristanetworks.com) to cv_device_v3 module.
Related Issue(s)
Fixes #654
Component(s) name
arista.cvp.cv_device_v3
Proposed changes
Previously,
get_device_by_name()
cvprac function was used to get info on a device.This was called for each device. Now,
get_inventory()
is called once to get the entire CVP inventory and cache it.get_inventory()
reports all information, especiallyfqdn
andhostname
as opposed toget_device_by_name()
only returningfqdn
.The module no longer derivese
hostname
fromfqdn
field. If the module is not providedhostname
as input, then we get it from the inventory.The schema now supports
hostname
knob.How to test
NOTE: This PR is dependent on some changes to
get_inventory()
function on cvprac. While we wait for that change to merge into cvprac, please make sure to comment line #600-626 in the latest cvprac: https://github.com/aristanetworks/cvprac/blob/b5306b22770848a32d5927620e804bd1482932c1/cvprac/cvp_api.py#L600and run the following playbook
Use
search_key
knob to specify if you want to serach the inventory byhostname
orfqdn
.Note: if
search_key: hostname
, thenhostname
should be specified incvp_device
variable.Similarly, if
search_key: fqdn
, thenfqdn
should be specified incvp_device
variableChecklist
User Checklist
Repository Checklist