napalm-vmware 0.3.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.
- napalm_vmware-0.3.0/LICENSE +165 -0
- napalm_vmware-0.3.0/PKG-INFO +201 -0
- napalm_vmware-0.3.0/README.md +163 -0
- napalm_vmware-0.3.0/napalm_vmware/__init__.py +6 -0
- napalm_vmware-0.3.0/napalm_vmware/_inventory.py +96 -0
- napalm_vmware-0.3.0/napalm_vmware/_plain.py +57 -0
- napalm_vmware-0.3.0/napalm_vmware/_session.py +47 -0
- napalm_vmware-0.3.0/napalm_vmware/_tasks.py +83 -0
- napalm_vmware-0.3.0/napalm_vmware/actions.py +109 -0
- napalm_vmware-0.3.0/napalm_vmware/base.py +164 -0
- napalm_vmware-0.3.0/napalm_vmware/esxi.py +75 -0
- napalm_vmware-0.3.0/napalm_vmware/parse/__init__.py +0 -0
- napalm_vmware-0.3.0/napalm_vmware/parse/environment.py +65 -0
- napalm_vmware-0.3.0/napalm_vmware/parse/facts.py +94 -0
- napalm_vmware-0.3.0/napalm_vmware/parse/hosts.py +40 -0
- napalm_vmware-0.3.0/napalm_vmware/parse/interfaces.py +88 -0
- napalm_vmware-0.3.0/napalm_vmware/parse/licenses.py +19 -0
- napalm_vmware-0.3.0/napalm_vmware/parse/lldp.py +33 -0
- napalm_vmware-0.3.0/napalm_vmware/parse/networks.py +106 -0
- napalm_vmware-0.3.0/napalm_vmware/parse/snapshots.py +52 -0
- napalm_vmware-0.3.0/napalm_vmware/parse/storage.py +27 -0
- napalm_vmware-0.3.0/napalm_vmware/parse/vm_config.py +96 -0
- napalm_vmware-0.3.0/napalm_vmware/parse/vm_devices.py +65 -0
- napalm_vmware-0.3.0/napalm_vmware/parse/vms.py +121 -0
- napalm_vmware-0.3.0/napalm_vmware/paths.py +92 -0
- napalm_vmware-0.3.0/napalm_vmware/provision/__init__.py +0 -0
- napalm_vmware-0.3.0/napalm_vmware/provision/image.py +139 -0
- napalm_vmware-0.3.0/napalm_vmware/provision/ovf.py +121 -0
- napalm_vmware-0.3.0/napalm_vmware/provision/placement.py +107 -0
- napalm_vmware-0.3.0/napalm_vmware/provision/seed.py +53 -0
- napalm_vmware-0.3.0/napalm_vmware/provision/transfer.py +113 -0
- napalm_vmware-0.3.0/napalm_vmware/provisioning.py +411 -0
- napalm_vmware-0.3.0/napalm_vmware/py.typed +0 -0
- napalm_vmware-0.3.0/napalm_vmware/vcenter.py +49 -0
- napalm_vmware-0.3.0/napalm_vmware.egg-info/PKG-INFO +201 -0
- napalm_vmware-0.3.0/napalm_vmware.egg-info/SOURCES.txt +59 -0
- napalm_vmware-0.3.0/napalm_vmware.egg-info/dependency_links.txt +1 -0
- napalm_vmware-0.3.0/napalm_vmware.egg-info/entry_points.txt +3 -0
- napalm_vmware-0.3.0/napalm_vmware.egg-info/requires.txt +12 -0
- napalm_vmware-0.3.0/napalm_vmware.egg-info/top_level.txt +1 -0
- napalm_vmware-0.3.0/pyproject.toml +112 -0
- napalm_vmware-0.3.0/setup.cfg +4 -0
- napalm_vmware-0.3.0/tests/test_actions.py +152 -0
- napalm_vmware-0.3.0/tests/test_drivers.py +274 -0
- napalm_vmware-0.3.0/tests/test_inventory.py +133 -0
- napalm_vmware-0.3.0/tests/test_parse_facts.py +95 -0
- napalm_vmware-0.3.0/tests/test_parse_host_state.py +201 -0
- napalm_vmware-0.3.0/tests/test_parse_interfaces.py +80 -0
- napalm_vmware-0.3.0/tests/test_parse_networks.py +126 -0
- napalm_vmware-0.3.0/tests/test_parse_vm_config.py +196 -0
- napalm_vmware-0.3.0/tests/test_parse_vms.py +131 -0
- napalm_vmware-0.3.0/tests/test_plain.py +67 -0
- napalm_vmware-0.3.0/tests/test_provision_image.py +107 -0
- napalm_vmware-0.3.0/tests/test_provision_ovf.py +79 -0
- napalm_vmware-0.3.0/tests/test_provision_placement.py +114 -0
- napalm_vmware-0.3.0/tests/test_provision_seed.py +79 -0
- napalm_vmware-0.3.0/tests/test_provision_transfer.py +63 -0
- napalm_vmware-0.3.0/tests/test_provisioning.py +307 -0
- napalm_vmware-0.3.0/tests/test_sanitize.py +97 -0
- napalm_vmware-0.3.0/tests/test_tasks.py +117 -0
- napalm_vmware-0.3.0/tests/test_vcsim.py +152 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of tracking and
|
|
55
|
+
discussing the Work, but excluding communication that is conspicuously
|
|
56
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
57
|
+
Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and included
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or by the combination of their Contributions
|
|
78
|
+
with the Work to which such Contributions were submitted. If You
|
|
79
|
+
institute patent litigation against any entity (including a cross-claim
|
|
80
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
81
|
+
Contribution embodied within the Work constitutes direct or contributory
|
|
82
|
+
patent infringement, then any patent licenses granted to You under
|
|
83
|
+
this License for that Work shall terminate as of the date such
|
|
84
|
+
litigation is filed.
|
|
85
|
+
|
|
86
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
87
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
88
|
+
modifications, and in Source or Object form, provided that You
|
|
89
|
+
meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
92
|
+
Works a copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices
|
|
95
|
+
stating that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
98
|
+
that You distribute, all copyright, patent, trademark, and
|
|
99
|
+
attribution notices from the Source form of the Work,
|
|
100
|
+
excluding those notices that do not pertain to any part of
|
|
101
|
+
the Derivative Works; and
|
|
102
|
+
|
|
103
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
104
|
+
distribution, You must include a readable copy of the
|
|
105
|
+
attribution notices contained within such NOTICE file, in
|
|
106
|
+
at least one of the following places: within a NOTICE text
|
|
107
|
+
file distributed as part of the Derivative Works; within
|
|
108
|
+
the Source form or documentation, if provided along with the
|
|
109
|
+
Derivative Works; or, within a display generated by the
|
|
110
|
+
Derivative Works, if and wherever such third-party notices
|
|
111
|
+
normally appear. The contents of the NOTICE file are for
|
|
112
|
+
informational purposes only and do not modify the License.
|
|
113
|
+
You may add Your own attribution notices within Derivative
|
|
114
|
+
Works that You distribute, alongside or in addition to the
|
|
115
|
+
NOTICE text from the Work, provided that such additional
|
|
116
|
+
attribution notices cannot be construed as modifying the License.
|
|
117
|
+
|
|
118
|
+
You may add Your own license statement for Your modifications and
|
|
119
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
120
|
+
publish, sublicense, and/or sell copies of the Work, and to permit
|
|
121
|
+
persons to whom the Work is furnished to do so.
|
|
122
|
+
|
|
123
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
124
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
125
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
126
|
+
this License, without any additional terms or conditions.
|
|
127
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
128
|
+
the terms of any separate license agreement you may have executed
|
|
129
|
+
with Licensor regarding such Contributions.
|
|
130
|
+
|
|
131
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
132
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
133
|
+
except as required for reasonable and customary use in describing the
|
|
134
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
135
|
+
|
|
136
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
137
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
138
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
139
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
140
|
+
implied, including, without limitation, any conditions of TITLE,
|
|
141
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
|
|
142
|
+
PURPOSE. You are solely responsible for determining the
|
|
143
|
+
appropriateness of using or reproducing the Work and assume any
|
|
144
|
+
risks associated with Your exercise of permissions under this License.
|
|
145
|
+
|
|
146
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
147
|
+
whether in tort (including negligence), strict liability, or contract
|
|
148
|
+
shall any Contributor be liable to You for damages, including any
|
|
149
|
+
direct, indirect, special, incidental, or exemplary damages of any
|
|
150
|
+
character arising as a result of this License or out of the use or
|
|
151
|
+
inability to use the Work (even if such Contributor has been advised
|
|
152
|
+
of the possibility of such damages).
|
|
153
|
+
|
|
154
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
155
|
+
the Work or Derivative Works thereof, You may choose to offer, and
|
|
156
|
+
charge a fee for, acceptance of support, warranty, indemnity, or other
|
|
157
|
+
liability obligations and/or rights consistent with this License.
|
|
158
|
+
However, in accepting such obligations, You may offer only your own
|
|
159
|
+
liability and not on behalf of any other Contributor, and only if
|
|
160
|
+
You agree to indemnify, defend, and hold each Contributor harmless
|
|
161
|
+
for any liability incurred by, or claims asserted against, such
|
|
162
|
+
Contributor by reason of your accepting any such warranty or
|
|
163
|
+
additional liability.
|
|
164
|
+
|
|
165
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: napalm-vmware
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: NAPALM drivers for VMware ESXi hosts and vCenter Server (vSphere API via pyVmomi)
|
|
5
|
+
Author-email: Christian Manivong <christian@manivong.de>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Repository, https://git.netork.io/NAPALM/napalm-vmware
|
|
8
|
+
Project-URL: Issues, https://git.netork.io/NAPALM/napalm-vmware/issues
|
|
9
|
+
Project-URL: Changelog, https://git.netork.io/NAPALM/napalm-vmware/src/branch/main/CHANGELOG.md
|
|
10
|
+
Keywords: napalm,vmware,esxi,vcenter,vsphere,hypervisor,driver
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: System :: Networking
|
|
21
|
+
Classifier: Topic :: System :: Systems Administration
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: napalm>=5.0.0
|
|
27
|
+
Requires-Dist: napalm-device-types>=4.21.1
|
|
28
|
+
Requires-Dist: pyvmomi>=8.0.1
|
|
29
|
+
Requires-Dist: requests>=2.31
|
|
30
|
+
Requires-Dist: pycdlib>=1.14
|
|
31
|
+
Requires-Dist: PyYAML>=6.0
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest-cov>=5; extra == "dev"
|
|
35
|
+
Requires-Dist: mypy>=1.11; extra == "dev"
|
|
36
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
# napalm-vmware
|
|
40
|
+
|
|
41
|
+
NAPALM drivers for VMware vSphere, speaking the vSphere API through
|
|
42
|
+
[pyVmomi](https://pypi.org/project/pyvmomi/):
|
|
43
|
+
|
|
44
|
+
| Driver | Endpoint | Device in netOrk |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| `vmware_esxi` | one ESXi host, addressed directly | the host: its vmnics, vmkernel NICs, sensors, VMs |
|
|
47
|
+
| `vmware_vcenter` | a vCenter Server | the vCenter: every VM it manages, with the ESXi host as the VM's `node` |
|
|
48
|
+
|
|
49
|
+
Both declare the `hypervisor` role from
|
|
50
|
+
[napalm-device-types](https://git.netork.io/NAPALM/napalm-device-types).
|
|
51
|
+
|
|
52
|
+
## Status
|
|
53
|
+
|
|
54
|
+
Tested against govmomi's **vcsim** simulator, in both ESXi and vCenter mode,
|
|
55
|
+
including real power and snapshot tasks. **Not yet tested against real
|
|
56
|
+
hardware**: see [Harvesting fixtures](#harvesting-fixtures).
|
|
57
|
+
|
|
58
|
+
| Method | ESXi | vCenter | Source |
|
|
59
|
+
|---|---|---|---|
|
|
60
|
+
| `get_facts` | ✅ | ✅ | host hardware + product / `about` |
|
|
61
|
+
| `get_interfaces`, `get_interfaces_ip` | ✅ | `{}` | vmnics + vmks |
|
|
62
|
+
| `get_lldp_neighbors` | ✅ | `{}` | `QueryNetworkHint` (LLDP, else CDP) |
|
|
63
|
+
| `get_environment` | ✅ | ✅ (per host) | quick stats + hardware sensors |
|
|
64
|
+
| `get_vms` | ✅ | ✅ | VMs, templates excluded |
|
|
65
|
+
| `get_vm_config` | ✅ | ✅ | virtual hardware |
|
|
66
|
+
| `start_vm`, `stop_vm`, `reboot_vm`, `suspend_vm` | ✅ | ✅ | power tasks / VMware Tools |
|
|
67
|
+
| `get_vm_snapshots`, `create/delete/rollback_vm_snapshot` | ✅ | ✅ | snapshot tree |
|
|
68
|
+
| `get_vm_storage_pools` | ✅ | ✅ | datastores |
|
|
69
|
+
| `get_virtual_networks` | ✅ | ✅ (+ dvPortgroups) | port groups |
|
|
70
|
+
| `get_hypervisor_hosts` | ✅ | ✅ | connection state, maintenance mode, config issues, managing vCenter |
|
|
71
|
+
| `get_licenses` | ✅ | ✅ | license manager: name and edition key, never the key |
|
|
72
|
+
| `reboot_host` | ✅ (maintenance mode only) | — | `RebootHost_Task` |
|
|
73
|
+
| `create_vm_from_cloud_init`, `destroy_vm`, `get_vm_status` | ✅ | ✅ | see [Provisioning](#provisioning) |
|
|
74
|
+
| `get_network_targets`, `get_image_storages` | ✅ | ✅ | port groups, datastores |
|
|
75
|
+
| VIBs, updates | — | — | not yet |
|
|
76
|
+
|
|
77
|
+
Unverified assumptions, to be checked against real hardware:
|
|
78
|
+
|
|
79
|
+
- the HTTP fingerprints (`vmware esxi` on the Host Client page, `vcenter` on
|
|
80
|
+
the vSphere Client page)
|
|
81
|
+
- the free vSphere Hypervisor license reporting `editionKey` `esxBasic`
|
|
82
|
+
|
|
83
|
+
## Requirements
|
|
84
|
+
|
|
85
|
+
- HTTPS (443) to the host or vCenter. No SSH.
|
|
86
|
+
- An account that may read the inventory. For power and snapshot actions it
|
|
87
|
+
also needs *Virtual machine → Interaction → Power on/off/Reset/Suspend* and
|
|
88
|
+
*Virtual machine → Snapshot management*.
|
|
89
|
+
- For provisioning: `qemu-img` (package `qemu-utils`) where the driver runs,
|
|
90
|
+
and HTTPS from there to every ESXi host that may receive a VM -- through a
|
|
91
|
+
vCenter the disk upload goes straight to the host, not via the vCenter.
|
|
92
|
+
- **A paid license for any write.** On the free vSphere Hypervisor license
|
|
93
|
+
the API is read-only; the driver reports `vmware_api_read_only` and turns
|
|
94
|
+
the refusal into a readable error.
|
|
95
|
+
|
|
96
|
+
## Install
|
|
97
|
+
|
|
98
|
+
Python 3.10 or later.
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pip install napalm-vmware
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Usage
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from napalm_vmware import VmwareEsxiDriver
|
|
108
|
+
|
|
109
|
+
driver = VmwareEsxiDriver(
|
|
110
|
+
"esx01.example.lan", "root", "secret", optional_args={"verify_ssl": False}
|
|
111
|
+
)
|
|
112
|
+
driver.open()
|
|
113
|
+
print(driver.get_facts())
|
|
114
|
+
for vm in driver.get_vms():
|
|
115
|
+
print(vm["name"], vm["status"], vm["vmid"])
|
|
116
|
+
driver.close()
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`optional_args`: `port` (default 443), `verify_ssl` / `ssl_verify` (default
|
|
120
|
+
`True`; ESXi ships a self-signed certificate), `image_cache_dir` (where
|
|
121
|
+
converted cloud images are kept; default a directory under the system temp
|
|
122
|
+
dir). Other keys are ignored.
|
|
123
|
+
|
|
124
|
+
VMs are addressed by name, by `vmid`, or by MoRef (`vm-42`). A name shared
|
|
125
|
+
by two VMs is refused rather than guessed.
|
|
126
|
+
|
|
127
|
+
## Tests
|
|
128
|
+
|
|
129
|
+
The rules are in [STANDARDS.md](https://git.netork.io/NAPALM/driver-standard/src/branch/main/STANDARDS.md).
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
python -m venv .venv && .venv/bin/pip install -e ".[dev]"
|
|
133
|
+
.venv/bin/pytest --cov # unit tests, no network
|
|
134
|
+
docker run -d --rm -p 127.0.0.1:8989:8989 vmware/vcsim -l 0.0.0.0:8989
|
|
135
|
+
docker run -d --rm -p 127.0.0.1:8990:8989 vmware/vcsim -esx -l 0.0.0.0:8989
|
|
136
|
+
VCSIM_VCENTER_PORT=8989 VCSIM_ESXI_PORT=8990 pytest -m vcsim
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Harvesting fixtures
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
tools/harvest.py esx01.example.lan root esxi8-dell # prompts for the password
|
|
143
|
+
tools/sanitize.py tools/harvest-out/esxi8-dell.json > tests/fixtures/esxi8-dell.json
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`harvest.py` reads exactly the property paths in `napalm_vmware/paths.py`,
|
|
147
|
+
the ones the drivers read. `tools/harvest-out/` is gitignored. Read the
|
|
148
|
+
sanitised file before committing it.
|
|
149
|
+
|
|
150
|
+
## Provisioning
|
|
151
|
+
|
|
152
|
+
`create_vm_from_cloud_init` takes the same cloud images netOrk's catalog
|
|
153
|
+
offers for Proxmox (qcow2/raw):
|
|
154
|
+
|
|
155
|
+
1. The image is downloaded where the driver runs, its checksum verified (one
|
|
156
|
+
retry), and converted with `qemu-img` to a streamOptimized VMDK. The VMDK
|
|
157
|
+
is cached by URL in `image_cache_dir`; the download is not kept.
|
|
158
|
+
2. A host is chosen that is connected, not in maintenance mode, and sees the
|
|
159
|
+
datastore and every requested port group (the named datastore, or the one
|
|
160
|
+
with the most free space).
|
|
161
|
+
3. The VM is created from a minimal OVF descriptor (PVSCSI disk, VMXNET3
|
|
162
|
+
NICs) and the disk streamed in over NFC.
|
|
163
|
+
4. Requested MACs are pinned, the disk grown to `disk_resize_gb`, and a
|
|
164
|
+
NoCloud seed ISO (user-data, meta-data, network-config) uploaded next to
|
|
165
|
+
the VM's files and attached as a CD-ROM on a new SATA controller.
|
|
166
|
+
5. The VM is powered on. Any failure after step 3 removes the VM again.
|
|
167
|
+
|
|
168
|
+
A port group fixes its VLAN, so `get_network_targets` reports each one with
|
|
169
|
+
`kind="portgroup"`, `vlan_aware=False` and its `fixed_vlan_tag`; a NIC asking
|
|
170
|
+
for a different `vlan_tag` is refused. The guest agent netOrk installs is
|
|
171
|
+
`open-vm-tools` (`GUEST_AGENTS`), which reports the IP address back. Only
|
|
172
|
+
Linux guests are provisioned; `guest_os` other than `"linux"` is refused
|
|
173
|
+
(BSD guests on VMware: NetOrk/netork#801).
|
|
174
|
+
|
|
175
|
+
Unverified until #305: that each distribution's cloud kernel carries the
|
|
176
|
+
PVSCSI and VMXNET3 drivers.
|
|
177
|
+
|
|
178
|
+
## Design notes
|
|
179
|
+
|
|
180
|
+
**One seam.** Every read goes through `Inventory.collect(type, paths)`, a
|
|
181
|
+
PropertyCollector query with explicit paths, and every result is converted
|
|
182
|
+
by `to_plain()` into dicts, lists and scalars (managed objects become their
|
|
183
|
+
MoRef, data objects get a `_type`). The parsers in `napalm_vmware/parse/`
|
|
184
|
+
only ever see that plain form, so a harvested JSON file and a live host feed
|
|
185
|
+
them identically. Lazy attribute access on pyVmomi objects is avoided on
|
|
186
|
+
purpose: it fails on some servers where the individual paths work.
|
|
187
|
+
|
|
188
|
+
**`vmid` is the instance UUID** (`config.instanceUuid`). It survives vMotion
|
|
189
|
+
and re-registration and is unique within a vCenter; a MoRef is none of those.
|
|
190
|
+
The MoRef is reported alongside as `moref`.
|
|
191
|
+
|
|
192
|
+
**The vCenter device has no interfaces.** The hosts' NICs belong to the
|
|
193
|
+
hosts. Reporting them on the vCenter would attach their MACs to the wrong
|
|
194
|
+
device. Add a host with `vmware_esxi` to see its NICs.
|
|
195
|
+
|
|
196
|
+
**Facts, not warnings.** The driver names no warnings. `get_hypervisor_hosts()`
|
|
197
|
+
and `get_licenses()` report what the endpoint says; whether a host in
|
|
198
|
+
maintenance mode or the free `esxBasic` edition is a problem is the caller's
|
|
199
|
+
to decide. The ESXi driver reports `connected` as `None` (a disconnected host
|
|
200
|
+
could not have answered) and the managing vCenter's address as `managed_by`;
|
|
201
|
+
under the vCenter driver `managed_by` is `None`, since every host names it.
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# napalm-vmware
|
|
2
|
+
|
|
3
|
+
NAPALM drivers for VMware vSphere, speaking the vSphere API through
|
|
4
|
+
[pyVmomi](https://pypi.org/project/pyvmomi/):
|
|
5
|
+
|
|
6
|
+
| Driver | Endpoint | Device in netOrk |
|
|
7
|
+
|---|---|---|
|
|
8
|
+
| `vmware_esxi` | one ESXi host, addressed directly | the host: its vmnics, vmkernel NICs, sensors, VMs |
|
|
9
|
+
| `vmware_vcenter` | a vCenter Server | the vCenter: every VM it manages, with the ESXi host as the VM's `node` |
|
|
10
|
+
|
|
11
|
+
Both declare the `hypervisor` role from
|
|
12
|
+
[napalm-device-types](https://git.netork.io/NAPALM/napalm-device-types).
|
|
13
|
+
|
|
14
|
+
## Status
|
|
15
|
+
|
|
16
|
+
Tested against govmomi's **vcsim** simulator, in both ESXi and vCenter mode,
|
|
17
|
+
including real power and snapshot tasks. **Not yet tested against real
|
|
18
|
+
hardware**: see [Harvesting fixtures](#harvesting-fixtures).
|
|
19
|
+
|
|
20
|
+
| Method | ESXi | vCenter | Source |
|
|
21
|
+
|---|---|---|---|
|
|
22
|
+
| `get_facts` | ✅ | ✅ | host hardware + product / `about` |
|
|
23
|
+
| `get_interfaces`, `get_interfaces_ip` | ✅ | `{}` | vmnics + vmks |
|
|
24
|
+
| `get_lldp_neighbors` | ✅ | `{}` | `QueryNetworkHint` (LLDP, else CDP) |
|
|
25
|
+
| `get_environment` | ✅ | ✅ (per host) | quick stats + hardware sensors |
|
|
26
|
+
| `get_vms` | ✅ | ✅ | VMs, templates excluded |
|
|
27
|
+
| `get_vm_config` | ✅ | ✅ | virtual hardware |
|
|
28
|
+
| `start_vm`, `stop_vm`, `reboot_vm`, `suspend_vm` | ✅ | ✅ | power tasks / VMware Tools |
|
|
29
|
+
| `get_vm_snapshots`, `create/delete/rollback_vm_snapshot` | ✅ | ✅ | snapshot tree |
|
|
30
|
+
| `get_vm_storage_pools` | ✅ | ✅ | datastores |
|
|
31
|
+
| `get_virtual_networks` | ✅ | ✅ (+ dvPortgroups) | port groups |
|
|
32
|
+
| `get_hypervisor_hosts` | ✅ | ✅ | connection state, maintenance mode, config issues, managing vCenter |
|
|
33
|
+
| `get_licenses` | ✅ | ✅ | license manager: name and edition key, never the key |
|
|
34
|
+
| `reboot_host` | ✅ (maintenance mode only) | — | `RebootHost_Task` |
|
|
35
|
+
| `create_vm_from_cloud_init`, `destroy_vm`, `get_vm_status` | ✅ | ✅ | see [Provisioning](#provisioning) |
|
|
36
|
+
| `get_network_targets`, `get_image_storages` | ✅ | ✅ | port groups, datastores |
|
|
37
|
+
| VIBs, updates | — | — | not yet |
|
|
38
|
+
|
|
39
|
+
Unverified assumptions, to be checked against real hardware:
|
|
40
|
+
|
|
41
|
+
- the HTTP fingerprints (`vmware esxi` on the Host Client page, `vcenter` on
|
|
42
|
+
the vSphere Client page)
|
|
43
|
+
- the free vSphere Hypervisor license reporting `editionKey` `esxBasic`
|
|
44
|
+
|
|
45
|
+
## Requirements
|
|
46
|
+
|
|
47
|
+
- HTTPS (443) to the host or vCenter. No SSH.
|
|
48
|
+
- An account that may read the inventory. For power and snapshot actions it
|
|
49
|
+
also needs *Virtual machine → Interaction → Power on/off/Reset/Suspend* and
|
|
50
|
+
*Virtual machine → Snapshot management*.
|
|
51
|
+
- For provisioning: `qemu-img` (package `qemu-utils`) where the driver runs,
|
|
52
|
+
and HTTPS from there to every ESXi host that may receive a VM -- through a
|
|
53
|
+
vCenter the disk upload goes straight to the host, not via the vCenter.
|
|
54
|
+
- **A paid license for any write.** On the free vSphere Hypervisor license
|
|
55
|
+
the API is read-only; the driver reports `vmware_api_read_only` and turns
|
|
56
|
+
the refusal into a readable error.
|
|
57
|
+
|
|
58
|
+
## Install
|
|
59
|
+
|
|
60
|
+
Python 3.10 or later.
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install napalm-vmware
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Usage
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from napalm_vmware import VmwareEsxiDriver
|
|
70
|
+
|
|
71
|
+
driver = VmwareEsxiDriver(
|
|
72
|
+
"esx01.example.lan", "root", "secret", optional_args={"verify_ssl": False}
|
|
73
|
+
)
|
|
74
|
+
driver.open()
|
|
75
|
+
print(driver.get_facts())
|
|
76
|
+
for vm in driver.get_vms():
|
|
77
|
+
print(vm["name"], vm["status"], vm["vmid"])
|
|
78
|
+
driver.close()
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`optional_args`: `port` (default 443), `verify_ssl` / `ssl_verify` (default
|
|
82
|
+
`True`; ESXi ships a self-signed certificate), `image_cache_dir` (where
|
|
83
|
+
converted cloud images are kept; default a directory under the system temp
|
|
84
|
+
dir). Other keys are ignored.
|
|
85
|
+
|
|
86
|
+
VMs are addressed by name, by `vmid`, or by MoRef (`vm-42`). A name shared
|
|
87
|
+
by two VMs is refused rather than guessed.
|
|
88
|
+
|
|
89
|
+
## Tests
|
|
90
|
+
|
|
91
|
+
The rules are in [STANDARDS.md](https://git.netork.io/NAPALM/driver-standard/src/branch/main/STANDARDS.md).
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
python -m venv .venv && .venv/bin/pip install -e ".[dev]"
|
|
95
|
+
.venv/bin/pytest --cov # unit tests, no network
|
|
96
|
+
docker run -d --rm -p 127.0.0.1:8989:8989 vmware/vcsim -l 0.0.0.0:8989
|
|
97
|
+
docker run -d --rm -p 127.0.0.1:8990:8989 vmware/vcsim -esx -l 0.0.0.0:8989
|
|
98
|
+
VCSIM_VCENTER_PORT=8989 VCSIM_ESXI_PORT=8990 pytest -m vcsim
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Harvesting fixtures
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
tools/harvest.py esx01.example.lan root esxi8-dell # prompts for the password
|
|
105
|
+
tools/sanitize.py tools/harvest-out/esxi8-dell.json > tests/fixtures/esxi8-dell.json
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`harvest.py` reads exactly the property paths in `napalm_vmware/paths.py`,
|
|
109
|
+
the ones the drivers read. `tools/harvest-out/` is gitignored. Read the
|
|
110
|
+
sanitised file before committing it.
|
|
111
|
+
|
|
112
|
+
## Provisioning
|
|
113
|
+
|
|
114
|
+
`create_vm_from_cloud_init` takes the same cloud images netOrk's catalog
|
|
115
|
+
offers for Proxmox (qcow2/raw):
|
|
116
|
+
|
|
117
|
+
1. The image is downloaded where the driver runs, its checksum verified (one
|
|
118
|
+
retry), and converted with `qemu-img` to a streamOptimized VMDK. The VMDK
|
|
119
|
+
is cached by URL in `image_cache_dir`; the download is not kept.
|
|
120
|
+
2. A host is chosen that is connected, not in maintenance mode, and sees the
|
|
121
|
+
datastore and every requested port group (the named datastore, or the one
|
|
122
|
+
with the most free space).
|
|
123
|
+
3. The VM is created from a minimal OVF descriptor (PVSCSI disk, VMXNET3
|
|
124
|
+
NICs) and the disk streamed in over NFC.
|
|
125
|
+
4. Requested MACs are pinned, the disk grown to `disk_resize_gb`, and a
|
|
126
|
+
NoCloud seed ISO (user-data, meta-data, network-config) uploaded next to
|
|
127
|
+
the VM's files and attached as a CD-ROM on a new SATA controller.
|
|
128
|
+
5. The VM is powered on. Any failure after step 3 removes the VM again.
|
|
129
|
+
|
|
130
|
+
A port group fixes its VLAN, so `get_network_targets` reports each one with
|
|
131
|
+
`kind="portgroup"`, `vlan_aware=False` and its `fixed_vlan_tag`; a NIC asking
|
|
132
|
+
for a different `vlan_tag` is refused. The guest agent netOrk installs is
|
|
133
|
+
`open-vm-tools` (`GUEST_AGENTS`), which reports the IP address back. Only
|
|
134
|
+
Linux guests are provisioned; `guest_os` other than `"linux"` is refused
|
|
135
|
+
(BSD guests on VMware: NetOrk/netork#801).
|
|
136
|
+
|
|
137
|
+
Unverified until #305: that each distribution's cloud kernel carries the
|
|
138
|
+
PVSCSI and VMXNET3 drivers.
|
|
139
|
+
|
|
140
|
+
## Design notes
|
|
141
|
+
|
|
142
|
+
**One seam.** Every read goes through `Inventory.collect(type, paths)`, a
|
|
143
|
+
PropertyCollector query with explicit paths, and every result is converted
|
|
144
|
+
by `to_plain()` into dicts, lists and scalars (managed objects become their
|
|
145
|
+
MoRef, data objects get a `_type`). The parsers in `napalm_vmware/parse/`
|
|
146
|
+
only ever see that plain form, so a harvested JSON file and a live host feed
|
|
147
|
+
them identically. Lazy attribute access on pyVmomi objects is avoided on
|
|
148
|
+
purpose: it fails on some servers where the individual paths work.
|
|
149
|
+
|
|
150
|
+
**`vmid` is the instance UUID** (`config.instanceUuid`). It survives vMotion
|
|
151
|
+
and re-registration and is unique within a vCenter; a MoRef is none of those.
|
|
152
|
+
The MoRef is reported alongside as `moref`.
|
|
153
|
+
|
|
154
|
+
**The vCenter device has no interfaces.** The hosts' NICs belong to the
|
|
155
|
+
hosts. Reporting them on the vCenter would attach their MACs to the wrong
|
|
156
|
+
device. Add a host with `vmware_esxi` to see its NICs.
|
|
157
|
+
|
|
158
|
+
**Facts, not warnings.** The driver names no warnings. `get_hypervisor_hosts()`
|
|
159
|
+
and `get_licenses()` report what the endpoint says; whether a host in
|
|
160
|
+
maintenance mode or the free `esxBasic` edition is a problem is the caller's
|
|
161
|
+
to decide. The ESXi driver reports `connected` as `None` (a disconnected host
|
|
162
|
+
could not have answered) and the managing vCenter's address as `managed_by`;
|
|
163
|
+
under the vCenter driver `managed_by` is `None`, since every host names it.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""Bulk reads through the vSphere PropertyCollector.
|
|
2
|
+
|
|
3
|
+
Every read in this package asks for an explicit list of property paths
|
|
4
|
+
(``napalm_vmware.paths``) instead of touching attributes on managed objects.
|
|
5
|
+
One round trip per object type rather than one per attribute, and it keeps
|
|
6
|
+
working where lazy attribute access does not: pyVmomi fails to deserialize
|
|
7
|
+
whole ``summary`` objects from some servers while the individual paths are
|
|
8
|
+
fine.
|
|
9
|
+
|
|
10
|
+
This class is the one seam the tests replace. Its output is already plain
|
|
11
|
+
(see :mod:`napalm_vmware._plain`), so a fake only has to return dicts.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from collections.abc import Sequence
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
from pyVmomi import vim, vmodl
|
|
20
|
+
|
|
21
|
+
from napalm_vmware._plain import to_plain
|
|
22
|
+
|
|
23
|
+
_PC = vmodl.query.PropertyCollector
|
|
24
|
+
_PAGE_SIZE = 500
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _vim_type(type_name: str) -> Any:
|
|
28
|
+
vim_type = getattr(vim, type_name, None) or getattr(vim.dvs, type_name, None)
|
|
29
|
+
if vim_type is None:
|
|
30
|
+
raise ValueError(f"Unknown vSphere managed object type {type_name!r}")
|
|
31
|
+
return vim_type
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Inventory:
|
|
35
|
+
"""Read-only access to a connected ServiceInstance's content."""
|
|
36
|
+
|
|
37
|
+
def __init__(self, content: Any) -> None:
|
|
38
|
+
self._content = content
|
|
39
|
+
|
|
40
|
+
def about(self) -> dict[str, Any]:
|
|
41
|
+
"""``ServiceContent.about``: product, version and API type of the endpoint."""
|
|
42
|
+
return to_plain(self._content.about)
|
|
43
|
+
|
|
44
|
+
def collect(self, type_name: str, paths: Sequence[str]) -> list[dict[str, Any]]:
|
|
45
|
+
"""Every object of ``type_name`` in the inventory, with the given properties."""
|
|
46
|
+
vim_type = _vim_type(type_name)
|
|
47
|
+
view = self._content.viewManager.CreateContainerView(
|
|
48
|
+
self._content.rootFolder, [vim_type], True
|
|
49
|
+
)
|
|
50
|
+
try:
|
|
51
|
+
traversal = _PC.TraversalSpec(
|
|
52
|
+
name="view", path="view", skip=False, type=vim.view.ContainerView
|
|
53
|
+
)
|
|
54
|
+
obj_spec = _PC.ObjectSpec(obj=view, skip=True, selectSet=[traversal])
|
|
55
|
+
return self._retrieve(obj_spec, vim_type, paths)
|
|
56
|
+
finally:
|
|
57
|
+
view.Destroy()
|
|
58
|
+
|
|
59
|
+
def properties(self, obj: Any, paths: Sequence[str], *, raw: bool = False) -> dict[str, Any]:
|
|
60
|
+
"""The given properties of one managed object; ``{}`` if it is gone.
|
|
61
|
+
|
|
62
|
+
``raw=True`` keeps the pyVmomi objects -- for a caller that has to hand
|
|
63
|
+
a device back to vSphere whole, backing and all, in a reconfigure.
|
|
64
|
+
"""
|
|
65
|
+
rows = self._retrieve(_PC.ObjectSpec(obj=obj), type(obj), paths, raw=raw)
|
|
66
|
+
return rows[0] if rows else {}
|
|
67
|
+
|
|
68
|
+
def licenses(self) -> list[dict[str, Any]]:
|
|
69
|
+
"""Licenses assigned on this endpoint (edition key, name, used/total)."""
|
|
70
|
+
manager = getattr(self._content, "licenseManager", None)
|
|
71
|
+
if manager is None:
|
|
72
|
+
return []
|
|
73
|
+
return self.properties(manager, ["licenses"]).get("licenses", [])
|
|
74
|
+
|
|
75
|
+
def _retrieve(
|
|
76
|
+
self, obj_spec: Any, vim_type: Any, paths: Sequence[str], *, raw: bool = False
|
|
77
|
+
) -> list[dict[str, Any]]:
|
|
78
|
+
spec = _PC.FilterSpec(
|
|
79
|
+
objectSet=[obj_spec], propSet=[_PC.PropertySpec(type=vim_type, pathSet=list(paths))]
|
|
80
|
+
)
|
|
81
|
+
pc = self._content.propertyCollector
|
|
82
|
+
result = pc.RetrievePropertiesEx([spec], _PC.RetrieveOptions(maxObjects=_PAGE_SIZE))
|
|
83
|
+
rows: list[dict[str, Any]] = []
|
|
84
|
+
while result is not None:
|
|
85
|
+
rows.extend(_row(obj, raw) for obj in result.objects)
|
|
86
|
+
if not result.token:
|
|
87
|
+
break
|
|
88
|
+
result = pc.ContinueRetrievePropertiesEx(token=result.token)
|
|
89
|
+
return rows
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _row(obj_content: Any, raw: bool = False) -> dict[str, Any]:
|
|
93
|
+
row: dict[str, Any] = {"_moref": obj_content.obj._moId}
|
|
94
|
+
for prop in obj_content.propSet or []:
|
|
95
|
+
row[prop.name] = prop.val if raw else to_plain(prop.val)
|
|
96
|
+
return row
|