virl2_client 2.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- examples/demo.ipynb +209 -0
- examples/licensing.py +159 -0
- examples/link_conditioning.py +98 -0
- examples/sample.py +105 -0
- virl2_client/__init__.py +32 -0
- virl2_client/event_handling.py +343 -0
- virl2_client/event_listening.py +183 -0
- virl2_client/exceptions.py +99 -0
- virl2_client/models/__init__.py +51 -0
- virl2_client/models/annotation.py +708 -0
- virl2_client/models/auth_management.py +449 -0
- virl2_client/models/authentication.py +176 -0
- virl2_client/models/cl_pyats.py +250 -0
- virl2_client/models/configuration.py +141 -0
- virl2_client/models/groups.py +166 -0
- virl2_client/models/interface.py +387 -0
- virl2_client/models/lab.py +1906 -0
- virl2_client/models/licensing.py +333 -0
- virl2_client/models/link.py +387 -0
- virl2_client/models/node.py +946 -0
- virl2_client/models/node_image_definitions.py +351 -0
- virl2_client/models/resource_pools.py +464 -0
- virl2_client/models/system.py +678 -0
- virl2_client/models/users.py +171 -0
- virl2_client/utils.py +180 -0
- virl2_client/virl2_client.py +918 -0
- virl2_client-2.7.0.dist-info/LICENSE +202 -0
- virl2_client-2.7.0.dist-info/METADATA +152 -0
- virl2_client-2.7.0.dist-info/NOTICE +5 -0
- virl2_client-2.7.0.dist-info/RECORD +31 -0
- virl2_client-2.7.0.dist-info/WHEEL +4 -0
examples/demo.ipynb
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cells": [
|
|
3
|
+
{
|
|
4
|
+
"cell_type": "code",
|
|
5
|
+
"execution_count": null,
|
|
6
|
+
"metadata": {},
|
|
7
|
+
"outputs": [],
|
|
8
|
+
"source": [
|
|
9
|
+
"from virl2_client import ClientLibrary\n",
|
|
10
|
+
"\n",
|
|
11
|
+
"client = ClientLibrary(\"https://192.168.1.1\", \"virl2\", \"virl2\", ssl_verify=False)"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"cell_type": "code",
|
|
16
|
+
"execution_count": null,
|
|
17
|
+
"metadata": {},
|
|
18
|
+
"outputs": [],
|
|
19
|
+
"source": [
|
|
20
|
+
"lab = client.create_lab()\n",
|
|
21
|
+
"print(lab.id)"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"cell_type": "code",
|
|
26
|
+
"execution_count": null,
|
|
27
|
+
"metadata": {},
|
|
28
|
+
"outputs": [],
|
|
29
|
+
"source": [
|
|
30
|
+
"r1 = lab.create_node(\"r1\", \"iosv\", 50, 100)"
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"cell_type": "code",
|
|
35
|
+
"execution_count": null,
|
|
36
|
+
"metadata": {},
|
|
37
|
+
"outputs": [],
|
|
38
|
+
"source": [
|
|
39
|
+
"r2 = lab.create_node(\"r2\", \"iosv\", 302, 201)"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"cell_type": "code",
|
|
44
|
+
"execution_count": null,
|
|
45
|
+
"metadata": {},
|
|
46
|
+
"outputs": [],
|
|
47
|
+
"source": [
|
|
48
|
+
"r3 = lab.create_node(\"r3\", \"iosv\", 200, 400)"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"cell_type": "code",
|
|
53
|
+
"execution_count": null,
|
|
54
|
+
"metadata": {},
|
|
55
|
+
"outputs": [],
|
|
56
|
+
"source": [
|
|
57
|
+
"r1_i1 = r1.create_interface()\n",
|
|
58
|
+
"r1_i2 = r1.create_interface()"
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"cell_type": "code",
|
|
63
|
+
"execution_count": null,
|
|
64
|
+
"metadata": {},
|
|
65
|
+
"outputs": [],
|
|
66
|
+
"source": [
|
|
67
|
+
"r2_i1 = r2.create_interface()\n",
|
|
68
|
+
"r2_i2 = r2.create_interface()"
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"cell_type": "code",
|
|
73
|
+
"execution_count": null,
|
|
74
|
+
"metadata": {},
|
|
75
|
+
"outputs": [],
|
|
76
|
+
"source": [
|
|
77
|
+
"r3_i1 = r3.create_interface()\n",
|
|
78
|
+
"r3_i2 = r3.create_interface()"
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"cell_type": "code",
|
|
83
|
+
"execution_count": null,
|
|
84
|
+
"metadata": {},
|
|
85
|
+
"outputs": [],
|
|
86
|
+
"source": [
|
|
87
|
+
"link_1 = lab.create_link(r1_i1, r2_i1)"
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"cell_type": "code",
|
|
92
|
+
"execution_count": null,
|
|
93
|
+
"metadata": {},
|
|
94
|
+
"outputs": [],
|
|
95
|
+
"source": [
|
|
96
|
+
"link_2 = lab.create_link(r2_i2, r3_i1)"
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"cell_type": "code",
|
|
101
|
+
"execution_count": null,
|
|
102
|
+
"metadata": {},
|
|
103
|
+
"outputs": [],
|
|
104
|
+
"source": [
|
|
105
|
+
"link_3 = lab.create_link(r3_i2, r1_i2)"
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"cell_type": "code",
|
|
110
|
+
"execution_count": null,
|
|
111
|
+
"metadata": {},
|
|
112
|
+
"outputs": [],
|
|
113
|
+
"source": [
|
|
114
|
+
"lab.remove_link(link_1)"
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"cell_type": "code",
|
|
119
|
+
"execution_count": null,
|
|
120
|
+
"metadata": {},
|
|
121
|
+
"outputs": [],
|
|
122
|
+
"source": [
|
|
123
|
+
"lab.remove_link(link_2)"
|
|
124
|
+
]
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"cell_type": "code",
|
|
128
|
+
"execution_count": null,
|
|
129
|
+
"metadata": {},
|
|
130
|
+
"outputs": [],
|
|
131
|
+
"source": [
|
|
132
|
+
"lab.remove_link(link_3)"
|
|
133
|
+
]
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"cell_type": "code",
|
|
137
|
+
"execution_count": null,
|
|
138
|
+
"metadata": {},
|
|
139
|
+
"outputs": [],
|
|
140
|
+
"source": [
|
|
141
|
+
"lab.remove_interface(r1_i2)"
|
|
142
|
+
]
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"cell_type": "code",
|
|
146
|
+
"execution_count": null,
|
|
147
|
+
"metadata": {},
|
|
148
|
+
"outputs": [],
|
|
149
|
+
"source": [
|
|
150
|
+
"lab.remove_node(r1)"
|
|
151
|
+
]
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"cell_type": "code",
|
|
155
|
+
"execution_count": null,
|
|
156
|
+
"metadata": {},
|
|
157
|
+
"outputs": [],
|
|
158
|
+
"source": [
|
|
159
|
+
"lab.remove_node(r2)"
|
|
160
|
+
]
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"cell_type": "code",
|
|
164
|
+
"execution_count": null,
|
|
165
|
+
"metadata": {},
|
|
166
|
+
"outputs": [],
|
|
167
|
+
"source": [
|
|
168
|
+
"lab.remove_node(r3)"
|
|
169
|
+
]
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"cell_type": "code",
|
|
173
|
+
"execution_count": null,
|
|
174
|
+
"metadata": {},
|
|
175
|
+
"outputs": [],
|
|
176
|
+
"source": [
|
|
177
|
+
"lab.remove()"
|
|
178
|
+
]
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"cell_type": "code",
|
|
182
|
+
"execution_count": null,
|
|
183
|
+
"metadata": {},
|
|
184
|
+
"outputs": [],
|
|
185
|
+
"source": []
|
|
186
|
+
}
|
|
187
|
+
],
|
|
188
|
+
"metadata": {
|
|
189
|
+
"kernelspec": {
|
|
190
|
+
"display_name": "Python 3",
|
|
191
|
+
"language": "python",
|
|
192
|
+
"name": "python3"
|
|
193
|
+
},
|
|
194
|
+
"language_info": {
|
|
195
|
+
"codemirror_mode": {
|
|
196
|
+
"name": "ipython",
|
|
197
|
+
"version": 3
|
|
198
|
+
},
|
|
199
|
+
"file_extension": ".py",
|
|
200
|
+
"mimetype": "text/x-python",
|
|
201
|
+
"name": "python",
|
|
202
|
+
"nbconvert_exporter": "python",
|
|
203
|
+
"pygments_lexer": "ipython3",
|
|
204
|
+
"version": "3.6.6"
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
"nbformat": 4,
|
|
208
|
+
"nbformat_minor": 2
|
|
209
|
+
}
|
examples/licensing.py
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
#
|
|
3
|
+
# This file is part of VIRL 2
|
|
4
|
+
# Copyright (c) 2019-2024, Cisco Systems, Inc.
|
|
5
|
+
# All rights reserved.
|
|
6
|
+
#
|
|
7
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
8
|
+
#
|
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
# you may not use this file except in compliance with the License.
|
|
11
|
+
# You may obtain a copy of the License at
|
|
12
|
+
#
|
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
#
|
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
# See the License for the specific language governing permissions and
|
|
19
|
+
# limitations under the License.
|
|
20
|
+
#
|
|
21
|
+
|
|
22
|
+
import getpass
|
|
23
|
+
import json
|
|
24
|
+
|
|
25
|
+
from virl2_client import ClientLibrary
|
|
26
|
+
|
|
27
|
+
VIRL_CONTROLLER = "virl2-controller"
|
|
28
|
+
VIRL_USERNAME = input("username: ")
|
|
29
|
+
VIRL_PASSWORD = getpass.getpass("password: ")
|
|
30
|
+
SL_TOKEN = input("Smart License token: ")
|
|
31
|
+
|
|
32
|
+
client = ClientLibrary(VIRL_CONTROLLER, VIRL_USERNAME, VIRL_PASSWORD, ssl_verify=False)
|
|
33
|
+
|
|
34
|
+
# Get the licensing handle from the client as a property
|
|
35
|
+
licensing = client.licensing
|
|
36
|
+
|
|
37
|
+
# Setup default license transport (i.e., directly connected to the external
|
|
38
|
+
# Smart License server)
|
|
39
|
+
licensing.set_default_transport()
|
|
40
|
+
|
|
41
|
+
# Register with the Smart License server.
|
|
42
|
+
# Wait for registration and authorization to complete.
|
|
43
|
+
result = licensing.register_wait(SL_TOKEN)
|
|
44
|
+
if not result:
|
|
45
|
+
result = licensing.get_reservation_return_code()
|
|
46
|
+
print(f"ERROR: Failed to register with Smart License server: {result}!")
|
|
47
|
+
exit(1)
|
|
48
|
+
|
|
49
|
+
# Get the current registration status. This returns a JSON blob with license
|
|
50
|
+
# status and authorization details.
|
|
51
|
+
status = licensing.status()
|
|
52
|
+
|
|
53
|
+
# Get the current list of licensed features. This returns a JSON blob with
|
|
54
|
+
# licensed features.
|
|
55
|
+
features = licensing.features()
|
|
56
|
+
|
|
57
|
+
print(json.dumps(status, indent=4))
|
|
58
|
+
|
|
59
|
+
"""
|
|
60
|
+
Prints:
|
|
61
|
+
|
|
62
|
+
{
|
|
63
|
+
"udi": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
|
64
|
+
"registration": {
|
|
65
|
+
"status": "COMPLETED",
|
|
66
|
+
"expires": "2021-06-10 20:17:39",
|
|
67
|
+
"smart_account": "Foo",
|
|
68
|
+
"virtual_account": "Bar",
|
|
69
|
+
"instance_name": "cml-controller.cml.lab",
|
|
70
|
+
"register_time": {
|
|
71
|
+
"succeeded": null,
|
|
72
|
+
"attempted": "2020-06-10 20:22:33",
|
|
73
|
+
"scheduled": null,
|
|
74
|
+
"status": null,
|
|
75
|
+
"failure": "OK",
|
|
76
|
+
"success": "SUCCESS"
|
|
77
|
+
},
|
|
78
|
+
"renew_time": {
|
|
79
|
+
"succeeded": null,
|
|
80
|
+
"attempted": null,
|
|
81
|
+
"scheduled": "2020-12-07 20:22:40",
|
|
82
|
+
"status": null,
|
|
83
|
+
"failure": null,
|
|
84
|
+
"success": "FAILED"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"authorization": {
|
|
88
|
+
"status": "IN_COMPLIANCE",
|
|
89
|
+
"renew_time": {
|
|
90
|
+
"succeeded": null,
|
|
91
|
+
"attempted": "2020-07-25 16:44:09",
|
|
92
|
+
"scheduled": "2020-08-24 16:44:08",
|
|
93
|
+
"status": "SUCCEEDED",
|
|
94
|
+
"failure": null,
|
|
95
|
+
"success": "SUCCESS"
|
|
96
|
+
},
|
|
97
|
+
"expires": "2020-10-23 16:39:07"
|
|
98
|
+
},
|
|
99
|
+
"reservation_mode": false,
|
|
100
|
+
"transport": {
|
|
101
|
+
"ssms": "https://smartreceiver.cisco.com/licservice/license",
|
|
102
|
+
"proxy": {
|
|
103
|
+
"server": null,
|
|
104
|
+
"port": null
|
|
105
|
+
},
|
|
106
|
+
"default_ssms": "https://smartreceiver.cisco.com/licservice/license"
|
|
107
|
+
},
|
|
108
|
+
"features": [
|
|
109
|
+
{
|
|
110
|
+
"name": "CML - Enterprise License",
|
|
111
|
+
"description": "Cisco Modeling Labs - Enterprise License with 20 nodes \
|
|
112
|
+
capacity included",
|
|
113
|
+
"in_use": 1,
|
|
114
|
+
"status": "IN_COMPLIANCE",
|
|
115
|
+
"version": "1.0"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"name": "CML \u2013 Expansion Nodes",
|
|
119
|
+
"description": "Cisco Modeling Labs - Expansion node capacity for CML \
|
|
120
|
+
Enterprise Servers",
|
|
121
|
+
"in_use": 50,
|
|
122
|
+
"status": "IN_COMPLIANCE",
|
|
123
|
+
"version": "1.0"
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
print(json.dumps(features, indent=4))
|
|
130
|
+
"""
|
|
131
|
+
Prints:
|
|
132
|
+
|
|
133
|
+
[
|
|
134
|
+
{
|
|
135
|
+
"id": "regid.2019-10.com.cisco.CML_ENT_BASE,\
|
|
136
|
+
1.0_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
|
|
137
|
+
"name": "CML - Enterprise License",
|
|
138
|
+
"description": "Cisco Modeling Labs - Enterprise License with 20 nodes \
|
|
139
|
+
capacity included",
|
|
140
|
+
"in_use": 1,
|
|
141
|
+
"status": "IN_COMPLIANCE",
|
|
142
|
+
"version": "1.0",
|
|
143
|
+
"min": 0,
|
|
144
|
+
"max": 1
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"id": "regid.2019-10.com.cisco.CML_NODE_COUNT,\
|
|
148
|
+
1.0_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
|
|
149
|
+
"name": "CML \u2013 Expansion Nodes",
|
|
150
|
+
"description": "Cisco Modeling Labs - Expansion node capacity for \
|
|
151
|
+
CML Enterprise Servers",
|
|
152
|
+
"in_use": 50,
|
|
153
|
+
"status": "IN_COMPLIANCE",
|
|
154
|
+
"version": "1.0",
|
|
155
|
+
"min": 0,
|
|
156
|
+
"max": 300
|
|
157
|
+
}
|
|
158
|
+
]
|
|
159
|
+
"""
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
#
|
|
3
|
+
# This file is part of VIRL 2
|
|
4
|
+
# Copyright (c) 2019-2024, Cisco Systems, Inc.
|
|
5
|
+
# All rights reserved.
|
|
6
|
+
#
|
|
7
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
8
|
+
#
|
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
# you may not use this file except in compliance with the License.
|
|
11
|
+
# You may obtain a copy of the License at
|
|
12
|
+
#
|
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
#
|
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
# See the License for the specific language governing permissions and
|
|
19
|
+
# limitations under the License.
|
|
20
|
+
#
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
import getpass
|
|
24
|
+
|
|
25
|
+
from httpx import HTTPStatusError
|
|
26
|
+
|
|
27
|
+
from virl2_client import ClientLibrary
|
|
28
|
+
|
|
29
|
+
VIRL_CONTROLLER = "virl2-controller"
|
|
30
|
+
VIRL_USERNAME = input("username: ")
|
|
31
|
+
VIRL_PASSWORD = getpass.getpass("password: ")
|
|
32
|
+
LAB_NAME = input("enter lab name: ")
|
|
33
|
+
|
|
34
|
+
client = ClientLibrary(VIRL_CONTROLLER, VIRL_USERNAME, VIRL_PASSWORD, ssl_verify=False)
|
|
35
|
+
|
|
36
|
+
# Find the lab by title and join it as long as it's the only
|
|
37
|
+
# lab with that title.
|
|
38
|
+
labs = client.find_labs_by_title(LAB_NAME)
|
|
39
|
+
|
|
40
|
+
if not labs or len(labs) != 1:
|
|
41
|
+
print(f"ERROR: Unable to find a unique lab named {LAB_NAME}")
|
|
42
|
+
exit(1)
|
|
43
|
+
|
|
44
|
+
lab = client.join_existing_lab(labs[0].id)
|
|
45
|
+
|
|
46
|
+
if not lab:
|
|
47
|
+
print(f"ERROR: Failed to join lab {LAB_NAME}")
|
|
48
|
+
exit(1)
|
|
49
|
+
|
|
50
|
+
# Print all links in the lab and ask which link to condition.
|
|
51
|
+
i = 1
|
|
52
|
+
links = []
|
|
53
|
+
for link in lab.links():
|
|
54
|
+
print(
|
|
55
|
+
f"{i}. {link.interface_a.node.label}[{link.interface_a.label}] <-> "
|
|
56
|
+
f"{link.interface_b.node.label}[{link.interface_b.label}]"
|
|
57
|
+
)
|
|
58
|
+
links.append(link.interface_a.get_link_to(link.interface_b))
|
|
59
|
+
i += 1
|
|
60
|
+
|
|
61
|
+
print()
|
|
62
|
+
link_number = 0
|
|
63
|
+
while link_number < 1 or link_number > i:
|
|
64
|
+
try:
|
|
65
|
+
link_number = int(input(f"Enter link number to condition (1-{i}): "))
|
|
66
|
+
except ValueError:
|
|
67
|
+
link_number = 0
|
|
68
|
+
|
|
69
|
+
# Print the selected link's current conditioning (if any).
|
|
70
|
+
link = links[link_number - 1]
|
|
71
|
+
print(f"Current condition is {link.get_condition()}")
|
|
72
|
+
# Request the new conditoning for bandwidth, latency, jitter, and loss.
|
|
73
|
+
# Bandwidth is an integer between 0-10000000 kbps
|
|
74
|
+
# Bandwidth of 0 is "no bandwidth restriction"
|
|
75
|
+
# Latency is an integer between 0-10000 ms
|
|
76
|
+
# Jitter is an integer between 0-10000 ms
|
|
77
|
+
# Loss is a float between 0-100%
|
|
78
|
+
new_condition = input(
|
|
79
|
+
"enter new condition in format 'BANDWIDTH, "
|
|
80
|
+
"LATENCY, JITTER, LOSS' or 'None' to disable: "
|
|
81
|
+
)
|
|
82
|
+
# If "None" is provided disable any conditioning on the link.
|
|
83
|
+
if new_condition.lower() == "none":
|
|
84
|
+
link.remove_condition()
|
|
85
|
+
print("Link conditioning has been disabled.")
|
|
86
|
+
else:
|
|
87
|
+
try:
|
|
88
|
+
# Set the current conditioning based on the provided values.
|
|
89
|
+
cond_list = new_condition.split(",")
|
|
90
|
+
bandwidth = int(cond_list[0]) # Bandwidth is an int
|
|
91
|
+
latency = int(cond_list[1]) # Latency is an int
|
|
92
|
+
jitter = int(cond_list[2]) # Jitter is an int
|
|
93
|
+
loss = float(cond_list[3]) # Loss is a float
|
|
94
|
+
link.set_condition(bandwidth, latency, jitter, loss)
|
|
95
|
+
print("Link conditioning set.")
|
|
96
|
+
except HTTPStatusError as exc:
|
|
97
|
+
print(f"ERROR: Failed to set link conditioning: {exc}")
|
|
98
|
+
exit(1)
|
examples/sample.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
#
|
|
3
|
+
# This file is part of VIRL 2
|
|
4
|
+
# Copyright (c) 2019-2024, Cisco Systems, Inc.
|
|
5
|
+
# All rights reserved.
|
|
6
|
+
#
|
|
7
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
8
|
+
#
|
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
# you may not use this file except in compliance with the License.
|
|
11
|
+
# You may obtain a copy of the License at
|
|
12
|
+
#
|
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
#
|
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
# See the License for the specific language governing permissions and
|
|
19
|
+
# limitations under the License.
|
|
20
|
+
#
|
|
21
|
+
|
|
22
|
+
# This script demonstrates various functionalities of the client library.
|
|
23
|
+
# Each example is accompanied by comments explaining its purpose and usage.
|
|
24
|
+
import pathlib
|
|
25
|
+
|
|
26
|
+
from virl2_client import ClientLibrary
|
|
27
|
+
|
|
28
|
+
SSMS = "https://sch-alpha.cisco.com/its/service/oddce/services/DDCEService"
|
|
29
|
+
|
|
30
|
+
TOKEN = (
|
|
31
|
+
"FFY4YzJjNjItMDUxNi00NjJhLWIzMzQtMzllMzEzN2NhYjk2"
|
|
32
|
+
"6s8e1gr5res1g35ads1g651rg23rs1gs3rd5g1s2rd1g3s2r"
|
|
33
|
+
"WhPV3MzWGJrT3U5VHVEL1NrWkNu%0AclBSST0%3D%0A"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# Set up the CML 2 connection
|
|
38
|
+
server_url = "http://localhost:8001"
|
|
39
|
+
username = "cml2" # Default username if not changed in CML instance
|
|
40
|
+
password = pathlib.Path("/etc/machine-id").read_text().strip()
|
|
41
|
+
# Default password is equal to the contents of the CML instances /etc/machine-id file
|
|
42
|
+
# If you are running this script remotely, replace the password above
|
|
43
|
+
client_library = ClientLibrary(server_url, username, password, allow_http=True)
|
|
44
|
+
|
|
45
|
+
# Check if the CML 2 system is ready
|
|
46
|
+
client_library.is_system_ready(wait=True)
|
|
47
|
+
|
|
48
|
+
# Set up licensing configuration
|
|
49
|
+
client_library.licensing.set_transport(ssms=SSMS)
|
|
50
|
+
client_library.licensing.register_wait(token=TOKEN)
|
|
51
|
+
|
|
52
|
+
# Get a list of existing labs and print their details
|
|
53
|
+
lab_list = client_library.get_lab_list()
|
|
54
|
+
for lab_id in lab_list:
|
|
55
|
+
lab = client_library.join_existing_lab(lab_id)
|
|
56
|
+
print("Lab ID:", lab.id)
|
|
57
|
+
print("Lab Title:", lab.title)
|
|
58
|
+
print("Lab Description:", lab.description)
|
|
59
|
+
print("Lab State:", lab.state)
|
|
60
|
+
print("----")
|
|
61
|
+
|
|
62
|
+
# A simpler way to join all labs at once
|
|
63
|
+
labs = client_library.all_labs()
|
|
64
|
+
|
|
65
|
+
# Create a lab
|
|
66
|
+
lab = client_library.create_lab()
|
|
67
|
+
|
|
68
|
+
# Create two server nodes
|
|
69
|
+
server1 = lab.create_node("server1", "server", 50, 100)
|
|
70
|
+
server2 = lab.create_node("server2", "server", 50, 200)
|
|
71
|
+
print("Created nodes:", server1, server2)
|
|
72
|
+
|
|
73
|
+
# Create a link between server1 and server2
|
|
74
|
+
link = lab.connect_two_nodes(server1, server2)
|
|
75
|
+
print("Created link between server1 and server2")
|
|
76
|
+
|
|
77
|
+
# Remove the link between server1 and server2
|
|
78
|
+
link.remove()
|
|
79
|
+
print("Removed link between server1 and server2")
|
|
80
|
+
|
|
81
|
+
# Manually synchronize lab states - this happens automatically once per second
|
|
82
|
+
# by default, but we can skip the wait by calling this method
|
|
83
|
+
lab.sync_states()
|
|
84
|
+
|
|
85
|
+
# Print the state of each node and its interfaces
|
|
86
|
+
for node in lab.nodes():
|
|
87
|
+
print(f"Node: {node.label} | State: {node.state}")
|
|
88
|
+
for interface in node.interfaces():
|
|
89
|
+
print(f" Interface: {interface.label} | State: {interface.state}")
|
|
90
|
+
|
|
91
|
+
# Export a lab topology to a file
|
|
92
|
+
lab_data = lab.download()
|
|
93
|
+
with open("demo_lab_export.yaml", "w") as file:
|
|
94
|
+
file.write(lab_data)
|
|
95
|
+
print("Lab exported successfully.")
|
|
96
|
+
|
|
97
|
+
# Clean up the lab
|
|
98
|
+
lab.stop()
|
|
99
|
+
lab.wipe()
|
|
100
|
+
lab.remove() # or client_library.remove_lab(lab_id)
|
|
101
|
+
|
|
102
|
+
# Deregister (optional) and set licensing back to the default transport (optional)
|
|
103
|
+
# Default SSMS is "https://smartreceiver.cisco.com/licservice/license"
|
|
104
|
+
client_library.licensing.deregister()
|
|
105
|
+
client_library.licensing.set_default_transport()
|
virl2_client/__init__.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2024, Cisco Systems, Inc.
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
7
|
+
#
|
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
# you may not use this file except in compliance with the License.
|
|
10
|
+
# You may obtain a copy of the License at
|
|
11
|
+
#
|
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
#
|
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
# See the License for the specific language governing permissions and
|
|
18
|
+
# limitations under the License.
|
|
19
|
+
#
|
|
20
|
+
|
|
21
|
+
from .exceptions import InterfaceNotFound, LabNotFound, LinkNotFound, NodeNotFound
|
|
22
|
+
from .virl2_client import ClientConfig, ClientLibrary, InitializationError
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"InterfaceNotFound",
|
|
26
|
+
"LabNotFound",
|
|
27
|
+
"LinkNotFound",
|
|
28
|
+
"NodeNotFound",
|
|
29
|
+
"ClientConfig",
|
|
30
|
+
"ClientLibrary",
|
|
31
|
+
"InitializationError",
|
|
32
|
+
]
|