aristanetworks / ansible-cvp

Ansible modules for Arista CloudVision
http://cvp.avd.sh
Apache License 2.0
65 stars 61 forks source link

Feat(cv_device_v3): Dotted hostname support #680

Open sugetha24 opened 8 months ago

sugetha24 commented 8 months ago

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, especially fqdn and hostname as opposed to get_device_by_name() only returning fqdn. The module no longer derivese hostname from fqdn field. If the module is not provided hostname 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#L600 and run the following playbook

- name: Playbook to demonstrate cvp modules.
  hosts: CVP
  connection: local
  gather_facts: no
  vars:
    # Container definition
    cvp_devices:
      - hostname: s1-leaf.1
      # - fqdn: s1-leaf.1.aristanetworks.com
        parentContainerName: SITE1_LEAFS
        configlets:
          - Add-VLAN-50
  tasks:
    - name: "Configure devices on {{inventory_hostname}}"
      arista.cvp.cv_device_v3:
        devices: '{{cvp_devices}}'
        state: present
        # search_key: fqdn
        search_key: hostname
      register: CVP_DEVICES_RESULTS
    - name: debug
      debug:
        msg: "{{CVP_DEVICES_RESULTS}}"

Use search_key knob to specify if you want to serach the inventory by hostname or fqdn. Note: if search_key: hostname, then hostname should be specified in cvp_device variable. Similarly, if search_key: fqdn, then fqdn should be specified in cvp_device variable

Checklist

User Checklist

Repository Checklist

github-actions[bot] commented 5 months ago

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

sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
7 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud