| 1 |
# Copyright (c) 2021 Arista Networks, Inc. |
| 2 |
# Use of this source code is governed by the Apache License 2.0 |
| 3 |
# that can be found in the COPYING file. |
| 4 |
# |
| 5 |
# NOTE: The following example is using the new Change Control Resource APIs supported in 2021.2.0 or newer and in CVaaS. |
| 6 |
# For CVaaS service-account token based auth has to be used. |
| 7 |
|
| 8 |
from cvprac.cvp_client import CvpClient |
| 9 |
import ssl |
| 10 |
import uuid |
| 11 |
from datetime import datetime |
| 12 |
ssl._create_default_https_context = ssl._create_unverified_context |
| 13 |
import requests.packages.urllib3 |
| 14 |
requests.packages.urllib3.disable_warnings() |
| 15 |
|
| 16 |
# Create connection to CloudVision |
| 17 |
clnt = CvpClient() |
| 18 |
clnt.connect(['cvp1'],'username', 'password') |
| 19 |
|
| 20 |
# Generate change control id and change control name |
| 21 |
cc_id = str(uuid.uuid4()) |
| 22 |
name = f"Change_{datetime.now().strftime('%Y%m%d_%H%M%S')}" |
| 23 |
|
| 24 |
# Select the tasks and create a CC where all tasks will be run in parallel |
| 25 |
tasks = ["1249","1250","1251","1252"] |
| 26 |
clnt.api.change_control_create_for_tasks(cc_id, name, tasks, series=False) |
| 27 |
|
| 28 |
# Approve the change control |
| 29 |
approve_note = "Approving CC via cvprac" |
| 30 |
clnt.api.change_control_approve(cc_id, notes=approve_note) |
| 31 |
|
| 32 |
# # Schedule the change control |
| 33 |
# # Executing scheduled CCs might only work post 2021.3.0+ |
| 34 |
# schedule_note = "Scheduling CC via cvprac" |
| 35 |
# schedule_time = "2021-12-23T03:17:00Z" |
| 36 |
# clnt.api.change_control_schedule(cc_id,schedule_time,notes=schedule_note) |
| 37 |
|
| 38 |
# Start the change control |
| 39 |
start_note = "Start the CC via cvprac" |
| 40 |
clnt.api.change_control_start(cc_id, notes=start_note) |