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
fb_vmware/app/get_vm_list.py
CHANGED
|
@@ -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 re
|
|
15
17
|
import sys
|
|
16
18
|
from operator import attrgetter, itemgetter
|
|
@@ -28,7 +30,7 @@ from ..errors import VSphereExpectedError
|
|
|
28
30
|
from ..vm import VsphereVm
|
|
29
31
|
from ..xlate import XLATOR
|
|
30
32
|
|
|
31
|
-
__version__ =
|
|
33
|
+
__version__ = "1.9.0"
|
|
32
34
|
LOG = logging.getLogger(__name__)
|
|
33
35
|
|
|
34
36
|
_ = XLATOR.gettext
|
|
@@ -46,19 +48,38 @@ class GetVmListAppError(VmwareAppError):
|
|
|
46
48
|
class GetVmListApplication(BaseVmwareApplication):
|
|
47
49
|
"""Class for the application objects."""
|
|
48
50
|
|
|
49
|
-
default_vm_pattern = r
|
|
50
|
-
avail_sort_keys = (
|
|
51
|
-
|
|
51
|
+
default_vm_pattern = r".*"
|
|
52
|
+
avail_sort_keys = (
|
|
53
|
+
"name",
|
|
54
|
+
"vsphere",
|
|
55
|
+
"dc",
|
|
56
|
+
"cluster",
|
|
57
|
+
"path",
|
|
58
|
+
"type",
|
|
59
|
+
"onl_str",
|
|
60
|
+
"cfg_ver",
|
|
61
|
+
"os",
|
|
62
|
+
)
|
|
63
|
+
default_sort_keys = ["name", "vsphere", "dc"]
|
|
52
64
|
|
|
53
65
|
# -------------------------------------------------------------------------
|
|
54
66
|
def __init__(
|
|
55
|
-
self,
|
|
56
|
-
|
|
57
|
-
|
|
67
|
+
self,
|
|
68
|
+
appname=None,
|
|
69
|
+
verbose=0,
|
|
70
|
+
version=GLOBAL_VERSION,
|
|
71
|
+
base_dir=None,
|
|
72
|
+
initialized=False,
|
|
73
|
+
usage=None,
|
|
74
|
+
description=None,
|
|
75
|
+
argparse_epilog=None,
|
|
76
|
+
argparse_prefix_chars="-",
|
|
77
|
+
env_prefix=None,
|
|
78
|
+
):
|
|
58
79
|
"""Initialize a GetVmListApplication object."""
|
|
59
80
|
desc = _(
|
|
60
|
-
|
|
61
|
-
|
|
81
|
+
"Tries to get a list of all virtual machines in " "VMware vSphere and print it out."
|
|
82
|
+
)
|
|
62
83
|
|
|
63
84
|
self._vm_pattern = self.default_vm_pattern
|
|
64
85
|
self._details = False
|
|
@@ -71,8 +92,12 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
71
92
|
self.vms = []
|
|
72
93
|
|
|
73
94
|
super(GetVmListApplication, self).__init__(
|
|
74
|
-
appname=appname,
|
|
75
|
-
|
|
95
|
+
appname=appname,
|
|
96
|
+
verbose=verbose,
|
|
97
|
+
version=version,
|
|
98
|
+
base_dir=base_dir,
|
|
99
|
+
description=desc,
|
|
100
|
+
initialized=False,
|
|
76
101
|
)
|
|
77
102
|
|
|
78
103
|
self.initialized = True
|
|
@@ -105,9 +130,9 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
105
130
|
@rtype: dict
|
|
106
131
|
"""
|
|
107
132
|
res = super(GetVmListApplication, self).as_dict(short=short)
|
|
108
|
-
res[
|
|
109
|
-
res[
|
|
110
|
-
res[
|
|
133
|
+
res["details"] = self.details
|
|
134
|
+
res["vm_pattern"] = self.vm_pattern
|
|
135
|
+
res["default_vm_pattern"] = self.default_vm_pattern
|
|
111
136
|
|
|
112
137
|
return res
|
|
113
138
|
|
|
@@ -128,66 +153,105 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
128
153
|
"""Initiate the argument parser."""
|
|
129
154
|
super(GetVmListApplication, self).init_arg_parser()
|
|
130
155
|
|
|
131
|
-
filter_group = self.arg_parser.add_argument_group(_(
|
|
156
|
+
filter_group = self.arg_parser.add_argument_group(_("Filter options"))
|
|
132
157
|
|
|
133
158
|
filter_group.add_argument(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
159
|
+
"-p",
|
|
160
|
+
"--pattern",
|
|
161
|
+
"--search-pattern",
|
|
162
|
+
dest="vm_pattern",
|
|
163
|
+
metavar="REGEX",
|
|
164
|
+
action=RegexOptionAction,
|
|
165
|
+
topic=_("for names of VMs"),
|
|
166
|
+
re_options=re.IGNORECASE,
|
|
137
167
|
help=_(
|
|
138
|
-
|
|
139
|
-
|
|
168
|
+
"A regular expression to filter the output list of VMs by their name "
|
|
169
|
+
"(Default: {!r})."
|
|
170
|
+
).format(self.default_vm_pattern),
|
|
140
171
|
)
|
|
141
172
|
|
|
142
|
-
valid_vm_types = (
|
|
173
|
+
valid_vm_types = ("all", "vm", "template")
|
|
143
174
|
filter_group.add_argument(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
175
|
+
"-T",
|
|
176
|
+
"--type",
|
|
177
|
+
metavar=_("TYPE"),
|
|
178
|
+
dest="vm_type",
|
|
179
|
+
choices=valid_vm_types,
|
|
180
|
+
default="all",
|
|
181
|
+
help=_(
|
|
182
|
+
"Filter output for the type of the VM. Valid values are {li} "
|
|
183
|
+
"(Default: {dflt!r})."
|
|
184
|
+
).format(dflt="all", li=format_list(valid_vm_types, do_repr=True)),
|
|
149
185
|
)
|
|
150
186
|
|
|
151
187
|
online_filter = filter_group.add_mutually_exclusive_group()
|
|
152
188
|
online_filter.add_argument(
|
|
153
|
-
|
|
154
|
-
|
|
189
|
+
"--on",
|
|
190
|
+
"--online",
|
|
191
|
+
action="store_true",
|
|
192
|
+
dest="online",
|
|
193
|
+
help=_("Filter output for online VMs."),
|
|
155
194
|
)
|
|
156
195
|
online_filter.add_argument(
|
|
157
|
-
|
|
158
|
-
|
|
196
|
+
"--off",
|
|
197
|
+
"--offline",
|
|
198
|
+
action="store_true",
|
|
199
|
+
dest="offline",
|
|
200
|
+
help=_("Filter output for offline VMs and templates."),
|
|
159
201
|
)
|
|
160
202
|
|
|
161
203
|
filter_group.add_argument(
|
|
162
|
-
|
|
163
|
-
|
|
204
|
+
"-H",
|
|
205
|
+
"--hw",
|
|
206
|
+
"--hardware-config",
|
|
207
|
+
metavar="REGEX",
|
|
208
|
+
action=RegexOptionAction,
|
|
209
|
+
dest="hw",
|
|
210
|
+
topic=_("for VMware hardware config version"),
|
|
211
|
+
re_options=re.IGNORECASE,
|
|
164
212
|
help=_(
|
|
165
|
-
|
|
166
|
-
"configuration version (e.g. '{}')."
|
|
213
|
+
"A regular expression to filter the output list of VMs by the VMware hardware "
|
|
214
|
+
"configuration version (e.g. '{}')."
|
|
215
|
+
).format(r"vmx-0\d$"),
|
|
167
216
|
)
|
|
168
217
|
|
|
169
218
|
filter_group.add_argument(
|
|
170
|
-
|
|
171
|
-
|
|
219
|
+
"--os",
|
|
220
|
+
metavar="REGEX",
|
|
221
|
+
action=RegexOptionAction,
|
|
222
|
+
dest="os",
|
|
223
|
+
topic=_("for the Operating System version"),
|
|
224
|
+
re_options=re.IGNORECASE,
|
|
172
225
|
help=_(
|
|
173
|
-
|
|
174
|
-
"System version, e.g. '{}'."
|
|
226
|
+
"A regular expression to filter the output list of VMs by their Operating "
|
|
227
|
+
"System version, e.g. '{}'."
|
|
228
|
+
).format("oracleLinux.*(_64)?Guest"),
|
|
175
229
|
)
|
|
176
230
|
|
|
177
|
-
output_options = self.arg_parser.add_argument_group(_(
|
|
231
|
+
output_options = self.arg_parser.add_argument_group(_("Output options"))
|
|
178
232
|
|
|
179
233
|
output_options.add_argument(
|
|
180
|
-
|
|
181
|
-
|
|
234
|
+
"-D",
|
|
235
|
+
"--details",
|
|
236
|
+
dest="details",
|
|
237
|
+
action="store_true",
|
|
238
|
+
help=_("Detailed output list (quering data needs some time longer)."),
|
|
182
239
|
)
|
|
183
240
|
|
|
184
241
|
output_options.add_argument(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
242
|
+
"-S",
|
|
243
|
+
"--sort",
|
|
244
|
+
metavar="KEY",
|
|
245
|
+
nargs="+",
|
|
246
|
+
dest="sort_keys",
|
|
247
|
+
choices=self.avail_sort_keys,
|
|
248
|
+
help=_(
|
|
249
|
+
"The keys for sorting the output. Available keys are: {avail}. "
|
|
250
|
+
"The default sorting keys are: {default}."
|
|
251
|
+
).format(
|
|
189
252
|
avail=format_list(self.avail_sort_keys, do_repr=True),
|
|
190
|
-
default=format_list(self.default_sort_keys, do_repr=True)
|
|
253
|
+
default=format_list(self.default_sort_keys, do_repr=True),
|
|
254
|
+
),
|
|
191
255
|
)
|
|
192
256
|
|
|
193
257
|
# -------------------------------------------------------------------------
|
|
@@ -201,17 +265,23 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
201
265
|
if self.args.vm_pattern:
|
|
202
266
|
try:
|
|
203
267
|
re_name = re.compile(self.args.vm_pattern, re.IGNORECASE)
|
|
204
|
-
LOG.debug(_(
|
|
268
|
+
LOG.debug(_("Regular expression for filtering: {!r}").format(re_name.pattern))
|
|
205
269
|
self._vm_pattern = self.args.vm_pattern
|
|
206
270
|
except Exception as e:
|
|
207
|
-
msg = _(
|
|
208
|
-
c=e.__class__.__name__, p=self.args.vm_pattern, e=e
|
|
271
|
+
msg = _("Got a {c} for pattern {p!r}: {e}").format(
|
|
272
|
+
c=e.__class__.__name__, p=self.args.vm_pattern, e=e
|
|
273
|
+
)
|
|
209
274
|
LOG.error(msg)
|
|
210
275
|
|
|
211
276
|
if not self.details:
|
|
212
|
-
if
|
|
213
|
-
|
|
214
|
-
|
|
277
|
+
if (
|
|
278
|
+
self.args.online
|
|
279
|
+
or self.args.offline
|
|
280
|
+
or self.args.hw
|
|
281
|
+
or self.args.os
|
|
282
|
+
or self.args.vm_type != "all"
|
|
283
|
+
):
|
|
284
|
+
LOG.info(_("Detailed output is required because of your given options."))
|
|
215
285
|
self.details = True
|
|
216
286
|
|
|
217
287
|
if self.args.sort_keys:
|
|
@@ -220,16 +290,20 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
220
290
|
else:
|
|
221
291
|
self.sort_keys = []
|
|
222
292
|
for key in self.args.sort_keys:
|
|
223
|
-
if key in (
|
|
293
|
+
if key in ("name", "vsphere", "path"):
|
|
224
294
|
self.sort_keys.append(key)
|
|
225
295
|
else:
|
|
226
|
-
LOG.warn(
|
|
227
|
-
|
|
228
|
-
|
|
296
|
+
LOG.warn(
|
|
297
|
+
_(
|
|
298
|
+
"Sorting key {!r} not usable, if not detailed output " "was given."
|
|
299
|
+
).format(key)
|
|
300
|
+
)
|
|
229
301
|
if not self.sort_keys:
|
|
230
|
-
LOG.warn(
|
|
231
|
-
|
|
232
|
-
|
|
302
|
+
LOG.warn(
|
|
303
|
+
_("No usable sorting keys found, using default sorting keys {}.").format(
|
|
304
|
+
format_list(self.default_sort_keys, do_repr=True)
|
|
305
|
+
)
|
|
306
|
+
)
|
|
233
307
|
self.sort_keys = self.default_sort_keys
|
|
234
308
|
|
|
235
309
|
if self.args.hw:
|
|
@@ -240,8 +314,7 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
240
314
|
# -------------------------------------------------------------------------
|
|
241
315
|
def _run(self):
|
|
242
316
|
|
|
243
|
-
LOG.debug(_(
|
|
244
|
-
a=self.appname, v=self.version))
|
|
317
|
+
LOG.debug(_("Starting {a!r}, version {v!r} ...").format(a=self.appname, v=self.version))
|
|
245
318
|
|
|
246
319
|
ret = 0
|
|
247
320
|
try:
|
|
@@ -256,7 +329,7 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
256
329
|
|
|
257
330
|
# -------------------------------------------------------------------------
|
|
258
331
|
def get_all_vms(self):
|
|
259
|
-
"""Get all VMs from
|
|
332
|
+
"""Get all VMs from vSphere, maybe filtered."""
|
|
260
333
|
ret = 0
|
|
261
334
|
all_vms = []
|
|
262
335
|
|
|
@@ -266,17 +339,17 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
266
339
|
for vsphere_name in self.vsphere:
|
|
267
340
|
all_vms += self.get_vms(vsphere_name, re_name)
|
|
268
341
|
elif not self.quiet:
|
|
269
|
-
spin_prompt = _(
|
|
342
|
+
spin_prompt = _("Getting all vSphere VMs ...") + " "
|
|
270
343
|
spinner_name = self.get_random_spinner_name()
|
|
271
344
|
with Spinner(spin_prompt, spinner_name):
|
|
272
345
|
for vsphere_name in self.vsphere:
|
|
273
346
|
all_vms += self.get_vms(vsphere_name, re_name)
|
|
274
|
-
sys.stdout.write(
|
|
275
|
-
sys.stdout.write(
|
|
347
|
+
sys.stdout.write(" " * len(spin_prompt))
|
|
348
|
+
sys.stdout.write("\r")
|
|
276
349
|
sys.stdout.flush()
|
|
277
350
|
|
|
278
351
|
if self.verbose > 1:
|
|
279
|
-
LOG.debug(_(
|
|
352
|
+
LOG.debug(_("Using sorting keys:") + " " + format_list(self.sort_keys, do_repr=True))
|
|
280
353
|
|
|
281
354
|
if self.details:
|
|
282
355
|
self.print_vms_detailed(all_vms)
|
|
@@ -288,11 +361,12 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
288
361
|
# -------------------------------------------------------------------------
|
|
289
362
|
def print_vms(self, all_vms):
|
|
290
363
|
"""Print out on STDOUT the list of found VMs."""
|
|
291
|
-
label_list = (
|
|
364
|
+
label_list = ("name", "vsphere", "dc", "path")
|
|
292
365
|
labels = {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
366
|
+
"name": _("Host"),
|
|
367
|
+
"vsphere": "vSphere",
|
|
368
|
+
"dc": _("Data Center"),
|
|
369
|
+
"path": _("Path"),
|
|
296
370
|
}
|
|
297
371
|
|
|
298
372
|
self._print_vms(all_vms, label_list, labels)
|
|
@@ -302,14 +376,15 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
302
376
|
"""Print out on STDOUT the list of found VMs in a detailled way."""
|
|
303
377
|
label_list = self.avail_sort_keys
|
|
304
378
|
labels = {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
379
|
+
"name": "VM/Template",
|
|
380
|
+
"vsphere": "vSphere",
|
|
381
|
+
"dc": _("Data Center"),
|
|
382
|
+
"cluster": _("Cluster"),
|
|
383
|
+
"path": _("Path"),
|
|
384
|
+
"type": _("Type"),
|
|
385
|
+
"onl_str": _("Online Status"),
|
|
386
|
+
"cfg_ver": _("Config Version"),
|
|
387
|
+
"os": _("Operating System"),
|
|
313
388
|
}
|
|
314
389
|
|
|
315
390
|
self._print_vms(all_vms, label_list, labels)
|
|
@@ -324,9 +399,9 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
324
399
|
max_len = 0
|
|
325
400
|
count = 0
|
|
326
401
|
for cdata in all_vms:
|
|
327
|
-
for field in (
|
|
402
|
+
for field in ("cluster", "path", "type", "cfg_ver", "os"):
|
|
328
403
|
if field in labels and cdata[field] is None:
|
|
329
|
-
cdata[field] =
|
|
404
|
+
cdata[field] = "~"
|
|
330
405
|
for label in labels.keys():
|
|
331
406
|
val = cdata[label]
|
|
332
407
|
if len(val) > str_lengths[label]:
|
|
@@ -338,21 +413,21 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
338
413
|
max_len += str_lengths[label]
|
|
339
414
|
|
|
340
415
|
if self.verbose > 1:
|
|
341
|
-
LOG.debug(
|
|
342
|
-
LOG.debug(
|
|
416
|
+
LOG.debug("Label length:\n" + pp(str_lengths))
|
|
417
|
+
LOG.debug("Max line length: {} chars".format(max_len))
|
|
343
418
|
|
|
344
|
-
tpl =
|
|
419
|
+
tpl = ""
|
|
345
420
|
for label in label_list:
|
|
346
|
-
if tpl !=
|
|
347
|
-
tpl +=
|
|
348
|
-
tpl +=
|
|
421
|
+
if tpl != "":
|
|
422
|
+
tpl += " "
|
|
423
|
+
tpl += "{{{la}:<{le}}}".format(la=label, le=str_lengths[label])
|
|
349
424
|
if self.verbose > 1:
|
|
350
|
-
LOG.debug(_(
|
|
425
|
+
LOG.debug(_("Line template: {}").format(tpl))
|
|
351
426
|
|
|
352
427
|
if not self.quiet:
|
|
353
428
|
print()
|
|
354
429
|
print(tpl.format(**labels))
|
|
355
|
-
print(
|
|
430
|
+
print("-" * max_len)
|
|
356
431
|
|
|
357
432
|
all_vms.sort(key=itemgetter(*self.sort_keys))
|
|
358
433
|
|
|
@@ -364,17 +439,15 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
364
439
|
if not self.quiet:
|
|
365
440
|
print()
|
|
366
441
|
if count == 0:
|
|
367
|
-
msg = _(
|
|
442
|
+
msg = _("Found no VMware VMs.")
|
|
368
443
|
else:
|
|
369
|
-
msg = ngettext(
|
|
370
|
-
'Found one VMWare VM.',
|
|
371
|
-
'Found {} VMWare VMs.', count).format(count)
|
|
444
|
+
msg = ngettext("Found one VMware VM.", "Found {} VMware VMs.", count).format(count)
|
|
372
445
|
print(msg)
|
|
373
446
|
print()
|
|
374
447
|
|
|
375
448
|
# -------------------------------------------------------------------------
|
|
376
449
|
def get_vms(self, vsphere_name, re_name=None):
|
|
377
|
-
"""Get the filtered list of VMs from
|
|
450
|
+
"""Get the filtered list of VMs from vSphere."""
|
|
378
451
|
vsphere = self.vsphere[vsphere_name]
|
|
379
452
|
vsphere.get_datacenter()
|
|
380
453
|
|
|
@@ -394,7 +467,7 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
394
467
|
def mangle_vmlist_no_details(self, vm_list, vsphere_name):
|
|
395
468
|
"""Prepare the non-detailled data about found VMs for output."""
|
|
396
469
|
if self.verbose > 3:
|
|
397
|
-
LOG.debug(
|
|
470
|
+
LOG.debug("Mangling VM list:\n" + pp(vm_list))
|
|
398
471
|
|
|
399
472
|
vms = []
|
|
400
473
|
first = True
|
|
@@ -402,21 +475,22 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
402
475
|
for vm in sorted(vm_list, key=itemgetter(0, 1)):
|
|
403
476
|
|
|
404
477
|
if self.verbose > 2 and first:
|
|
405
|
-
LOG.debug(
|
|
478
|
+
LOG.debug("VM:\n" + pp(vm))
|
|
406
479
|
|
|
407
480
|
cdata = {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
481
|
+
"vsphere": vsphere_name,
|
|
482
|
+
"name": vm[0],
|
|
483
|
+
"dc": vm[1],
|
|
484
|
+
"path": vm[2],
|
|
411
485
|
}
|
|
412
486
|
|
|
413
|
-
if cdata[
|
|
414
|
-
cdata[
|
|
487
|
+
if cdata["path"]:
|
|
488
|
+
cdata["path"] = "/" + cdata["path"]
|
|
415
489
|
else:
|
|
416
|
-
cdata[
|
|
490
|
+
cdata["path"] = "/"
|
|
417
491
|
|
|
418
492
|
if self.verbose > 2 and first:
|
|
419
|
-
LOG.debug(
|
|
493
|
+
LOG.debug("Mangled VM:\n" + pp(cdata))
|
|
420
494
|
|
|
421
495
|
first = False
|
|
422
496
|
|
|
@@ -430,20 +504,20 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
430
504
|
vms = []
|
|
431
505
|
|
|
432
506
|
first = True
|
|
433
|
-
for vm in sorted(vm_list, key=attrgetter(
|
|
507
|
+
for vm in sorted(vm_list, key=attrgetter("name", "path")):
|
|
434
508
|
|
|
435
509
|
if not isinstance(vm, VsphereVm):
|
|
436
|
-
msg = _(
|
|
437
|
-
msg +=
|
|
510
|
+
msg = _("Found a {} object:").format(vm.__class__.__name__)
|
|
511
|
+
msg += "\n" + pp(vm)
|
|
438
512
|
LOG.error(msg)
|
|
439
513
|
continue
|
|
440
514
|
|
|
441
515
|
if self.verbose > 2 and first:
|
|
442
|
-
LOG.debug(
|
|
516
|
+
LOG.debug("VM:\n" + pp(vm.as_dict()))
|
|
443
517
|
|
|
444
518
|
cdata = self._mangle_vm_details(vm, vsphere_name)
|
|
445
519
|
if self.verbose > 2 and first and cdata:
|
|
446
|
-
LOG.debug(
|
|
520
|
+
LOG.debug("Mangled VM:\n" + pp(cdata))
|
|
447
521
|
|
|
448
522
|
first = False
|
|
449
523
|
|
|
@@ -459,8 +533,8 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
459
533
|
|
|
460
534
|
cdata = None
|
|
461
535
|
|
|
462
|
-
if self.args.vm_type !=
|
|
463
|
-
if self.args.vm_type ==
|
|
536
|
+
if self.args.vm_type != "all":
|
|
537
|
+
if self.args.vm_type == "vm":
|
|
464
538
|
if vm.template:
|
|
465
539
|
return None
|
|
466
540
|
else:
|
|
@@ -482,40 +556,64 @@ class GetVmListApplication(BaseVmwareApplication):
|
|
|
482
556
|
if not self._re_os.search(vm.config_version):
|
|
483
557
|
return None
|
|
484
558
|
|
|
559
|
+
dc = "~"
|
|
560
|
+
if vm.dc_name:
|
|
561
|
+
dc = vm.dc_name
|
|
562
|
+
|
|
485
563
|
cdata = {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
564
|
+
"vsphere": vsphere_name,
|
|
565
|
+
"dc": dc,
|
|
566
|
+
"cluster": vm.cluster_name,
|
|
567
|
+
"name": vm.name,
|
|
568
|
+
"path": vm.path,
|
|
569
|
+
"type": "Virtual Machine",
|
|
570
|
+
"online": vm.online,
|
|
571
|
+
"onl_str": "Online",
|
|
572
|
+
"cfg_ver": vm.config_version,
|
|
573
|
+
"os": vm.guest_id,
|
|
495
574
|
}
|
|
496
575
|
|
|
497
|
-
if cdata[
|
|
498
|
-
cdata[
|
|
576
|
+
if cdata["path"]:
|
|
577
|
+
cdata["path"] = "/" + cdata["path"]
|
|
499
578
|
else:
|
|
500
|
-
cdata[
|
|
579
|
+
cdata["path"] = "/"
|
|
501
580
|
|
|
502
|
-
if not cdata[
|
|
503
|
-
cdata[
|
|
581
|
+
if not cdata["cluster"]:
|
|
582
|
+
cdata["cluster"] = None
|
|
504
583
|
|
|
505
|
-
if not cdata[
|
|
506
|
-
cdata[
|
|
584
|
+
if not cdata["os"]:
|
|
585
|
+
cdata["os"] = None
|
|
507
586
|
|
|
508
587
|
if not vm.online:
|
|
509
|
-
cdata[
|
|
588
|
+
cdata["onl_str"] = "Offline"
|
|
510
589
|
|
|
511
590
|
if vm.template:
|
|
512
|
-
cdata[
|
|
591
|
+
cdata["type"] = "VMware Template"
|
|
513
592
|
|
|
514
593
|
return cdata
|
|
515
594
|
|
|
516
595
|
|
|
517
596
|
# =============================================================================
|
|
518
|
-
|
|
597
|
+
def main():
|
|
598
|
+
"""Entrypoint for get-vsphere-vm-list."""
|
|
599
|
+
my_path = pathlib.Path(__file__)
|
|
600
|
+
appname = my_path.name
|
|
601
|
+
|
|
602
|
+
locale.setlocale(locale.LC_ALL, "")
|
|
603
|
+
|
|
604
|
+
app = GetVmListApplication(appname=appname)
|
|
605
|
+
app.initialized = True
|
|
606
|
+
|
|
607
|
+
if app.verbose > 2:
|
|
608
|
+
print(_("{c}-Object:\n{a}").format(c=app.__class__.__name__, a=app), file=sys.stderr)
|
|
609
|
+
|
|
610
|
+
app()
|
|
611
|
+
|
|
612
|
+
sys.exit(0)
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
# =============================================================================
|
|
616
|
+
if __name__ == "__main__":
|
|
519
617
|
|
|
520
618
|
pass
|
|
521
619
|
|