aristanetworks / ansible-cvp

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

Feat(cv_container_v3): Add support for image bundles on containers #550

Closed colinmacgiolla closed 1 year ago

colinmacgiolla commented 1 year ago

Change Summary

The PR introduces support for assigning, updating, and removing (in strict mode) an imageBundle (there can be only one) from a container.

If an image bundle is already assigned to the container, and the user topology does not specify one (or has it as blank), the existing image bundle will remain in place unless strict mode is used.

Related Issue(s)

Fixes #

Component(s) name

arista.cvp.cv_container_v3

Proposed changes

This is mostly changes in the container_tools.py where I've added the necessary function calls to add/remove an image bundle from an element. No changes were required re deleting a container, as the API call allows the container to be deleted, whether or not there is a bundle assigned.

How to test

Tested with CVP 2021.2.2 and cvprac 1.2.0

Creating a new container with an existing image bundle assigned:

---
- name: Container Image Management in Cloudvision
  hosts: cv_server
  connection: local
  gather_facts: false
  collections:
    - arista.cvp

  vars:
    # Container definition
    containers_provision:
        Undefined:
            configlets: []
            imageBundle: EOS-4.25.4M
            parentContainerName: Tenant
        Test123:
            configlets: []
            imageBundle: 'top_level_container'
            parentContainerName: Tenant

  tasks:
    - name: "Build Container topology on {{inventory_hostname}}"
      arista.cvp.cv_container_v3:
        topology: '{{containers_provision}}

Updating the image bundle on an existing container

---
- name: Container Image Management in Cloudvision
  hosts: cv_server
  connection: local
  gather_facts: false
  collections:
    - arista.cvp

  vars:
    # Container definition
    containers_provision:
        Undefined:
            configlets: []
            imageBundle: EOS-4.25.4M
            parentContainerName: Tenant
        Test123:
            configlets: []
            imageBundle: 'low_level_container'
            parentContainerName: Tenant

  tasks:
    - name: "Build Container topology on {{inventory_hostname}}"
      arista.cvp.cv_container_v3:
        topology: '{{containers_provision}}'

Removing the image bundle from an existing container

---
- name: Container Image Management in Cloudvision
  hosts: cv_server
  connection: local
  gather_facts: false
  collections:
    - arista.cvp

  vars:
    # Container definition
    containers_provision:
        Undefined:
            configlets: []
            imageBundle: EOS-4.25.4M
            parentContainerName: Tenant
        Test123:
            configlets: []
            imageBundle: ''
            parentContainerName: Tenant

  tasks:
    - name: "Apply updated Container topology on {{inventory_hostname}} in strict mode"
      arista.cvp.cv_container_v3:
        topology: '{{containers_provision}}'
        apply_mode: strict

Checklist

User Checklist

Repository Checklist

sugetha24 commented 1 year ago

LGTM! Would be nice to add the example playbooks to the example folder but we can do that in a different PR, I see we haven't yet added anything for cv_container_v3 there anyways

@colinmacgiolla I suggest going ahead and adding the examples you have here in the PR.

colinmacgiolla commented 1 year ago

LGTM! Would be nice to add the example playbooks to the example folder but we can do that in a different PR, I see we haven't yet added anything for cv_container_v3 there anyways

@colinmacgiolla I suggest going ahead and adding the examples you have here in the PR.

Done