virl2_client 2.3.0__tar.gz → 2.4.0__tar.gz
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.
- {virl2_client-2.3.0 → virl2_client-2.4.0}/PKG-INFO +11 -3
- {virl2_client-2.3.0 → virl2_client-2.4.0}/README.md +6 -1
- {virl2_client-2.3.0 → virl2_client-2.4.0}/examples/licensing.py +5 -5
- {virl2_client-2.3.0 → virl2_client-2.4.0}/examples/link_conditioning.py +3 -3
- {virl2_client-2.3.0 → virl2_client-2.4.0}/examples/sample.py +4 -4
- {virl2_client-2.3.0 → virl2_client-2.4.0}/pyproject.toml +13 -10
- virl2_client-2.4.0/setup.py +34 -0
- virl2_client-2.4.0/virl2_client/__init__.py +25 -0
- {virl2_client-2.3.0 → virl2_client-2.4.0}/virl2_client/exceptions.py +3 -3
- {virl2_client-2.3.0 → virl2_client-2.4.0}/virl2_client/models/__init__.py +3 -3
- {virl2_client-2.3.0 → virl2_client-2.4.0}/virl2_client/models/authentication.py +5 -15
- {virl2_client-2.3.0 → virl2_client-2.4.0}/virl2_client/models/cl_pyats.py +5 -5
- {virl2_client-2.3.0 → virl2_client-2.4.0}/virl2_client/models/groups.py +3 -3
- {virl2_client-2.3.0 → virl2_client-2.4.0}/virl2_client/models/interface.py +4 -3
- {virl2_client-2.3.0 → virl2_client-2.4.0}/virl2_client/models/lab.py +127 -82
- {virl2_client-2.3.0 → virl2_client-2.4.0}/virl2_client/models/licensing.py +5 -5
- {virl2_client-2.3.0 → virl2_client-2.4.0}/virl2_client/models/link.py +10 -7
- {virl2_client-2.3.0 → virl2_client-2.4.0}/virl2_client/models/node.py +14 -8
- {virl2_client-2.3.0 → virl2_client-2.4.0}/virl2_client/models/node_image_definitions.py +3 -5
- {virl2_client-2.3.0 → virl2_client-2.4.0}/virl2_client/models/system.py +3 -3
- {virl2_client-2.3.0 → virl2_client-2.4.0}/virl2_client/models/users.py +3 -3
- {virl2_client-2.3.0 → virl2_client-2.4.0}/virl2_client/utils.py +3 -3
- {virl2_client-2.3.0 → virl2_client-2.4.0}/virl2_client/virl2_client.py +37 -23
- virl2_client-2.3.0/setup.py +0 -30
- virl2_client-2.3.0/virl2_client/__init__.py +0 -25
- {virl2_client-2.3.0 → virl2_client-2.4.0}/LICENSE +0 -0
- {virl2_client-2.3.0 → virl2_client-2.4.0}/examples/demo.ipynb +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: virl2-client
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.0
|
|
4
4
|
Summary: VIRL2 Client Library
|
|
5
5
|
Home-page: https://github.com/ciscodevnet/virl2-client
|
|
6
6
|
License: Apache-2.0
|
|
7
7
|
Author: Simon Knight
|
|
8
8
|
Author-email: simknigh@cisco.com
|
|
9
|
-
Requires-Python: >=3.
|
|
9
|
+
Requires-Python: >=3.7.0,<4.0.0
|
|
10
10
|
Classifier: Development Status :: 4 - Beta
|
|
11
11
|
Classifier: Environment :: Console
|
|
12
12
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
@@ -18,8 +18,11 @@ Classifier: Programming Language :: Python :: 3.7
|
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.8
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.9
|
|
20
20
|
Classifier: Topic :: System :: Networking
|
|
21
|
+
Provides-Extra: pyats
|
|
22
|
+
Requires-Dist: pyats (>=22.4,<23.0); extra == "pyats"
|
|
21
23
|
Requires-Dist: requests (>=2,<3)
|
|
22
24
|
Requires-Dist: requests-toolbelt (>=0.9.1,<0.10.0)
|
|
25
|
+
Requires-Dist: urllib3 (>=1.26.9,<2.0.0)
|
|
23
26
|
Project-URL: Repository, https://github.com/ciscodevnet/virl2-client
|
|
24
27
|
Description-Content-Type: text/markdown
|
|
25
28
|
|
|
@@ -34,7 +37,7 @@ This is the client library for the Cisco VIRL 2 Network Simulation Platform
|
|
|
34
37
|
edit, delete and control network simulations on a VIRL 2 controller.
|
|
35
38
|
|
|
36
39
|
It is a pure Python implementation that requires Python3. We've tested and
|
|
37
|
-
written the package with Python 3.
|
|
40
|
+
written the package with Python 3.8.10.
|
|
38
41
|
|
|
39
42
|
The **status** of this package can be considered **Beta**. We're not aware of
|
|
40
43
|
any major issues at the time of release. However, since this is the first
|
|
@@ -71,6 +74,11 @@ proper version/build information. For example
|
|
|
71
74
|
|
|
72
75
|
We recommend the use of a virtual environment for installation.
|
|
73
76
|
|
|
77
|
+
If you want to interact with devices via the client library, you need to
|
|
78
|
+
install pyATS library.
|
|
79
|
+
|
|
80
|
+
pip3 install pyats
|
|
81
|
+
|
|
74
82
|
## Usage
|
|
75
83
|
|
|
76
84
|
The package itself is fairly well documented using docstrings. In addition, the
|
|
@@ -9,7 +9,7 @@ This is the client library for the Cisco VIRL 2 Network Simulation Platform
|
|
|
9
9
|
edit, delete and control network simulations on a VIRL 2 controller.
|
|
10
10
|
|
|
11
11
|
It is a pure Python implementation that requires Python3. We've tested and
|
|
12
|
-
written the package with Python 3.
|
|
12
|
+
written the package with Python 3.8.10.
|
|
13
13
|
|
|
14
14
|
The **status** of this package can be considered **Beta**. We're not aware of
|
|
15
15
|
any major issues at the time of release. However, since this is the first
|
|
@@ -46,6 +46,11 @@ proper version/build information. For example
|
|
|
46
46
|
|
|
47
47
|
We recommend the use of a virtual environment for installation.
|
|
48
48
|
|
|
49
|
+
If you want to interact with devices via the client library, you need to
|
|
50
|
+
install pyATS library.
|
|
51
|
+
|
|
52
|
+
pip3 install pyats
|
|
53
|
+
|
|
49
54
|
## Usage
|
|
50
55
|
|
|
51
56
|
The package itself is fairly well documented using docstrings. In addition, the
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
#
|
|
3
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
4
|
-
#
|
|
5
3
|
# This file is part of VIRL 2
|
|
4
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
5
|
+
# All rights reserved.
|
|
6
6
|
#
|
|
7
|
-
#
|
|
7
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
8
8
|
#
|
|
9
9
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
10
|
# you may not use this file except in compliance with the License.
|
|
@@ -97,12 +97,12 @@ Prints:
|
|
|
97
97
|
},
|
|
98
98
|
"reservation_mode": false,
|
|
99
99
|
"transport": {
|
|
100
|
-
"ssms": "https://
|
|
100
|
+
"ssms": "https://smartreceiver.cisco.com/licservice/license",
|
|
101
101
|
"proxy": {
|
|
102
102
|
"server": null,
|
|
103
103
|
"port": null
|
|
104
104
|
},
|
|
105
|
-
"default_ssms": "https://
|
|
105
|
+
"default_ssms": "https://smartreceiver.cisco.com/licservice/license"
|
|
106
106
|
},
|
|
107
107
|
"features": [
|
|
108
108
|
{
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
#
|
|
3
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
4
|
-
#
|
|
5
3
|
# This file is part of VIRL 2
|
|
4
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
5
|
+
# All rights reserved.
|
|
6
6
|
#
|
|
7
|
-
#
|
|
7
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
8
8
|
#
|
|
9
9
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
10
|
# you may not use this file except in compliance with the License.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
#
|
|
3
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
4
|
-
#
|
|
5
3
|
# This file is part of VIRL 2
|
|
4
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
5
|
+
# All rights reserved.
|
|
6
6
|
#
|
|
7
|
-
#
|
|
7
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
8
8
|
#
|
|
9
9
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
10
|
# you may not use this file except in compliance with the License.
|
|
@@ -94,5 +94,5 @@ assert [link for link in lab.links() if link.state is not None] == []
|
|
|
94
94
|
status = cl.licensing.deregister()
|
|
95
95
|
cl.licensing.remove_certificate()
|
|
96
96
|
# set licensing back to default transport
|
|
97
|
-
# default ssms is "https://
|
|
97
|
+
# default ssms is "https://smartreceiver.cisco.com/licservice/license"
|
|
98
98
|
cl.licensing.set_default_transport()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "virl2_client"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.4.0"
|
|
4
4
|
description = "VIRL2 Client Library"
|
|
5
5
|
authors = ["Simon Knight <simknigh@cisco.com>", "Ralph Schmieder <rschmied@cisco.com>"]
|
|
6
6
|
license = "Apache-2.0"
|
|
@@ -20,22 +20,25 @@ classifiers = [
|
|
|
20
20
|
]
|
|
21
21
|
|
|
22
22
|
[tool.poetry.dependencies]
|
|
23
|
-
python = "^3.
|
|
23
|
+
python = "^3.7.0"
|
|
24
24
|
requests = "^2"
|
|
25
25
|
requests-toolbelt = "^0.9.1"
|
|
26
|
+
urllib3 = "^1.26.9"
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
# For integration tests, pyATS is needed (Unicon)
|
|
28
|
+
# optional pyats package
|
|
29
29
|
# (this pulls in a lot more dependencies)
|
|
30
|
-
|
|
30
|
+
pyats = {version = "^22.4", optional = true}
|
|
31
|
+
|
|
32
|
+
[tool.poetry.dev-dependencies]
|
|
33
|
+
flake8 = "^4.0.1"
|
|
34
|
+
pre-commit = "^2.17.0"
|
|
31
35
|
pytest = "*"
|
|
32
36
|
requests-mock = "^1.9.2"
|
|
33
|
-
responses = "
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
responses = "^0.20.0"
|
|
38
|
+
|
|
39
|
+
[tool.poetry.extras]
|
|
40
|
+
pyats = ["pyats"]
|
|
37
41
|
|
|
38
42
|
[build-system]
|
|
39
43
|
requires = ["poetry>=1.1.8"]
|
|
40
44
|
build-backend = "poetry.masonry.api"
|
|
41
|
-
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from setuptools import setup
|
|
3
|
+
|
|
4
|
+
packages = \
|
|
5
|
+
['virl2_client', 'virl2_client.models']
|
|
6
|
+
|
|
7
|
+
package_data = \
|
|
8
|
+
{'': ['*']}
|
|
9
|
+
|
|
10
|
+
install_requires = \
|
|
11
|
+
['requests-toolbelt>=0.9.1,<0.10.0', 'requests>=2,<3', 'urllib3>=1.26.9,<2.0.0']
|
|
12
|
+
|
|
13
|
+
extras_require = \
|
|
14
|
+
{'pyats': ['pyats>=22.4,<23.0']}
|
|
15
|
+
|
|
16
|
+
setup_kwargs = {
|
|
17
|
+
'name': 'virl2-client',
|
|
18
|
+
'version': '2.4.0',
|
|
19
|
+
'description': 'VIRL2 Client Library',
|
|
20
|
+
'long_description': '[](https://github.com/CiscoDevNet/virl2-client/actions/workflows/main.yml)\n\n# VIRL 2 Client Library\n\n## Introduction\n\nThis is the client library for the Cisco VIRL 2 Network Simulation Platform\n(`virl2_client`). It provides a Python package to programmatically create,\nedit, delete and control network simulations on a VIRL 2 controller.\n\nIt is a pure Python implementation that requires Python3. We\'ve tested and\nwritten the package with Python 3.8.10.\n\nThe **status** of this package can be considered **Beta**. We\'re not aware of\nany major issues at the time of release. However, since this is the first\nrelease of the package, bugs might exist. Both in the package as well as in\nthe API implementation on the controller.\n\n## Use Case Description\n\nThe client library provides a convenient interface to control the lifecycle of\na network simulation. This can be used for automation scripts directly in\nPython but also for third party integrations / plugins which need to integrate\nwith a simulated network. Examples already existing are an [Ansible\nplugin](https://github.com/CiscoDevNet/ansible-virl).\n\n## Installation\n\nThe package comes in form of a wheel that is downloadable from the VIRL 2\ncontroller. The package can be installed either from PyPi using\n\n pip3 install virl2_client\n\nor, alternatively, the version that is bundled with the VIRL 2 controller can\nbe downloaded to the local filesystem and then directly installed via\n\n pip3 install ./virl2_client-*.whl\n\nThe bundled version is available on the index site of the docs when viewed\ndirectly on the VIRL 2 controller.\n\nEnsure to replace use the correct file name, replacing the wildcard with the\nproper version/build information. For example\n\n pip3 install virl2_client-2.0.0b10-py3-none-any.whl\n\nWe recommend the use of a virtual environment for installation.\n\nIf you want to interact with devices via the client library, you need to\ninstall pyATS library.\n\n pip3 install pyats\n\n## Usage\n\nThe package itself is fairly well documented using docstrings. In addition, the\ndocumentation is available in HTML format on the controller itself, via the\n"Tools -> Client Library" menu.\n\n## Compatibility\n\nThis package and the used API is specific to VIRL 2. It is not\nbackwards compatible with VIRL 1.x and therefore can not be used with VIRL\n1.x. If you are looking for a convenient tool to interface with the VIRL 1 API\nthen the [VIRL Utils tool](https://github.com/CiscoDevNet/virlutils) is\nrecommended.\n\n## Known Issues\n\nThere are no known issues at this point. See the comment in the *Introduction*\nsection.\n\n## Getting Help\n\nIf you have questions, concerns, bug reports, etc., please create an issue\nagainst the [repository on\nGitHub](https://github.com/CiscoDevNet/virl2-client/)\n\n## Getting Involved\n\nWe welcome contributions. Whether you fixed a bug, added a new feature or\ncorrected a typo, all contributions are welcome. General instructions on how to\ncontribute can be found in the [CONTRIBUTING](CONTRIBUTING.md) file.\n\n## Licensing Info\n\nThis code is licensed under the Apache 2.0 License. See [LICENSE](LICENSE) for\ndetails.\n\n## References\n\nThis package is part of the VIRL 2 Network Simulation platform. For details, go\nto https://developer.cisco.com/modeling-labs. Additional documentation for the\nproduct is available at https://developer.cisco.com/docs/modeling-labs\n',
|
|
21
|
+
'author': 'Simon Knight',
|
|
22
|
+
'author_email': 'simknigh@cisco.com',
|
|
23
|
+
'maintainer': None,
|
|
24
|
+
'maintainer_email': None,
|
|
25
|
+
'url': 'https://github.com/ciscodevnet/virl2-client',
|
|
26
|
+
'packages': packages,
|
|
27
|
+
'package_data': package_data,
|
|
28
|
+
'install_requires': install_requires,
|
|
29
|
+
'extras_require': extras_require,
|
|
30
|
+
'python_requires': '>=3.7.0,<4.0.0',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
setup(**setup_kwargs)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2022, 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
|
+
# flake8: noqa: F401
|
|
22
|
+
|
|
23
|
+
from .exceptions import InterfaceNotFound, LabNotFound, LinkNotFound, NodeNotFound
|
|
24
|
+
from .virl2_client import ClientConfig, ClientLibrary, InitializationError
|
|
25
|
+
from .models.authentication import Context
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
3
|
-
#
|
|
4
2
|
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
4
|
+
# All rights reserved.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
7
7
|
#
|
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
9
|
# you may not use this file except in compliance with the License.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
3
|
-
#
|
|
4
2
|
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
4
|
+
# All rights reserved.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
7
7
|
#
|
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
9
|
# you may not use this file except in compliance with the License.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
3
|
-
#
|
|
4
2
|
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
4
|
+
# All rights reserved.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
7
7
|
#
|
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
9
|
# you may not use this file except in compliance with the License.
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
#
|
|
20
20
|
|
|
21
21
|
import logging
|
|
22
|
-
import uuid
|
|
23
22
|
from urllib.parse import urljoin, urlparse
|
|
24
23
|
|
|
25
24
|
import requests
|
|
@@ -93,23 +92,18 @@ class TokenAuth(requests.auth.AuthBase):
|
|
|
93
92
|
|
|
94
93
|
|
|
95
94
|
class Context:
|
|
96
|
-
def __init__(self, base_url, requests_session=None
|
|
95
|
+
def __init__(self, base_url, requests_session=None):
|
|
97
96
|
self._base_url = base_url
|
|
98
|
-
if client_uuid is None:
|
|
99
|
-
self._client_uuid = str(uuid.uuid4())
|
|
100
|
-
else:
|
|
101
|
-
self._client_uuid = client_uuid
|
|
102
97
|
if requests_session is None:
|
|
103
98
|
self._requests_session = requests.Session()
|
|
104
99
|
else:
|
|
105
100
|
self._requests_session = requests_session
|
|
106
101
|
|
|
107
102
|
def __repr__(self):
|
|
108
|
-
return "{}({!r}, {!r}
|
|
103
|
+
return "{}({!r}, {!r}".format(
|
|
109
104
|
self.__class__.__name__,
|
|
110
105
|
self._base_url,
|
|
111
106
|
self._requests_session,
|
|
112
|
-
self._client_uuid,
|
|
113
107
|
)
|
|
114
108
|
|
|
115
109
|
@property
|
|
@@ -119,7 +113,3 @@ class Context:
|
|
|
119
113
|
@property
|
|
120
114
|
def session(self):
|
|
121
115
|
return self._requests_session
|
|
122
|
-
|
|
123
|
-
@property
|
|
124
|
-
def uuid(self):
|
|
125
|
-
return self._client_uuid
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
3
|
-
#
|
|
4
2
|
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
4
|
+
# All rights reserved.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
7
7
|
#
|
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
9
|
# you may not use this file except in compliance with the License.
|
|
@@ -103,7 +103,7 @@ class ClPyats:
|
|
|
103
103
|
|
|
104
104
|
# TODO: later check if connected
|
|
105
105
|
# TODO: later look at pooling connections
|
|
106
|
-
pyats_device.connect(log_stdout=False)
|
|
106
|
+
pyats_device.connect(log_stdout=False, learn_hostname=True)
|
|
107
107
|
self._connections.append(pyats_device)
|
|
108
108
|
return pyats_device.execute(command, log_stdout=False)
|
|
109
109
|
|
|
@@ -127,7 +127,7 @@ class ClPyats:
|
|
|
127
127
|
|
|
128
128
|
# TODO: later check if connected
|
|
129
129
|
# TODO: later look at pooling connections
|
|
130
|
-
pyats_device.connect(log_stdout=False)
|
|
130
|
+
pyats_device.connect(log_stdout=False, learn_hostname=True)
|
|
131
131
|
self._connections.append(pyats_device)
|
|
132
132
|
return pyats_device.configure(command, log_stdout=False)
|
|
133
133
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
3
|
-
#
|
|
4
2
|
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
4
|
+
# All rights reserved.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
7
7
|
#
|
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
9
|
# you may not use this file except in compliance with the License.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
3
|
-
#
|
|
4
2
|
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
4
|
+
# All rights reserved.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
7
7
|
#
|
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
9
|
# you may not use this file except in compliance with the License.
|
|
@@ -179,4 +179,5 @@ class Interface:
|
|
|
179
179
|
|
|
180
180
|
@property
|
|
181
181
|
def state(self):
|
|
182
|
+
self.node.lab.sync_states_if_outdated()
|
|
182
183
|
return self._state
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
3
|
-
#
|
|
4
2
|
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
4
|
+
# All rights reserved.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
7
7
|
#
|
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
9
|
# you may not use this file except in compliance with the License.
|
|
@@ -253,16 +253,6 @@ class Lab:
|
|
|
253
253
|
response.raise_for_status()
|
|
254
254
|
self._description = value
|
|
255
255
|
|
|
256
|
-
@property
|
|
257
|
-
def client_uuid(self):
|
|
258
|
-
"""
|
|
259
|
-
Returns the client UUID This random ID identifies a client session.
|
|
260
|
-
|
|
261
|
-
:returns: A UUID4
|
|
262
|
-
:rtype: str
|
|
263
|
-
"""
|
|
264
|
-
return self._context.uuid
|
|
265
|
-
|
|
266
256
|
@property
|
|
267
257
|
def session(self):
|
|
268
258
|
"""
|
|
@@ -424,7 +414,14 @@ class Lab:
|
|
|
424
414
|
return [node for node in self.nodes() if tag in node.tags()]
|
|
425
415
|
|
|
426
416
|
def create_node(
|
|
427
|
-
self,
|
|
417
|
+
self,
|
|
418
|
+
label,
|
|
419
|
+
node_definition,
|
|
420
|
+
x=0,
|
|
421
|
+
y=0,
|
|
422
|
+
wait=None,
|
|
423
|
+
populate_interfaces=False,
|
|
424
|
+
**kwargs
|
|
428
425
|
):
|
|
429
426
|
"""
|
|
430
427
|
Creates a node in the lab with the given parameters.
|
|
@@ -735,7 +732,7 @@ class Lab:
|
|
|
735
732
|
disk_write = 0
|
|
736
733
|
|
|
737
734
|
self._nodes[node_id].statistics = {
|
|
738
|
-
"cpu_usage": float(node_data
|
|
735
|
+
"cpu_usage": float(node_data.get("cpu_usage", 0)),
|
|
739
736
|
"disk_read": disk_read,
|
|
740
737
|
"disk_write": disk_write,
|
|
741
738
|
}
|
|
@@ -817,7 +814,9 @@ class Lab:
|
|
|
817
814
|
|
|
818
815
|
def wait_until_lab_converged(self, max_iterations=None, wait_time=None):
|
|
819
816
|
"""Wait until lab converge."""
|
|
820
|
-
max_iter =
|
|
817
|
+
max_iter = (
|
|
818
|
+
self.wait_max_iterations if max_iterations is None else max_iterations
|
|
819
|
+
)
|
|
821
820
|
wait_time = self.wait_time if wait_time is None else wait_time
|
|
822
821
|
logger.info("Waiting for lab %s to converge", self._lab_id)
|
|
823
822
|
for index in range(max_iter):
|
|
@@ -835,7 +834,8 @@ class Lab:
|
|
|
835
834
|
time.sleep(wait_time)
|
|
836
835
|
|
|
837
836
|
msg = "Lab %s has not converged, maximum tries %s exceeded" % (
|
|
838
|
-
self.id,
|
|
837
|
+
self.id,
|
|
838
|
+
max_iter,
|
|
839
839
|
)
|
|
840
840
|
logger.error(msg)
|
|
841
841
|
# after maximum retries are exceeded and lab has not converged
|
|
@@ -880,9 +880,15 @@ class Lab:
|
|
|
880
880
|
return response.json()
|
|
881
881
|
|
|
882
882
|
def is_active(self):
|
|
883
|
-
"
|
|
884
|
-
|
|
885
|
-
|
|
883
|
+
"""
|
|
884
|
+
Returns whether the lab is started.
|
|
885
|
+
|
|
886
|
+
Deprecated since 2.4 (will be removed in 2.5)
|
|
887
|
+
:returns: Whether the lab is started
|
|
888
|
+
:rtype: bool
|
|
889
|
+
"""
|
|
890
|
+
logger.warning("Deprecated since 2.4 (will be removed in 2.5)")
|
|
891
|
+
return self.state() == "STARTED"
|
|
886
892
|
|
|
887
893
|
def details(self):
|
|
888
894
|
"""
|
|
@@ -1008,26 +1014,32 @@ class Lab:
|
|
|
1008
1014
|
self._last_sync_topology_time = time.time()
|
|
1009
1015
|
|
|
1010
1016
|
def import_lab(self, topology):
|
|
1011
|
-
self.
|
|
1012
|
-
self._description = topology["lab_description"]
|
|
1013
|
-
self._notes = topology["lab_notes"]
|
|
1014
|
-
self._owner = topology.get("lab_owner", self.username)
|
|
1015
|
-
# TODO: add support for origin_id etc
|
|
1017
|
+
self._import_lab(topology)
|
|
1016
1018
|
|
|
1017
1019
|
for node in topology["nodes"]:
|
|
1018
1020
|
node_id = node["id"]
|
|
1019
1021
|
if node_id in self._nodes:
|
|
1020
1022
|
raise Exception("Node already exists")
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1023
|
+
self._import_node(node_id, node)
|
|
1024
|
+
|
|
1025
|
+
if "interfaces" not in node:
|
|
1026
|
+
# logger.warning("Deprecated since 2.4 (will be removed in 2.5)")
|
|
1027
|
+
continue
|
|
1028
|
+
|
|
1029
|
+
for iface in node["interfaces"]:
|
|
1030
|
+
iface_id = iface["id"]
|
|
1031
|
+
if iface_id in self._interfaces:
|
|
1032
|
+
raise Exception("Interface already exists")
|
|
1033
|
+
self._import_interface(iface_id, node_id, iface)
|
|
1034
|
+
|
|
1035
|
+
if "interfaces" in topology:
|
|
1036
|
+
# logger.warning("Deprecated since 2.4 (will be removed in 2.5)")
|
|
1037
|
+
for iface in topology["interfaces"]:
|
|
1038
|
+
iface_id = iface["id"]
|
|
1039
|
+
node_id = iface["node"]
|
|
1040
|
+
if iface_id in self._interfaces:
|
|
1041
|
+
raise Exception("Interface already exists")
|
|
1042
|
+
self._import_interface(iface_id, node_id, iface)
|
|
1031
1043
|
|
|
1032
1044
|
for link in topology["links"]:
|
|
1033
1045
|
link_id = link["id"]
|
|
@@ -1037,24 +1049,45 @@ class Lab:
|
|
|
1037
1049
|
iface_b_id = link["interface_b"]
|
|
1038
1050
|
self._import_link(link_id, iface_b_id, iface_a_id)
|
|
1039
1051
|
|
|
1052
|
+
def _import_lab(self, topology):
|
|
1053
|
+
lab_dict = topology.get("lab")
|
|
1054
|
+
if lab_dict is None:
|
|
1055
|
+
logger.warning("Deprecated since 2.4 (will be removed in 2.5)")
|
|
1056
|
+
self._title = topology["lab_title"]
|
|
1057
|
+
self._description = topology["lab_description"]
|
|
1058
|
+
self._notes = topology["lab_notes"]
|
|
1059
|
+
self._owner = topology["lab_owner"]
|
|
1060
|
+
# topology.get("lab_owner", self.username)
|
|
1061
|
+
else:
|
|
1062
|
+
self._title = lab_dict["title"]
|
|
1063
|
+
self._description = lab_dict["description"]
|
|
1064
|
+
self._notes = lab_dict["notes"]
|
|
1065
|
+
self._owner = lab_dict.get("owner", self.username)
|
|
1066
|
+
|
|
1040
1067
|
def _import_link(self, link_id, iface_b_id, iface_a_id):
|
|
1041
1068
|
iface_a = self._interfaces[iface_a_id]
|
|
1042
1069
|
iface_b = self._interfaces[iface_b_id]
|
|
1043
1070
|
return self.create_link_local(iface_a, iface_b, link_id)
|
|
1044
1071
|
|
|
1045
1072
|
def _import_interface(self, iface_id, node_id, iface_data):
|
|
1073
|
+
if "data" in iface_data:
|
|
1074
|
+
# logger.warning("Deprecated since 2.4 (will be removed in 2.5)")
|
|
1075
|
+
iface_data = iface_data["data"]
|
|
1046
1076
|
label = iface_data["label"]
|
|
1047
|
-
slot = iface_data
|
|
1077
|
+
slot = iface_data.get("slot")
|
|
1048
1078
|
iface_type = iface_data["type"]
|
|
1049
1079
|
node = self._nodes[node_id]
|
|
1050
1080
|
return self.create_interface_local(iface_id, label, node, slot, iface_type)
|
|
1051
1081
|
|
|
1052
1082
|
def _import_node(self, node_id, node_data):
|
|
1083
|
+
if "data" in node_data:
|
|
1084
|
+
# logger.warning("Deprecated since 2.4 (will be removed in 2.5)")
|
|
1085
|
+
node_data = node_data["data"]
|
|
1053
1086
|
label = node_data["label"]
|
|
1054
1087
|
x = node_data["x"]
|
|
1055
1088
|
y = node_data["y"]
|
|
1056
1089
|
node_definition = node_data["node_definition"]
|
|
1057
|
-
image_definition = node_data
|
|
1090
|
+
image_definition = node_data.get("image_definition", None)
|
|
1058
1091
|
ram = node_data["ram"]
|
|
1059
1092
|
cpus = node_data["cpus"]
|
|
1060
1093
|
cpu_limit = node_data.get("cpu_limit", 100)
|
|
@@ -1079,11 +1112,7 @@ class Lab:
|
|
|
1079
1112
|
)
|
|
1080
1113
|
|
|
1081
1114
|
def update_lab(self, topology, exclude_configurations):
|
|
1082
|
-
self.
|
|
1083
|
-
self._description = topology["lab_description"]
|
|
1084
|
-
self._notes = topology["lab_notes"]
|
|
1085
|
-
self._owner = topology.get("lab_owner", self.username)
|
|
1086
|
-
# TODO: add support for origin_id etc
|
|
1115
|
+
self._import_lab(topology)
|
|
1087
1116
|
|
|
1088
1117
|
# add in order: node -> interface -> link
|
|
1089
1118
|
# remove in reverse, eg link -> interface -> node
|
|
@@ -1093,9 +1122,15 @@ class Lab:
|
|
|
1093
1122
|
|
|
1094
1123
|
update_node_keys = set(node["id"] for node in topology["nodes"])
|
|
1095
1124
|
update_link_keys = set(links["id"] for links in topology["links"])
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1125
|
+
if "interfaces" in topology:
|
|
1126
|
+
# logger.warning("Deprecated since 2.4 (will be removed in 2.5)")
|
|
1127
|
+
update_interface_keys = set(iface["id"] for iface in topology["interfaces"])
|
|
1128
|
+
else:
|
|
1129
|
+
update_interface_keys = set(
|
|
1130
|
+
interface["id"]
|
|
1131
|
+
for node in topology["nodes"]
|
|
1132
|
+
for interface in node["interfaces"]
|
|
1133
|
+
)
|
|
1099
1134
|
|
|
1100
1135
|
# removed elements
|
|
1101
1136
|
removed_nodes = existing_node_keys - update_node_keys
|
|
@@ -1122,18 +1157,29 @@ class Lab:
|
|
|
1122
1157
|
new_links = update_link_keys - existing_link_keys
|
|
1123
1158
|
new_interfaces = update_interface_keys - existing_interface_keys
|
|
1124
1159
|
|
|
1125
|
-
for
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
interface
|
|
1136
|
-
|
|
1160
|
+
for node in topology["nodes"]:
|
|
1161
|
+
node_id = node["id"]
|
|
1162
|
+
if node_id in new_nodes:
|
|
1163
|
+
node = self._import_node(node_id, node)
|
|
1164
|
+
logger.info("Added node %s", node)
|
|
1165
|
+
|
|
1166
|
+
if "interfaces" in topology:
|
|
1167
|
+
# logger.warning("Deprecated since 2.4 (will be removed in 2.5)")
|
|
1168
|
+
continue
|
|
1169
|
+
|
|
1170
|
+
for interface in node["interfaces"]:
|
|
1171
|
+
interface_id = interface["id"]
|
|
1172
|
+
if interface_id in new_interfaces:
|
|
1173
|
+
interface = self._import_interface(interface_id, node_id, interface)
|
|
1174
|
+
logger.info("Added interface %s", interface)
|
|
1175
|
+
|
|
1176
|
+
if "interfaces" in topology:
|
|
1177
|
+
# logger.warning("Deprecated since 2.4 (will be removed in 2.5)")
|
|
1178
|
+
for iface in topology["interfaces"]:
|
|
1179
|
+
iface_id = iface["id"]
|
|
1180
|
+
if iface_id in new_interfaces:
|
|
1181
|
+
node_id = iface["node"]
|
|
1182
|
+
self._import_interface(iface_id, node_id, iface)
|
|
1137
1183
|
|
|
1138
1184
|
for link_id in new_links:
|
|
1139
1185
|
link_data = self._find_link_in_topology(link_id, topology)
|
|
@@ -1144,42 +1190,41 @@ class Lab:
|
|
|
1144
1190
|
|
|
1145
1191
|
# kept elements
|
|
1146
1192
|
kept_nodes = update_node_keys.intersection(existing_node_keys)
|
|
1147
|
-
kept_links = update_link_keys.intersection(existing_link_keys)
|
|
1148
|
-
kept_interfaces = update_interface_keys.intersection(existing_interface_keys)
|
|
1193
|
+
# kept_links = update_link_keys.intersection(existing_link_keys)
|
|
1194
|
+
# kept_interfaces = update_interface_keys.intersection(existing_interface_keys)
|
|
1149
1195
|
|
|
1150
1196
|
for node_id in kept_nodes:
|
|
1151
1197
|
node = self._find_node_in_topology(node_id, topology)
|
|
1152
|
-
node_data = node["data"]
|
|
1153
1198
|
lab_node = self._nodes[node_id]
|
|
1154
|
-
lab_node.update(
|
|
1199
|
+
lab_node.update(node, exclude_configurations)
|
|
1155
1200
|
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
# change with tags
|
|
1160
|
-
pass
|
|
1201
|
+
# For now, can't update interface data server-side, this will change with tags
|
|
1202
|
+
# for interface_id in kept_interfaces:
|
|
1203
|
+
# interface_data = self._find_interface_in_topology(interface_id, topology)
|
|
1161
1204
|
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
# with tags
|
|
1166
|
-
pass
|
|
1205
|
+
# For now, can't update link data server-side, this will change with tags
|
|
1206
|
+
# for link_id in kept_links:
|
|
1207
|
+
# link_data = self._find_link_in_topology(link_id, topology)
|
|
1167
1208
|
|
|
1168
|
-
|
|
1209
|
+
@staticmethod
|
|
1210
|
+
def _find_link_in_topology(link_id, topology):
|
|
1169
1211
|
for link in topology["links"]:
|
|
1170
1212
|
if link["id"] == link_id:
|
|
1171
1213
|
return link
|
|
1172
1214
|
# if cannot find, is an internal structure error
|
|
1173
1215
|
return
|
|
1174
1216
|
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1217
|
+
# @staticmethod
|
|
1218
|
+
# def _find_interface_in_topology(interface_id, topology):
|
|
1219
|
+
# for node in topology["nodes"]:
|
|
1220
|
+
# for interface in node["interfaces"]:
|
|
1221
|
+
# if interface["id"] == interface_id:
|
|
1222
|
+
# return interface
|
|
1223
|
+
# # if cannot find, is an internal structure error
|
|
1224
|
+
# return
|
|
1225
|
+
|
|
1226
|
+
@staticmethod
|
|
1227
|
+
def _find_node_in_topology(node_id, topology):
|
|
1183
1228
|
for node in topology["nodes"]:
|
|
1184
1229
|
if node["id"] == node_id:
|
|
1185
1230
|
return node
|
|
@@ -1218,7 +1263,7 @@ class Lab:
|
|
|
1218
1263
|
self.pyats.sync_testbed(self.username, self.password)
|
|
1219
1264
|
|
|
1220
1265
|
def sync_layer3_addresses(self):
|
|
1221
|
-
"Syncs all layer 3 IP addresses from the backend server."
|
|
1266
|
+
"""Syncs all layer 3 IP addresses from the backend server."""
|
|
1222
1267
|
url = self.lab_base_url + "/layer3_addresses"
|
|
1223
1268
|
response = self.session.get(url)
|
|
1224
1269
|
response.raise_for_status()
|
|
@@ -1230,7 +1275,7 @@ class Lab:
|
|
|
1230
1275
|
self._last_sync_l3_address_time = time.time()
|
|
1231
1276
|
|
|
1232
1277
|
def cleanup_pyats_connections(self):
|
|
1233
|
-
"Closes and cleans up connection that pyATS might still hold."
|
|
1278
|
+
"""Closes and cleans up connection that pyATS might still hold."""
|
|
1234
1279
|
self.pyats.cleanup()
|
|
1235
1280
|
|
|
1236
1281
|
def download(self):
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
3
|
-
#
|
|
4
2
|
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
4
|
+
# All rights reserved.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
7
7
|
#
|
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
9
|
# you may not use this file except in compliance with the License.
|
|
@@ -338,8 +338,8 @@ class Licensing(object):
|
|
|
338
338
|
if count > self.max_wait:
|
|
339
339
|
timeout = self.max_wait * self.wait_interval
|
|
340
340
|
raise RuntimeError(
|
|
341
|
-
|
|
342
|
-
|
|
341
|
+
"Timeout: licensing {} did not reach {} status after {} secs. "
|
|
342
|
+
"Last status was {}".format(what, target_status, timeout, status)
|
|
343
343
|
)
|
|
344
344
|
status = self.status()[what]["status"]
|
|
345
345
|
logger.debug("%s status: %s", what, status)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
3
|
-
#
|
|
4
2
|
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
4
|
+
# All rights reserved.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
7
7
|
#
|
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
9
|
# you may not use this file except in compliance with the License.
|
|
@@ -149,7 +149,9 @@ class Link:
|
|
|
149
149
|
|
|
150
150
|
def wait_until_converged(self, max_iterations=None, wait_time=None):
|
|
151
151
|
logger.info("Waiting for link %s to converge", self.id)
|
|
152
|
-
max_iter =
|
|
152
|
+
max_iter = (
|
|
153
|
+
self.lab.wait_max_iterations if max_iterations is None else max_iterations
|
|
154
|
+
)
|
|
153
155
|
wait_time = self.lab.wait_time if wait_time is None else wait_time
|
|
154
156
|
for index in range(max_iter):
|
|
155
157
|
converged = self.has_converged()
|
|
@@ -164,9 +166,10 @@ class Link:
|
|
|
164
166
|
max_iter,
|
|
165
167
|
)
|
|
166
168
|
time.sleep(wait_time)
|
|
167
|
-
|
|
169
|
+
|
|
168
170
|
msg = "Link %s has not converged, maximum tries %s exceeded" % (
|
|
169
|
-
self.id,
|
|
171
|
+
self.id,
|
|
172
|
+
max_iter,
|
|
170
173
|
)
|
|
171
174
|
logger.error(msg)
|
|
172
175
|
# after maximum retries are exceeded and link has not converged
|
|
@@ -176,7 +179,7 @@ class Link:
|
|
|
176
179
|
raise RuntimeError(msg)
|
|
177
180
|
|
|
178
181
|
def has_converged(self):
|
|
179
|
-
url = self.
|
|
182
|
+
url = self.base_url + "/check_if_converged"
|
|
180
183
|
response = self.session.get(url)
|
|
181
184
|
response.raise_for_status()
|
|
182
185
|
converged = response.json()
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
3
|
-
#
|
|
4
2
|
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
4
|
+
# All rights reserved.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
7
7
|
#
|
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
9
|
# you may not use this file except in compliance with the License.
|
|
@@ -308,7 +308,7 @@ class Node:
|
|
|
308
308
|
|
|
309
309
|
def _set_node_property(self, key, val):
|
|
310
310
|
logger.info("Setting node property %s %s: %s", self, key, val)
|
|
311
|
-
node_url = "{}
|
|
311
|
+
node_url = "{}".format(self._base_url)
|
|
312
312
|
response = self.session.patch(url=node_url, json={key: val})
|
|
313
313
|
response.raise_for_status()
|
|
314
314
|
|
|
@@ -349,7 +349,9 @@ class Node:
|
|
|
349
349
|
|
|
350
350
|
def wait_until_converged(self, max_iterations=None, wait_time=None):
|
|
351
351
|
logger.info("Waiting for node %s to converge", self.id)
|
|
352
|
-
max_iter =
|
|
352
|
+
max_iter = (
|
|
353
|
+
self.lab.wait_max_iterations if max_iterations is None else max_iterations
|
|
354
|
+
)
|
|
353
355
|
wait_time = self.lab.wait_time if wait_time is None else wait_time
|
|
354
356
|
for index in range(max_iter):
|
|
355
357
|
converged = self.has_converged()
|
|
@@ -366,7 +368,8 @@ class Node:
|
|
|
366
368
|
time.sleep(wait_time)
|
|
367
369
|
|
|
368
370
|
msg = "Node %s has not converged, maximum tries %s exceeded" % (
|
|
369
|
-
self.id,
|
|
371
|
+
self.id,
|
|
372
|
+
max_iter,
|
|
370
373
|
)
|
|
371
374
|
logger.error(msg)
|
|
372
375
|
# after maximum retries are exceeded and node has not converged
|
|
@@ -376,7 +379,7 @@ class Node:
|
|
|
376
379
|
raise RuntimeError(msg)
|
|
377
380
|
|
|
378
381
|
def has_converged(self):
|
|
379
|
-
url = self.
|
|
382
|
+
url = self._base_url + "/check_if_converged"
|
|
380
383
|
response = self.session.get(url)
|
|
381
384
|
response.raise_for_status()
|
|
382
385
|
converged = response.json()
|
|
@@ -499,11 +502,14 @@ class Node:
|
|
|
499
502
|
}
|
|
500
503
|
|
|
501
504
|
def update(self, node_data, exclude_configurations):
|
|
505
|
+
if "data" in node_data:
|
|
506
|
+
# logger.warning("Deprecated since 2.4 (will be removed in 2.5)")
|
|
507
|
+
node_data = node_data["data"]
|
|
502
508
|
self._label = node_data["label"]
|
|
503
509
|
self._x = node_data["x"]
|
|
504
510
|
self._y = node_data["y"]
|
|
505
511
|
self._node_definition = node_data["node_definition"]
|
|
506
|
-
self._image_definition = node_data
|
|
512
|
+
self._image_definition = node_data.get("image_definition", None)
|
|
507
513
|
self._ram = node_data["ram"]
|
|
508
514
|
self._cpus = node_data["cpus"]
|
|
509
515
|
self._cpu_limit = node_data.get("cpu_limit", 100)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
3
|
-
#
|
|
4
2
|
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
4
|
+
# All rights reserved.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
7
7
|
#
|
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
9
|
# you may not use this file except in compliance with the License.
|
|
@@ -231,7 +231,6 @@ class NodeImageDefinitions:
|
|
|
231
231
|
url = self._base_url + "node_definitions/" + definition_id
|
|
232
232
|
response = self.session.delete(url)
|
|
233
233
|
response.raise_for_status()
|
|
234
|
-
return response.json()
|
|
235
234
|
|
|
236
235
|
def remove_image_definition(self, definition_id):
|
|
237
236
|
"""
|
|
@@ -250,7 +249,6 @@ class NodeImageDefinitions:
|
|
|
250
249
|
url = self._base_url + "image_definitions/" + definition_id
|
|
251
250
|
response = self.session.delete(url)
|
|
252
251
|
response.raise_for_status()
|
|
253
|
-
return response.json()
|
|
254
252
|
|
|
255
253
|
|
|
256
254
|
def progress_callback(monitor):
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
3
|
-
#
|
|
4
2
|
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
4
|
+
# All rights reserved.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
7
7
|
#
|
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
9
|
# you may not use this file except in compliance with the License.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
3
|
-
#
|
|
4
2
|
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
4
|
+
# All rights reserved.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
7
7
|
#
|
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
9
|
# you may not use this file except in compliance with the License.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
3
|
-
#
|
|
4
2
|
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
4
|
+
# All rights reserved.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
7
7
|
#
|
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
9
|
# you may not use this file except in compliance with the License.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#
|
|
2
|
-
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
3
|
-
#
|
|
4
2
|
# This file is part of VIRL 2
|
|
3
|
+
# Copyright (c) 2019-2022, Cisco Systems, Inc.
|
|
4
|
+
# All rights reserved.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
6
|
+
# Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
7
7
|
#
|
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
9
|
# you may not use this file except in compliance with the License.
|
|
@@ -187,7 +187,7 @@ class ClientLibrary:
|
|
|
187
187
|
"""
|
|
188
188
|
|
|
189
189
|
# current client version
|
|
190
|
-
VERSION = Version("2.
|
|
190
|
+
VERSION = Version("2.4.0")
|
|
191
191
|
# list of Version objects
|
|
192
192
|
INCOMPATIBLE_CONTROLLER_VERSIONS = [
|
|
193
193
|
Version("2.0.0"),
|
|
@@ -471,7 +471,7 @@ class ClientLibrary:
|
|
|
471
471
|
ready = result.get("ready")
|
|
472
472
|
except requests.HTTPError:
|
|
473
473
|
# 502 Bad Gateway is expected and hints
|
|
474
|
-
# that system is not ready - no need to
|
|
474
|
+
# that system is not ready - no need to
|
|
475
475
|
# raise - just wait
|
|
476
476
|
ready = False
|
|
477
477
|
if not ready and loops > 0:
|
|
@@ -486,19 +486,27 @@ class ClientLibrary:
|
|
|
486
486
|
"""
|
|
487
487
|
raise Exception("this is deprecated, use is_system_ready(wait=True), if needed")
|
|
488
488
|
|
|
489
|
-
|
|
489
|
+
@staticmethod
|
|
490
|
+
def is_virl_1x(path: Path):
|
|
491
|
+
if path.suffix == ".virl":
|
|
492
|
+
return True
|
|
493
|
+
return False
|
|
494
|
+
|
|
495
|
+
def import_lab(self, topology, title=None, offline=False, virl_1x=False):
|
|
490
496
|
"""
|
|
491
497
|
Imports an existing topology from a string.
|
|
492
498
|
|
|
493
499
|
:param topology: Topology representation as a string
|
|
494
500
|
:type topology: str
|
|
495
|
-
:param title: Title of the lab
|
|
496
|
-
:type title: str
|
|
501
|
+
:param title: Title of the lab (optional)
|
|
502
|
+
:type title: str (otherwise ignored)
|
|
497
503
|
:param offline: whether the ClientLibrary should import the
|
|
498
504
|
lab locally. The topology parameter has to be a JSON string
|
|
499
505
|
in this case. This can not be XML or YAML representation of
|
|
500
506
|
the lab. Compatible JSON from `GET /labs/{lab_id}/topology`.
|
|
501
507
|
:type offline: bool
|
|
508
|
+
:param virl_1x: Is this old virl-1x topology format (default=False)
|
|
509
|
+
:type virl_1x: bool
|
|
502
510
|
:returns: A Lab instance
|
|
503
511
|
:rtype: models.Lab
|
|
504
512
|
:raises ValueError: if there's no lab ID in the API response
|
|
@@ -508,10 +516,12 @@ class ClientLibrary:
|
|
|
508
516
|
if offline:
|
|
509
517
|
lab_id = "offline_lab"
|
|
510
518
|
else:
|
|
511
|
-
if
|
|
512
|
-
url =
|
|
519
|
+
if virl_1x:
|
|
520
|
+
url = "{}import/virl-1x".format(self._base_url)
|
|
513
521
|
else:
|
|
514
|
-
url =
|
|
522
|
+
url = "{}import".format(self._base_url)
|
|
523
|
+
if isinstance(title, str):
|
|
524
|
+
url = "{}?title={}".format(url, title)
|
|
515
525
|
response = self.session.post(url, data=topology)
|
|
516
526
|
response.raise_for_status()
|
|
517
527
|
result = response.json()
|
|
@@ -519,10 +529,8 @@ class ClientLibrary:
|
|
|
519
529
|
if lab_id is None:
|
|
520
530
|
raise ValueError("No lab ID returned!")
|
|
521
531
|
|
|
522
|
-
# remove the extension (.yaml) to name the lab
|
|
523
|
-
lab_title = title.replace(Path(title).suffix, "")
|
|
524
532
|
lab = Lab(
|
|
525
|
-
|
|
533
|
+
title,
|
|
526
534
|
lab_id,
|
|
527
535
|
self._context,
|
|
528
536
|
self.username,
|
|
@@ -534,32 +542,34 @@ class ClientLibrary:
|
|
|
534
542
|
if offline:
|
|
535
543
|
topology_dict = json.loads(topology)
|
|
536
544
|
# ensure the lab owner is not properly set
|
|
537
|
-
|
|
545
|
+
# how does below get to offline? user_id is calling controller
|
|
546
|
+
topology_dict["lab"]["owner"] = self.user_management.user_id(self.username)
|
|
538
547
|
lab.import_lab(topology_dict)
|
|
539
548
|
else:
|
|
540
549
|
lab.sync()
|
|
541
550
|
self._labs[lab_id] = lab
|
|
542
551
|
return lab
|
|
543
552
|
|
|
544
|
-
def import_lab_from_path(self,
|
|
553
|
+
def import_lab_from_path(self, path, title=None):
|
|
545
554
|
"""
|
|
546
555
|
Imports an existing topology from a file / path.
|
|
547
556
|
|
|
548
|
-
:param
|
|
549
|
-
:type
|
|
557
|
+
:param path: Topology filename / path
|
|
558
|
+
:type path: str
|
|
550
559
|
:param title: Title of the lab
|
|
551
560
|
:type title: str
|
|
552
561
|
:returns: A Lab instance
|
|
553
562
|
:rtype: models.Lab
|
|
554
563
|
"""
|
|
555
|
-
topology_path = Path(
|
|
564
|
+
topology_path = Path(path)
|
|
556
565
|
if not topology_path.exists():
|
|
557
|
-
message = "{} can not be found".format(
|
|
566
|
+
message = "{} can not be found".format(path)
|
|
558
567
|
raise Exception(message)
|
|
559
568
|
|
|
560
569
|
topology = topology_path.read_text()
|
|
561
|
-
|
|
562
|
-
|
|
570
|
+
return self.import_lab(
|
|
571
|
+
topology, title=title, virl_1x=self.is_virl_1x(topology_path)
|
|
572
|
+
)
|
|
563
573
|
|
|
564
574
|
def import_sample_lab(self, title):
|
|
565
575
|
"""
|
|
@@ -574,7 +584,11 @@ class ClientLibrary:
|
|
|
574
584
|
topology = pkg_resources.resource_string(
|
|
575
585
|
"simple_common", topology_file_path.as_posix()
|
|
576
586
|
)
|
|
577
|
-
return self.import_lab(
|
|
587
|
+
return self.import_lab(
|
|
588
|
+
topology=topology.decode(),
|
|
589
|
+
title=title,
|
|
590
|
+
virl_1x=self.is_virl_1x(topology_file_path),
|
|
591
|
+
)
|
|
578
592
|
|
|
579
593
|
def all_labs(self, show_all=False):
|
|
580
594
|
"""
|
virl2_client-2.3.0/setup.py
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
from setuptools import setup
|
|
3
|
-
|
|
4
|
-
packages = \
|
|
5
|
-
['virl2_client', 'virl2_client.models']
|
|
6
|
-
|
|
7
|
-
package_data = \
|
|
8
|
-
{'': ['*']}
|
|
9
|
-
|
|
10
|
-
install_requires = \
|
|
11
|
-
['requests-toolbelt>=0.9.1,<0.10.0', 'requests>=2,<3']
|
|
12
|
-
|
|
13
|
-
setup_kwargs = {
|
|
14
|
-
'name': 'virl2-client',
|
|
15
|
-
'version': '2.3.0',
|
|
16
|
-
'description': 'VIRL2 Client Library',
|
|
17
|
-
'long_description': '[](https://github.com/CiscoDevNet/virl2-client/actions/workflows/main.yml)\n\n# VIRL 2 Client Library\n\n## Introduction\n\nThis is the client library for the Cisco VIRL 2 Network Simulation Platform\n(`virl2_client`). It provides a Python package to programmatically create,\nedit, delete and control network simulations on a VIRL 2 controller.\n\nIt is a pure Python implementation that requires Python3. We\'ve tested and\nwritten the package with Python 3.6.8.\n\nThe **status** of this package can be considered **Beta**. We\'re not aware of\nany major issues at the time of release. However, since this is the first\nrelease of the package, bugs might exist. Both in the package as well as in\nthe API implementation on the controller.\n\n## Use Case Description\n\nThe client library provides a convenient interface to control the lifecycle of\na network simulation. This can be used for automation scripts directly in\nPython but also for third party integrations / plugins which need to integrate\nwith a simulated network. Examples already existing are an [Ansible\nplugin](https://github.com/CiscoDevNet/ansible-virl).\n\n## Installation\n\nThe package comes in form of a wheel that is downloadable from the VIRL 2\ncontroller. The package can be installed either from PyPi using\n\n pip3 install virl2_client\n\nor, alternatively, the version that is bundled with the VIRL 2 controller can\nbe downloaded to the local filesystem and then directly installed via\n\n pip3 install ./virl2_client-*.whl\n\nThe bundled version is available on the index site of the docs when viewed\ndirectly on the VIRL 2 controller.\n\nEnsure to replace use the correct file name, replacing the wildcard with the\nproper version/build information. For example\n\n pip3 install virl2_client-2.0.0b10-py3-none-any.whl\n\nWe recommend the use of a virtual environment for installation.\n\n## Usage\n\nThe package itself is fairly well documented using docstrings. In addition, the\ndocumentation is available in HTML format on the controller itself, via the\n"Tools -> Client Library" menu.\n\n## Compatibility\n\nThis package and the used API is specific to VIRL 2. It is not\nbackwards compatible with VIRL 1.x and therefore can not be used with VIRL\n1.x. If you are looking for a convenient tool to interface with the VIRL 1 API\nthen the [VIRL Utils tool](https://github.com/CiscoDevNet/virlutils) is\nrecommended.\n\n## Known Issues\n\nThere are no known issues at this point. See the comment in the *Introduction*\nsection.\n\n## Getting Help\n\nIf you have questions, concerns, bug reports, etc., please create an issue\nagainst the [repository on\nGitHub](https://github.com/CiscoDevNet/virl2-client/)\n\n## Getting Involved\n\nWe welcome contributions. Whether you fixed a bug, added a new feature or\ncorrected a typo, all contributions are welcome. General instructions on how to\ncontribute can be found in the [CONTRIBUTING](CONTRIBUTING.md) file.\n\n## Licensing Info\n\nThis code is licensed under the Apache 2.0 License. See [LICENSE](LICENSE) for\ndetails.\n\n## References\n\nThis package is part of the VIRL 2 Network Simulation platform. For details, go\nto https://developer.cisco.com/modeling-labs. Additional documentation for the\nproduct is available at https://developer.cisco.com/docs/modeling-labs\n',
|
|
18
|
-
'author': 'Simon Knight',
|
|
19
|
-
'author_email': 'simknigh@cisco.com',
|
|
20
|
-
'maintainer': None,
|
|
21
|
-
'maintainer_email': None,
|
|
22
|
-
'url': 'https://github.com/ciscodevnet/virl2-client',
|
|
23
|
-
'packages': packages,
|
|
24
|
-
'package_data': package_data,
|
|
25
|
-
'install_requires': install_requires,
|
|
26
|
-
'python_requires': '>=3.6.0,<4.0.0',
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
setup(**setup_kwargs)
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Python bindings for the Cisco VIRL 2 Network Simulation Platform
|
|
3
|
-
|
|
4
|
-
This file is part of VIRL 2
|
|
5
|
-
|
|
6
|
-
Copyright 2020 Cisco Systems Inc.
|
|
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
|
-
# flake8: noqa: F401
|
|
22
|
-
|
|
23
|
-
from .exceptions import InterfaceNotFound, LabNotFound, LinkNotFound, NodeNotFound
|
|
24
|
-
from .virl2_client import ClientConfig, ClientLibrary, InitializationError
|
|
25
|
-
from .models.authentication import Context
|
|
File without changes
|
|
File without changes
|