Debian Codegraph @

docs/labs/lab06-provisioning/change_control_custom_rapi.py

raw
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
21 cc_id = str(uuid.uuid4())
22 name = f"Change_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
23
24 # Create custom stage hierarchy
25 # The below example would result in the following hierarchy:
26 # root (series)
27 # |- stages 1-2 (series)
28 # | |- stage 1ab (parallel)
29 # | | |- stage 1a
30 # | | |- stage 1b
31 # | |- stage 2
32 # |- stage 3
33 data = {'key': {
34 'id': cc_id
35 },
36 'change': {
37 'name': cc_id,
38 'notes': 'cvprac CC',
39 'rootStageId': 'root',
40 'stages': {'values': {'root': {'name': 'root',
41 'rows': {'values': [{'values': ['1-2']},
42 {'values': ['3']}]
43 }
44 },
45 '1-2': {'name': 'stages 1-2',
46 'rows': {'values': [{'values': ['1ab']},
47 {'values': ['2']}]}},
48 '1ab': {'name': 'stage 1ab',
49 'rows': {'values': [{'values': ['1a','1b']}]
50 }
51 },
52 '1a': {'action': {'args': {'values': {'TaskID': '1242'}},
53 'name': 'task',
54 'timeout': 3000},
55 'name': 'stage 1a'},
56 '1b': {'action': {'args': {'values': {'TaskID': '1243'}},
57 'name': 'task',
58 'timeout': 3000},
59 'name': 'stage 1b'},
60 '2': {'action': {'args': {'values': {'TaskID': '1240'}},
61 'name': 'task',
62 'timeout': 3000},
63 'name': 'stage 2'},
64 '3': {'action': {'args': {'values': {'TaskID': '1241'}},
65 'name': 'task',
66 'timeout': 3000},
67 'name': 'stage 3'},
68 }
69 }
70 }
71 }
72 # Create change control from custom stage hierarchy data
73 clnt.api.change_control_create_with_custom_stages(data)
74
75 # Approve the change control
76 approval_note = "Approve CC via cvprac" # notes are optional
77 clnt.api.change_control_approve(cc_id, notes=approval_note)
78
79 # Start the change control
80 start_note = "Starting CC via cvprac" # notes are optional
81 clnt.api.change_control_start(cc_id, notes=start_note)