fb-vmware 1.5.3__py3-none-any.whl → 1.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fb_vmware/__init__.py +3 -3
- fb_vmware/about.py +70 -59
- fb_vmware/app/__init__.py +104 -39
- fb_vmware/app/get_host_list.py +164 -97
- fb_vmware/app/get_network_list.py +200 -127
- fb_vmware/app/get_storage_cluster_list.py +139 -79
- fb_vmware/app/get_storage_list.py +453 -0
- fb_vmware/app/get_vm_info.py +115 -58
- fb_vmware/app/get_vm_list.py +226 -128
- fb_vmware/base.py +85 -57
- fb_vmware/cluster.py +165 -79
- fb_vmware/config/__init__.py +161 -115
- fb_vmware/connect.py +870 -405
- fb_vmware/controller.py +146 -106
- fb_vmware/datastore.py +255 -111
- fb_vmware/dc.py +95 -59
- fb_vmware/disk.py +145 -98
- fb_vmware/ds_cluster.py +160 -57
- fb_vmware/dvs.py +275 -160
- fb_vmware/errors.py +48 -40
- fb_vmware/ether.py +196 -141
- fb_vmware/host.py +274 -164
- fb_vmware/host_port_group.py +115 -68
- fb_vmware/iface.py +35 -24
- fb_vmware/network.py +165 -77
- fb_vmware/obj.py +72 -58
- fb_vmware/typed_dict.py +25 -26
- fb_vmware/vm.py +266 -164
- fb_vmware/xlate.py +24 -27
- fb_vmware-1.7.0.data/data/.gitkeep +0 -0
- fb_vmware-1.7.0.data/data/share/locale/de_DE/LC_MESSAGES/fb_vmware.mo +0 -0
- fb_vmware-1.7.0.data/data/share/locale/en_US/LC_MESSAGES/fb_vmware.mo +0 -0
- fb_vmware-1.7.0.dist-info/METADATA +54 -0
- fb_vmware-1.7.0.dist-info/RECORD +37 -0
- {fb_vmware-1.5.3.dist-info → fb_vmware-1.7.0.dist-info}/WHEEL +1 -2
- fb_vmware-1.7.0.dist-info/entry_points.txt +8 -0
- fb_vmware/local_version.py +0 -17
- fb_vmware-1.5.3.data/data/share/locale/de_DE/LC_MESSAGES/fb_vmware.mo +0 -0
- fb_vmware-1.5.3.data/data/share/locale/en_US/LC_MESSAGES/fb_vmware.mo +0 -0
- fb_vmware-1.5.3.data/scripts/get-vsphere-host-list +0 -71
- fb_vmware-1.5.3.data/scripts/get-vsphere-network-list +0 -71
- fb_vmware-1.5.3.data/scripts/get-vsphere-storage-cluster-list +0 -71
- fb_vmware-1.5.3.data/scripts/get-vsphere-vm-info +0 -71
- fb_vmware-1.5.3.data/scripts/get-vsphere-vm-list +0 -71
- fb_vmware-1.5.3.dist-info/METADATA +0 -51
- fb_vmware-1.5.3.dist-info/RECORD +0 -41
- fb_vmware-1.5.3.dist-info/top_level.txt +0 -1
- {fb_vmware-1.5.3.dist-info → fb_vmware-1.7.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
"""
|
|
4
|
-
@summary:
|
|
4
|
+
@summary: Print a list of all networks in a VMware vSphere.
|
|
5
5
|
|
|
6
6
|
@author: Frank Brehm
|
|
7
7
|
@contact: frank@brehm-online.com
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
from __future__ import absolute_import, print_function
|
|
11
11
|
|
|
12
12
|
# Standard modules
|
|
13
|
+
import locale
|
|
13
14
|
import logging
|
|
15
|
+
import pathlib
|
|
14
16
|
import sys
|
|
15
17
|
from operator import itemgetter
|
|
16
18
|
|
|
@@ -26,12 +28,13 @@ from ..network import GeneralNetworksDict
|
|
|
26
28
|
from ..network import VsphereNetwork
|
|
27
29
|
from ..xlate import XLATOR
|
|
28
30
|
|
|
29
|
-
__version__ =
|
|
31
|
+
__version__ = "1.7.0"
|
|
30
32
|
LOG = logging.getLogger(__name__)
|
|
31
33
|
|
|
32
34
|
_ = XLATOR.gettext
|
|
33
35
|
ngettext = XLATOR.ngettext
|
|
34
36
|
|
|
37
|
+
|
|
35
38
|
# =============================================================================
|
|
36
39
|
class GetVmNetworkAppError(VmwareAppError):
|
|
37
40
|
"""Base exception class for all exceptions in this application."""
|
|
@@ -45,20 +48,31 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
45
48
|
|
|
46
49
|
# -------------------------------------------------------------------------
|
|
47
50
|
def __init__(
|
|
48
|
-
self,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
self,
|
|
52
|
+
appname=None,
|
|
53
|
+
verbose=0,
|
|
54
|
+
version=GLOBAL_VERSION,
|
|
55
|
+
base_dir=None,
|
|
56
|
+
initialized=False,
|
|
57
|
+
usage=None,
|
|
58
|
+
description=None,
|
|
59
|
+
argparse_epilog=None,
|
|
60
|
+
argparse_prefix_chars="-",
|
|
61
|
+
env_prefix=None,
|
|
62
|
+
):
|
|
51
63
|
"""Initialize a GetNetworkListApp object."""
|
|
52
|
-
desc = _(
|
|
53
|
-
'Tries to get a list of all networks in '
|
|
54
|
-
'VMWare VSphere and print it out.')
|
|
64
|
+
desc = _("Tries to get a list of all networks in VMware vSphere and print it out.")
|
|
55
65
|
|
|
56
66
|
self.all_dvpgs = GeneralNetworksDict()
|
|
57
67
|
self.all_networks = GeneralNetworksDict()
|
|
58
68
|
|
|
59
69
|
super(GetNetworkListApp, self).__init__(
|
|
60
|
-
appname=appname,
|
|
61
|
-
|
|
70
|
+
appname=appname,
|
|
71
|
+
verbose=verbose,
|
|
72
|
+
version=version,
|
|
73
|
+
base_dir=base_dir,
|
|
74
|
+
description=desc,
|
|
75
|
+
initialized=False,
|
|
62
76
|
)
|
|
63
77
|
|
|
64
78
|
self.initialized = True
|
|
@@ -81,8 +95,7 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
81
95
|
# -------------------------------------------------------------------------
|
|
82
96
|
def _run(self):
|
|
83
97
|
|
|
84
|
-
LOG.debug(_(
|
|
85
|
-
a=self.appname, v=self.version))
|
|
98
|
+
LOG.debug(_("Starting {a!r}, version {v!r} ...").format(a=self.appname, v=self.version))
|
|
86
99
|
|
|
87
100
|
VsphereNetwork.warn_unassigned_net = False
|
|
88
101
|
|
|
@@ -99,12 +112,12 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
99
112
|
|
|
100
113
|
# -------------------------------------------------------------------------
|
|
101
114
|
def get_networks(self, vsphere_name):
|
|
102
|
-
"""Get all networks in a
|
|
115
|
+
"""Get all networks in a VMware vSphere."""
|
|
103
116
|
networks = []
|
|
104
117
|
|
|
105
118
|
vsphere = self.vsphere[vsphere_name]
|
|
106
119
|
try:
|
|
107
|
-
vsphere.get_networks()
|
|
120
|
+
vsphere.get_networks(vsphere_name=vsphere_name)
|
|
108
121
|
|
|
109
122
|
except VSphereExpectedError as e:
|
|
110
123
|
LOG.error(str(e))
|
|
@@ -120,10 +133,10 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
120
133
|
|
|
121
134
|
for vsphere_name in self.vsphere:
|
|
122
135
|
vsphere = self.vsphere[vsphere_name]
|
|
123
|
-
LOG.debug(_(
|
|
136
|
+
LOG.debug(_("Get all network-like objects from vSphere {!r} ...").format(vsphere_name))
|
|
124
137
|
|
|
125
138
|
try:
|
|
126
|
-
vsphere.get_networks()
|
|
139
|
+
vsphere.get_networks(vsphere_name=vsphere_name)
|
|
127
140
|
except VSphereExpectedError as e:
|
|
128
141
|
LOG.error(str(e))
|
|
129
142
|
self.exit(6)
|
|
@@ -140,12 +153,12 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
140
153
|
self._get_all_networks()
|
|
141
154
|
|
|
142
155
|
else:
|
|
143
|
-
spin_prompt = _(
|
|
156
|
+
spin_prompt = _("Getting all vSphere networks") + " "
|
|
144
157
|
spinner_name = self.get_random_spinner_name()
|
|
145
158
|
with Spinner(spin_prompt, spinner_name):
|
|
146
159
|
self._get_all_networks()
|
|
147
|
-
sys.stdout.write(
|
|
148
|
-
sys.stdout.write(
|
|
160
|
+
sys.stdout.write(" " * len(spin_prompt))
|
|
161
|
+
sys.stdout.write("\r")
|
|
149
162
|
sys.stdout.flush()
|
|
150
163
|
|
|
151
164
|
if self.verbose > 2:
|
|
@@ -155,7 +168,7 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
155
168
|
for uuid in self.vsphere[vsphere_name].dvs.keys():
|
|
156
169
|
dvs[vsphere_name][uuid] = self.vsphere[vsphere_name].dvs[uuid].as_dict()
|
|
157
170
|
|
|
158
|
-
msg = _(
|
|
171
|
+
msg = _("Found Distributed Virtual Switches:") + "\n" + pp(dvs)
|
|
159
172
|
LOG.debug(msg)
|
|
160
173
|
|
|
161
174
|
if self.verbose > 2:
|
|
@@ -175,9 +188,9 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
175
188
|
if len(networks_lists[vsphere_name]):
|
|
176
189
|
networks[vsphere_name] = [networks_lists[vsphere_name][0]]
|
|
177
190
|
|
|
178
|
-
msg = _(
|
|
191
|
+
msg = _("Found Distributed Virtual Portgroups:") + pp(dv_port_groups)
|
|
179
192
|
LOG.debug(msg)
|
|
180
|
-
msg = _(
|
|
193
|
+
msg = _("Found Virtual Networks:") + pp(networks)
|
|
181
194
|
LOG.debug(msg)
|
|
182
195
|
|
|
183
196
|
return ret
|
|
@@ -188,23 +201,23 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
188
201
|
all_dvs = []
|
|
189
202
|
|
|
190
203
|
print()
|
|
191
|
-
title = _(
|
|
192
|
-
print(self.colored(title,
|
|
193
|
-
print(self.colored(
|
|
204
|
+
title = _("Distributed Virtual Switches")
|
|
205
|
+
print(self.colored(title, "cyan"))
|
|
206
|
+
print(self.colored("=" * len(title), "cyan"))
|
|
194
207
|
|
|
195
208
|
# -----------------------------
|
|
196
209
|
def get_contact(dvs):
|
|
197
210
|
"""Generate and return a contact string for this DVS."""
|
|
198
211
|
contact_name = None
|
|
199
212
|
contact_info = None
|
|
200
|
-
contact =
|
|
213
|
+
contact = "~"
|
|
201
214
|
if dvs.contact_name is not None:
|
|
202
215
|
contact_name = dvs.contact_name.strip()
|
|
203
216
|
if dvs.contact_info is not None:
|
|
204
217
|
contact_info = dvs.contact_info.strip()
|
|
205
218
|
if contact_name:
|
|
206
219
|
if contact_info:
|
|
207
|
-
contact =
|
|
220
|
+
contact = "{n} ({i})".format(n=contact_name, i=contact_info)
|
|
208
221
|
else:
|
|
209
222
|
contact = contact_name
|
|
210
223
|
elif contact_info:
|
|
@@ -216,16 +229,21 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
216
229
|
for uuid in self.vsphere[vsphere_name].dvs.keys():
|
|
217
230
|
this_dvs = self.vsphere[vsphere_name].dvs[uuid]
|
|
218
231
|
|
|
232
|
+
dc_name = "~"
|
|
233
|
+
if this_dvs.dc_name:
|
|
234
|
+
dc_name = this_dvs.dc_name
|
|
235
|
+
|
|
219
236
|
dvs = {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
237
|
+
"vsphere": vsphere_name,
|
|
238
|
+
"dc": dc_name,
|
|
239
|
+
"name": this_dvs.name,
|
|
240
|
+
"contact": get_contact(this_dvs),
|
|
241
|
+
"create_time": this_dvs.create_time.isoformat(sep=" ", timespec="seconds"),
|
|
242
|
+
"description": this_dvs.description,
|
|
243
|
+
"hosts": "{:,}".format(this_dvs.num_hosts),
|
|
244
|
+
"ports": "{:,}".format(this_dvs.num_ports),
|
|
245
|
+
"standalone_ports": "{:,}".format(this_dvs.num_standalone_ports),
|
|
246
|
+
"ratio_reservation": "{:d} %".format(this_dvs.pnic_cap_ratio_reservation),
|
|
229
247
|
}
|
|
230
248
|
all_dvs.append(dvs)
|
|
231
249
|
|
|
@@ -234,25 +252,34 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
234
252
|
return
|
|
235
253
|
|
|
236
254
|
print()
|
|
237
|
-
print(_(
|
|
255
|
+
print(_("No Distributed Virtual Switches found."))
|
|
238
256
|
|
|
239
257
|
# -------------------------------------------------------------------------
|
|
240
258
|
def _print_virtual_switches(self, all_dvs):
|
|
241
259
|
|
|
242
260
|
labels = {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
261
|
+
"vsphere": "vSphere",
|
|
262
|
+
"dc": _("Data Center"),
|
|
263
|
+
"name": _("Name"),
|
|
264
|
+
"contact": _("Contact"),
|
|
265
|
+
"create_time": _("Creation time"),
|
|
266
|
+
"description": _("Description"),
|
|
267
|
+
"hosts": _("Hosts"),
|
|
268
|
+
"ports": _("Ports"),
|
|
269
|
+
"standalone_ports": _("Standalone Ports"),
|
|
270
|
+
"ratio_reservation": _("Ratio reservation"),
|
|
252
271
|
}
|
|
253
272
|
label_list = (
|
|
254
|
-
|
|
255
|
-
|
|
273
|
+
"name",
|
|
274
|
+
"vsphere",
|
|
275
|
+
"dc",
|
|
276
|
+
"create_time",
|
|
277
|
+
"hosts",
|
|
278
|
+
"ports",
|
|
279
|
+
"standalone_ports",
|
|
280
|
+
"ratio_reservation",
|
|
281
|
+
"contact",
|
|
282
|
+
"description",
|
|
256
283
|
)
|
|
257
284
|
|
|
258
285
|
str_lengths = {}
|
|
@@ -265,7 +292,7 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
265
292
|
for label in labels.keys():
|
|
266
293
|
val = dvs[label]
|
|
267
294
|
if val is None:
|
|
268
|
-
val =
|
|
295
|
+
val = "-"
|
|
269
296
|
dvs[label] = val
|
|
270
297
|
if len(val) > str_lengths[label]:
|
|
271
298
|
str_lengths[label] = len(val)
|
|
@@ -276,26 +303,26 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
276
303
|
max_len += str_lengths[label]
|
|
277
304
|
|
|
278
305
|
if self.verbose > 1:
|
|
279
|
-
LOG.debug(
|
|
280
|
-
LOG.debug(
|
|
306
|
+
LOG.debug("Label length:\n" + pp(str_lengths))
|
|
307
|
+
LOG.debug("Max line length: {} chars".format(max_len))
|
|
281
308
|
|
|
282
|
-
tpl =
|
|
309
|
+
tpl = ""
|
|
283
310
|
for label in label_list:
|
|
284
|
-
if tpl !=
|
|
285
|
-
tpl +=
|
|
286
|
-
if label in (
|
|
287
|
-
tpl +=
|
|
311
|
+
if tpl != "":
|
|
312
|
+
tpl += " "
|
|
313
|
+
if label in ("hosts", "ports", "standalone_ports", "ratio_reservation"):
|
|
314
|
+
tpl += "{{{la}:>{le}}}".format(la=label, le=str_lengths[label])
|
|
288
315
|
else:
|
|
289
|
-
tpl +=
|
|
316
|
+
tpl += "{{{la}:<{le}}}".format(la=label, le=str_lengths[label])
|
|
290
317
|
if self.verbose > 1:
|
|
291
|
-
LOG.debug(_(
|
|
318
|
+
LOG.debug(_("Line template: {}").format(tpl))
|
|
292
319
|
|
|
293
320
|
if not self.quiet:
|
|
294
321
|
print()
|
|
295
322
|
print(tpl.format(**labels))
|
|
296
|
-
print(
|
|
323
|
+
print("-" * max_len)
|
|
297
324
|
|
|
298
|
-
sort_keys = [
|
|
325
|
+
sort_keys = ["vsphere", "name"]
|
|
299
326
|
all_dvs.sort(key=itemgetter(*sort_keys))
|
|
300
327
|
for dvs in all_dvs:
|
|
301
328
|
count += 1
|
|
@@ -307,37 +334,47 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
307
334
|
all_dvpgs = []
|
|
308
335
|
|
|
309
336
|
print()
|
|
310
|
-
title = _(
|
|
311
|
-
print(self.colored(title,
|
|
312
|
-
print(self.colored(
|
|
337
|
+
title = _("Distributed Virtual Port Groups")
|
|
338
|
+
print(self.colored(title, "cyan"))
|
|
339
|
+
print(self.colored("=" * len(title), "cyan"))
|
|
313
340
|
|
|
314
341
|
for vsphere_name in self.vsphere:
|
|
315
342
|
for name in self.vsphere[vsphere_name].dv_portgroups.keys():
|
|
316
343
|
this_dvpg = self.vsphere[vsphere_name].dv_portgroups[name]
|
|
317
|
-
dvs_name =
|
|
344
|
+
dvs_name = "~"
|
|
318
345
|
dvs_uuid = this_dvpg.dvs_uuid
|
|
319
346
|
if dvs_uuid in self.vsphere[vsphere_name].dvs:
|
|
320
347
|
dvs_name = self.vsphere[vsphere_name].dvs[dvs_uuid].name
|
|
321
|
-
network =
|
|
348
|
+
network = "~"
|
|
322
349
|
if this_dvpg.network:
|
|
323
350
|
network = str(this_dvpg.network)
|
|
324
|
-
uplink = _(
|
|
351
|
+
uplink = _("No")
|
|
325
352
|
if this_dvpg.uplink:
|
|
326
|
-
uplink = _(
|
|
327
|
-
accessible =
|
|
353
|
+
uplink = _("Yes")
|
|
354
|
+
accessible = "No"
|
|
328
355
|
if this_dvpg.accessible:
|
|
329
|
-
accessible = _(
|
|
356
|
+
accessible = _("Yes")
|
|
357
|
+
|
|
358
|
+
dc_name = "~"
|
|
359
|
+
if this_dvpg.dc_name:
|
|
360
|
+
dc_name = this_dvpg.dc_name
|
|
361
|
+
|
|
362
|
+
vlan_id = "~"
|
|
363
|
+
if this_dvpg.vlan_id:
|
|
364
|
+
vlan_id = this_dvpg.vlan_id
|
|
330
365
|
|
|
331
366
|
dvpg = {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
367
|
+
"vsphere": vsphere_name,
|
|
368
|
+
"dc": dc_name,
|
|
369
|
+
"name": name,
|
|
370
|
+
"dvs": dvs_name,
|
|
371
|
+
"vlan_id": vlan_id,
|
|
372
|
+
"network": network,
|
|
373
|
+
"accessible": accessible,
|
|
374
|
+
"num_ports": "{:,}".format(this_dvpg.num_ports),
|
|
375
|
+
"type": this_dvpg.pg_type,
|
|
376
|
+
"uplink": uplink,
|
|
377
|
+
"description": this_dvpg.description,
|
|
341
378
|
}
|
|
342
379
|
all_dvpgs.append(dvpg)
|
|
343
380
|
|
|
@@ -346,25 +383,36 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
346
383
|
return
|
|
347
384
|
|
|
348
385
|
print()
|
|
349
|
-
print(_(
|
|
386
|
+
print(_("No Distributed Virtual Port Groups found."))
|
|
350
387
|
|
|
351
388
|
# -------------------------------------------------------------------------
|
|
352
389
|
def _print_dv_portgroups(self, all_dvpgs):
|
|
353
390
|
|
|
354
391
|
labels = {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
392
|
+
"vsphere": "vSphere",
|
|
393
|
+
"dc": "DC",
|
|
394
|
+
"name": _("Name"),
|
|
395
|
+
"dvs": "DV Switch",
|
|
396
|
+
"vlan_id": "VLAN ID",
|
|
397
|
+
"network": _("Network"),
|
|
398
|
+
"accessible": _("Accessible"),
|
|
399
|
+
"num_ports": _("Ports"),
|
|
400
|
+
"type": _("Type"),
|
|
401
|
+
"uplink": _("Uplink"),
|
|
402
|
+
"description": _("Description"),
|
|
364
403
|
}
|
|
365
404
|
label_list = (
|
|
366
|
-
|
|
367
|
-
|
|
405
|
+
"name",
|
|
406
|
+
"vsphere",
|
|
407
|
+
"dc",
|
|
408
|
+
"dvs",
|
|
409
|
+
"vlan_id",
|
|
410
|
+
"network",
|
|
411
|
+
"accessible",
|
|
412
|
+
"type",
|
|
413
|
+
"num_ports",
|
|
414
|
+
"uplink",
|
|
415
|
+
"description",
|
|
368
416
|
)
|
|
369
417
|
|
|
370
418
|
str_lengths = {}
|
|
@@ -377,7 +425,7 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
377
425
|
for label in labels.keys():
|
|
378
426
|
val = dvpg[label]
|
|
379
427
|
if val is None:
|
|
380
|
-
val =
|
|
428
|
+
val = "-"
|
|
381
429
|
dvpg[label] = val
|
|
382
430
|
if len(val) > str_lengths[label]:
|
|
383
431
|
str_lengths[label] = len(val)
|
|
@@ -388,24 +436,24 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
388
436
|
max_len += str_lengths[label]
|
|
389
437
|
|
|
390
438
|
if self.verbose > 1:
|
|
391
|
-
LOG.debug(
|
|
392
|
-
LOG.debug(
|
|
439
|
+
LOG.debug("Label length:\n" + pp(str_lengths))
|
|
440
|
+
LOG.debug("Max line length: {} chars".format(max_len))
|
|
393
441
|
|
|
394
|
-
tpl =
|
|
442
|
+
tpl = ""
|
|
395
443
|
for label in label_list:
|
|
396
|
-
if tpl !=
|
|
397
|
-
tpl +=
|
|
398
|
-
if label in (
|
|
399
|
-
tpl +=
|
|
444
|
+
if tpl != "":
|
|
445
|
+
tpl += " "
|
|
446
|
+
if label in ("num_ports", "vlan_id"):
|
|
447
|
+
tpl += "{{{la}:>{le}}}".format(la=label, le=str_lengths[label])
|
|
400
448
|
else:
|
|
401
|
-
tpl +=
|
|
449
|
+
tpl += "{{{la}:<{le}}}".format(la=label, le=str_lengths[label])
|
|
402
450
|
if self.verbose > 1:
|
|
403
|
-
LOG.debug(_(
|
|
451
|
+
LOG.debug(_("Line template: {}").format(tpl))
|
|
404
452
|
|
|
405
453
|
if not self.quiet:
|
|
406
454
|
print()
|
|
407
455
|
print(tpl.format(**labels))
|
|
408
|
-
print(
|
|
456
|
+
print("-" * max_len)
|
|
409
457
|
|
|
410
458
|
for dvpg in all_dvpgs:
|
|
411
459
|
count += 1
|
|
@@ -417,25 +465,30 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
417
465
|
all_networks = []
|
|
418
466
|
|
|
419
467
|
print()
|
|
420
|
-
title = _(
|
|
421
|
-
print(self.colored(title,
|
|
422
|
-
print(self.colored(
|
|
468
|
+
title = _("Virtual Networks")
|
|
469
|
+
print(self.colored(title, "cyan"))
|
|
470
|
+
print(self.colored("=" * len(title), "cyan"))
|
|
423
471
|
|
|
424
472
|
for vsphere_name in self.vsphere:
|
|
425
473
|
for name in self.vsphere[vsphere_name].networks.keys():
|
|
426
474
|
this_network = self.vsphere[vsphere_name].networks[name]
|
|
427
|
-
network =
|
|
475
|
+
network = "~"
|
|
428
476
|
if this_network.network:
|
|
429
477
|
network = str(this_network.network)
|
|
430
|
-
accessible =
|
|
478
|
+
accessible = "No"
|
|
431
479
|
if this_network.accessible:
|
|
432
|
-
accessible = _(
|
|
480
|
+
accessible = _("Yes")
|
|
481
|
+
|
|
482
|
+
dc_name = "~"
|
|
483
|
+
if this_network.dc_name:
|
|
484
|
+
dc_name = this_network.dc_name
|
|
433
485
|
|
|
434
486
|
net = {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
487
|
+
"vsphere": vsphere_name,
|
|
488
|
+
"dc": dc_name,
|
|
489
|
+
"name": name,
|
|
490
|
+
"network": network,
|
|
491
|
+
"accessible": accessible,
|
|
439
492
|
}
|
|
440
493
|
all_networks.append(net)
|
|
441
494
|
|
|
@@ -444,18 +497,19 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
444
497
|
return
|
|
445
498
|
|
|
446
499
|
print()
|
|
447
|
-
print(_(
|
|
500
|
+
print(_("No Virtual Networks found."))
|
|
448
501
|
|
|
449
502
|
# -------------------------------------------------------------------------
|
|
450
503
|
def _print_networks(self, all_networks):
|
|
451
504
|
|
|
452
505
|
labels = {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
506
|
+
"vsphere": "vSphere",
|
|
507
|
+
"dc": _("Data Center"),
|
|
508
|
+
"name": _("Name"),
|
|
509
|
+
"network": _("Network"),
|
|
510
|
+
"accessible": _("Accessible"),
|
|
457
511
|
}
|
|
458
|
-
label_list = (
|
|
512
|
+
label_list = ("name", "vsphere", "dc", "network", "accessible")
|
|
459
513
|
|
|
460
514
|
str_lengths = {}
|
|
461
515
|
for label in labels:
|
|
@@ -467,7 +521,7 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
467
521
|
for label in labels.keys():
|
|
468
522
|
val = net[label]
|
|
469
523
|
if val is None:
|
|
470
|
-
val =
|
|
524
|
+
val = "-"
|
|
471
525
|
net[label] = val
|
|
472
526
|
if len(val) > str_lengths[label]:
|
|
473
527
|
str_lengths[label] = len(val)
|
|
@@ -478,21 +532,21 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
478
532
|
max_len += str_lengths[label]
|
|
479
533
|
|
|
480
534
|
if self.verbose > 1:
|
|
481
|
-
LOG.debug(
|
|
482
|
-
LOG.debug(
|
|
535
|
+
LOG.debug("Label length:\n" + pp(str_lengths))
|
|
536
|
+
LOG.debug("Max line length: {} chars".format(max_len))
|
|
483
537
|
|
|
484
|
-
tpl =
|
|
538
|
+
tpl = ""
|
|
485
539
|
for label in label_list:
|
|
486
|
-
if tpl !=
|
|
487
|
-
tpl +=
|
|
488
|
-
tpl +=
|
|
540
|
+
if tpl != "":
|
|
541
|
+
tpl += " "
|
|
542
|
+
tpl += "{{{la}:<{le}}}".format(la=label, le=str_lengths[label])
|
|
489
543
|
if self.verbose > 1:
|
|
490
|
-
LOG.debug(_(
|
|
544
|
+
LOG.debug(_("Line template: {}").format(tpl))
|
|
491
545
|
|
|
492
546
|
if not self.quiet:
|
|
493
547
|
print()
|
|
494
548
|
print(tpl.format(**labels))
|
|
495
|
-
print(
|
|
549
|
+
print("-" * max_len)
|
|
496
550
|
|
|
497
551
|
for net in all_networks:
|
|
498
552
|
count += 1
|
|
@@ -500,7 +554,26 @@ class GetNetworkListApp(BaseVmwareApplication):
|
|
|
500
554
|
|
|
501
555
|
|
|
502
556
|
# =============================================================================
|
|
503
|
-
|
|
557
|
+
def main():
|
|
558
|
+
"""Entrypoint for get-vsphere-network-list."""
|
|
559
|
+
my_path = pathlib.Path(__file__)
|
|
560
|
+
appname = my_path.name
|
|
561
|
+
|
|
562
|
+
locale.setlocale(locale.LC_ALL, "")
|
|
563
|
+
|
|
564
|
+
app = GetNetworkListApp(appname=appname)
|
|
565
|
+
app.initialized = True
|
|
566
|
+
|
|
567
|
+
if app.verbose > 2:
|
|
568
|
+
print(_("{c}-Object:\n{a}").format(c=app.__class__.__name__, a=app), file=sys.stderr)
|
|
569
|
+
|
|
570
|
+
app()
|
|
571
|
+
|
|
572
|
+
sys.exit(0)
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
# =============================================================================
|
|
576
|
+
if __name__ == "__main__":
|
|
504
577
|
|
|
505
578
|
pass
|
|
506
579
|
|