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/__init__.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
"""
|
|
4
|
-
@summary: The module for a base
|
|
4
|
+
@summary: The module for a base vSphere handler object.
|
|
5
5
|
|
|
6
6
|
@author: Frank Brehm
|
|
7
7
|
@contact: frank@brehm-online.com
|
|
@@ -56,7 +56,7 @@ from .vm import VsphereVmList
|
|
|
56
56
|
from .xlate import XLATOR
|
|
57
57
|
|
|
58
58
|
|
|
59
|
-
__version__ =
|
|
59
|
+
__version__ = "1.7.0"
|
|
60
60
|
|
|
61
61
|
LOG = logging.getLogger(__name__)
|
|
62
62
|
|
|
@@ -65,7 +65,7 @@ _ = XLATOR.gettext
|
|
|
65
65
|
|
|
66
66
|
# =============================================================================
|
|
67
67
|
|
|
68
|
-
if __name__ ==
|
|
68
|
+
if __name__ == "__main__":
|
|
69
69
|
|
|
70
70
|
pass
|
|
71
71
|
|
fb_vmware/about.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
"""
|
|
4
|
-
@summary: The module for capsulating a
|
|
4
|
+
@summary: The module for capsulating a vSphere about info object.
|
|
5
5
|
|
|
6
6
|
@author: Frank Brehm
|
|
7
7
|
@contact: frank@brehm-online.com
|
|
@@ -24,7 +24,7 @@ from pyVmomi import vim
|
|
|
24
24
|
# Own modules
|
|
25
25
|
from .xlate import XLATOR
|
|
26
26
|
|
|
27
|
-
__version__ =
|
|
27
|
+
__version__ = "1.0.1"
|
|
28
28
|
LOG = logging.getLogger(__name__)
|
|
29
29
|
|
|
30
30
|
_ = XLATOR.gettext
|
|
@@ -32,11 +32,12 @@ _ = XLATOR.gettext
|
|
|
32
32
|
|
|
33
33
|
# =============================================================================
|
|
34
34
|
class VsphereAboutInfo(FbBaseObject):
|
|
35
|
-
"""This is a wrapper for the about-information of a
|
|
35
|
+
"""This is a wrapper for the about-information of a VMware vSphere center."""
|
|
36
36
|
|
|
37
37
|
# -------------------------------------------------------------------------
|
|
38
38
|
def __init__(
|
|
39
|
-
|
|
39
|
+
self, appname=None, verbose=0, version=__version__, base_dir=None, initialized=None
|
|
40
|
+
):
|
|
40
41
|
"""Initialize the VsphereAboutInfo object."""
|
|
41
42
|
self._api_type = None
|
|
42
43
|
self._api_version = None
|
|
@@ -50,7 +51,8 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
50
51
|
self._lic_prodversion = None
|
|
51
52
|
|
|
52
53
|
super(VsphereAboutInfo, self).__init__(
|
|
53
|
-
appname=appname, verbose=verbose, version=version, base_dir=base_dir
|
|
54
|
+
appname=appname, verbose=verbose, version=version, base_dir=base_dir
|
|
55
|
+
)
|
|
54
56
|
|
|
55
57
|
if initialized is not None:
|
|
56
58
|
self.initialized = initialized
|
|
@@ -68,7 +70,7 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
68
70
|
self._api_type = None
|
|
69
71
|
return
|
|
70
72
|
v = str(value).strip()
|
|
71
|
-
if v ==
|
|
73
|
+
if v == "":
|
|
72
74
|
self._api_type = None
|
|
73
75
|
else:
|
|
74
76
|
self._api_type = v
|
|
@@ -86,7 +88,7 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
86
88
|
self._api_version = None
|
|
87
89
|
return
|
|
88
90
|
v = str(value).strip()
|
|
89
|
-
if v ==
|
|
91
|
+
if v == "":
|
|
90
92
|
self._api_version = None
|
|
91
93
|
else:
|
|
92
94
|
self._api_version = v
|
|
@@ -104,7 +106,7 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
104
106
|
self._name = None
|
|
105
107
|
return
|
|
106
108
|
v = str(value).strip()
|
|
107
|
-
if v ==
|
|
109
|
+
if v == "":
|
|
108
110
|
self._name = None
|
|
109
111
|
else:
|
|
110
112
|
self._name = v
|
|
@@ -122,7 +124,7 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
122
124
|
self._full_name = None
|
|
123
125
|
return
|
|
124
126
|
v = str(value).strip()
|
|
125
|
-
if v ==
|
|
127
|
+
if v == "":
|
|
126
128
|
self._full_name = None
|
|
127
129
|
else:
|
|
128
130
|
self._full_name = v
|
|
@@ -140,7 +142,7 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
140
142
|
self._vendor = None
|
|
141
143
|
return
|
|
142
144
|
v = str(value).strip()
|
|
143
|
-
if v ==
|
|
145
|
+
if v == "":
|
|
144
146
|
self._vendor = None
|
|
145
147
|
else:
|
|
146
148
|
self._vendor = v
|
|
@@ -158,7 +160,7 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
158
160
|
self._os_version = None
|
|
159
161
|
return
|
|
160
162
|
v = str(value).strip()
|
|
161
|
-
if v ==
|
|
163
|
+
if v == "":
|
|
162
164
|
self._os_version = None
|
|
163
165
|
else:
|
|
164
166
|
self._os_version = v
|
|
@@ -176,7 +178,7 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
176
178
|
self._os_type = None
|
|
177
179
|
return
|
|
178
180
|
v = str(value).strip()
|
|
179
|
-
if v ==
|
|
181
|
+
if v == "":
|
|
180
182
|
self._os_type = None
|
|
181
183
|
else:
|
|
182
184
|
self._os_type = v
|
|
@@ -194,7 +196,7 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
194
196
|
self._instance_uuid = None
|
|
195
197
|
return
|
|
196
198
|
v = str(value).strip()
|
|
197
|
-
if v ==
|
|
199
|
+
if v == "":
|
|
198
200
|
self._instance_uuid = None
|
|
199
201
|
else:
|
|
200
202
|
try:
|
|
@@ -216,7 +218,7 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
216
218
|
self._lic_prodname = None
|
|
217
219
|
return
|
|
218
220
|
v = str(value).strip()
|
|
219
|
-
if v ==
|
|
221
|
+
if v == "":
|
|
220
222
|
self._lic_prodname = None
|
|
221
223
|
else:
|
|
222
224
|
self._lic_prodname = v
|
|
@@ -234,7 +236,7 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
234
236
|
self._lic_prodversion = None
|
|
235
237
|
return
|
|
236
238
|
v = str(value).strip()
|
|
237
|
-
if v ==
|
|
239
|
+
if v == "":
|
|
238
240
|
self._lic_prodversion = None
|
|
239
241
|
else:
|
|
240
242
|
self._lic_prodversion = v
|
|
@@ -251,16 +253,16 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
251
253
|
@rtype: dict
|
|
252
254
|
"""
|
|
253
255
|
res = super(VsphereAboutInfo, self).as_dict(short=short)
|
|
254
|
-
res[
|
|
255
|
-
res[
|
|
256
|
-
res[
|
|
257
|
-
res[
|
|
258
|
-
res[
|
|
259
|
-
res[
|
|
260
|
-
res[
|
|
261
|
-
res[
|
|
262
|
-
res[
|
|
263
|
-
res[
|
|
256
|
+
res["api_type"] = self.api_type
|
|
257
|
+
res["api_version"] = self.api_version
|
|
258
|
+
res["name"] = self.name
|
|
259
|
+
res["full_name"] = self.full_name
|
|
260
|
+
res["vendor"] = self.vendor
|
|
261
|
+
res["os_version"] = self.os_version
|
|
262
|
+
res["os_type"] = self.os_type
|
|
263
|
+
res["instance_uuid"] = self.instance_uuid
|
|
264
|
+
res["lic_prodname"] = self.lic_prodname
|
|
265
|
+
res["lic_prodversion"] = self.lic_prodversion
|
|
264
266
|
|
|
265
267
|
return res
|
|
266
268
|
|
|
@@ -271,8 +273,17 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
271
273
|
if test_mode:
|
|
272
274
|
|
|
273
275
|
necessary_fields = (
|
|
274
|
-
|
|
275
|
-
|
|
276
|
+
"apiType",
|
|
277
|
+
"apiVersion",
|
|
278
|
+
"name",
|
|
279
|
+
"fullName",
|
|
280
|
+
"vendor",
|
|
281
|
+
"version",
|
|
282
|
+
"osType",
|
|
283
|
+
"instanceUuid",
|
|
284
|
+
"licenseProductName",
|
|
285
|
+
"licenseProductVersion",
|
|
286
|
+
)
|
|
276
287
|
failing_fields = []
|
|
277
288
|
|
|
278
289
|
for field in necessary_fields:
|
|
@@ -281,47 +292,47 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
281
292
|
|
|
282
293
|
if len(failing_fields):
|
|
283
294
|
msg = _(
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
msg +=
|
|
295
|
+
"The given parameter {p!r} on calling method {m}() has failing " "attributes"
|
|
296
|
+
).format(p="data", m="from_summary")
|
|
297
|
+
msg += ": " + format_list(failing_fields, do_repr=True)
|
|
287
298
|
raise AssertionError(msg)
|
|
288
299
|
|
|
289
300
|
else:
|
|
290
301
|
if not isinstance(data, vim.AboutInfo):
|
|
291
302
|
msg = _(
|
|
292
|
-
|
|
293
|
-
|
|
303
|
+
"Parameter {t!r} must be a {e} object, a {v} object was given " "instead."
|
|
304
|
+
).format(t="data", e="vim.AboutInfo", v=data.__class__.__qualname__)
|
|
294
305
|
raise TypeError(msg)
|
|
295
306
|
|
|
296
307
|
params = {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
308
|
+
"appname": appname,
|
|
309
|
+
"verbose": verbose,
|
|
310
|
+
"base_dir": base_dir,
|
|
311
|
+
"initialized": False,
|
|
301
312
|
}
|
|
302
313
|
|
|
303
314
|
if verbose > 2:
|
|
304
|
-
LOG.debug(_(
|
|
315
|
+
LOG.debug(_("Creating {} object from:").format(cls.__name__) + "\n" + pp(params))
|
|
305
316
|
info = cls(**params)
|
|
306
317
|
|
|
307
|
-
# 'about': (vim.AboutInfo) {
|
|
308
|
-
# dynamicType = <unset>,
|
|
309
|
-
# dynamicProperty = (vmodl.DynamicProperty) [],
|
|
310
|
-
# name = 'VMware vCenter Server',
|
|
311
|
-
# fullName = 'VMware vCenter Server 6.5.0 build-8024368',
|
|
312
|
-
# vendor = 'VMware, Inc.',
|
|
313
|
-
# version = '6.5.0',
|
|
314
|
-
# build = '8024368',
|
|
315
|
-
# localeVersion = 'INTL',
|
|
316
|
-
# localeBuild = '000',
|
|
317
|
-
# osType = 'linux-x64',
|
|
318
|
-
# productLineId = 'vpx',
|
|
319
|
-
# apiType = 'VirtualCenter',
|
|
320
|
-
# apiVersion = '6.5',
|
|
321
|
-
# instanceUuid = 'ea1b28ca-0d17-4292-ab04-189e57ec9629',
|
|
322
|
-
# licenseProductName = 'VMware VirtualCenter Server',
|
|
323
|
-
# licenseProductVersion = '6.0'
|
|
324
|
-
# },
|
|
318
|
+
# 'about': (vim.AboutInfo) {
|
|
319
|
+
# dynamicType = <unset>,
|
|
320
|
+
# dynamicProperty = (vmodl.DynamicProperty) [],
|
|
321
|
+
# name = 'VMware vCenter Server',
|
|
322
|
+
# fullName = 'VMware vCenter Server 6.5.0 build-8024368',
|
|
323
|
+
# vendor = 'VMware, Inc.',
|
|
324
|
+
# version = '6.5.0',
|
|
325
|
+
# build = '8024368',
|
|
326
|
+
# localeVersion = 'INTL',
|
|
327
|
+
# localeBuild = '000',
|
|
328
|
+
# osType = 'linux-x64',
|
|
329
|
+
# productLineId = 'vpx',
|
|
330
|
+
# apiType = 'VirtualCenter',
|
|
331
|
+
# apiVersion = '6.5',
|
|
332
|
+
# instanceUuid = 'ea1b28ca-0d17-4292-ab04-189e57ec9629',
|
|
333
|
+
# licenseProductName = 'VMware VirtualCenter Server',
|
|
334
|
+
# licenseProductVersion = '6.0'
|
|
335
|
+
# },
|
|
325
336
|
|
|
326
337
|
info.api_type = data.apiType
|
|
327
338
|
info.api_version = data.apiVersion
|
|
@@ -337,7 +348,7 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
337
348
|
info.initialized = True
|
|
338
349
|
|
|
339
350
|
if verbose > 2:
|
|
340
|
-
LOG.debug(_(
|
|
351
|
+
LOG.debug(_("Created {} object:").format(cls.__name__) + "\n" + pp(info.as_dict()))
|
|
341
352
|
|
|
342
353
|
return info
|
|
343
354
|
|
|
@@ -345,8 +356,8 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
345
356
|
def __copy__(self):
|
|
346
357
|
"""Return a new VsphereAboutInfo object with data from current object copied in."""
|
|
347
358
|
info = VsphereAboutInfo(
|
|
348
|
-
appname=self.appname, verbose=self.verbose, base_dir=self.base_dir,
|
|
349
|
-
|
|
359
|
+
appname=self.appname, verbose=self.verbose, base_dir=self.base_dir, initialized=False
|
|
360
|
+
)
|
|
350
361
|
|
|
351
362
|
info.api_type = self.api_type
|
|
352
363
|
info.api_version = self.api_version
|
|
@@ -365,7 +376,7 @@ class VsphereAboutInfo(FbBaseObject):
|
|
|
365
376
|
|
|
366
377
|
|
|
367
378
|
# =============================================================================
|
|
368
|
-
if __name__ ==
|
|
379
|
+
if __name__ == "__main__":
|
|
369
380
|
|
|
370
381
|
pass
|
|
371
382
|
|
fb_vmware/app/__init__.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
"""
|
|
4
|
-
@summary: A base module for all
|
|
4
|
+
@summary: A base module for all VMware/vSphere application classes.
|
|
5
5
|
|
|
6
6
|
@author: Frank Brehm
|
|
7
7
|
@contact: frank@brehm-online.com
|
|
@@ -12,6 +12,8 @@ from __future__ import absolute_import, print_function
|
|
|
12
12
|
# Standard modules
|
|
13
13
|
import copy
|
|
14
14
|
import logging
|
|
15
|
+
import os
|
|
16
|
+
import pathlib
|
|
15
17
|
import random
|
|
16
18
|
|
|
17
19
|
# Third party modules
|
|
@@ -28,11 +30,17 @@ from .. import __version__ as GLOBAL_VERSION
|
|
|
28
30
|
from ..config import VmwareConfiguration
|
|
29
31
|
from ..connect import VsphereConnection
|
|
30
32
|
from ..errors import VSphereExpectedError
|
|
33
|
+
from ..xlate import DOMAIN
|
|
34
|
+
from ..xlate import LOCALE_DIR
|
|
31
35
|
from ..xlate import XLATOR
|
|
36
|
+
from ..xlate import __base_dir__ as __xlate_base_dir__
|
|
37
|
+
from ..xlate import __lib_dir__ as __xlate_lib_dir__
|
|
38
|
+
from ..xlate import __mo_file__ as __xlate_mo_file__
|
|
39
|
+
from ..xlate import __module_dir__ as __xlate_module_dir__
|
|
32
40
|
|
|
33
|
-
__version__ =
|
|
41
|
+
__version__ = "1.3.0"
|
|
34
42
|
LOG = logging.getLogger(__name__)
|
|
35
|
-
TZ = pytz.timezone(
|
|
43
|
+
TZ = pytz.timezone("Europe/Berlin")
|
|
36
44
|
|
|
37
45
|
_ = XLATOR.gettext
|
|
38
46
|
ngettext = XLATOR.ngettext
|
|
@@ -40,36 +48,60 @@ ngettext = XLATOR.ngettext
|
|
|
40
48
|
|
|
41
49
|
# =============================================================================
|
|
42
50
|
class VmwareAppError(FbAppError):
|
|
43
|
-
"""Base exception class for all exceptions in all
|
|
51
|
+
"""Base exception class for all exceptions in all VMware/vSphere application classes."""
|
|
44
52
|
|
|
45
53
|
pass
|
|
46
54
|
|
|
47
55
|
|
|
48
56
|
# =============================================================================
|
|
49
57
|
class BaseVmwareApplication(FbConfigApplication):
|
|
50
|
-
"""Base class for all
|
|
58
|
+
"""Base class for all VMware/vSphere application classes."""
|
|
51
59
|
|
|
52
60
|
# -------------------------------------------------------------------------
|
|
53
61
|
def __init__(
|
|
54
|
-
self,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
self,
|
|
63
|
+
appname=None,
|
|
64
|
+
verbose=0,
|
|
65
|
+
version=GLOBAL_VERSION,
|
|
66
|
+
base_dir=None,
|
|
67
|
+
cfg_class=VmwareConfiguration,
|
|
68
|
+
initialized=False,
|
|
69
|
+
usage=None,
|
|
70
|
+
description=None,
|
|
71
|
+
argparse_epilog=None,
|
|
72
|
+
argparse_prefix_chars="-",
|
|
73
|
+
env_prefix=None,
|
|
74
|
+
append_appname_to_stems=True,
|
|
75
|
+
config_dir=None,
|
|
76
|
+
additional_stems=None,
|
|
77
|
+
additional_cfgdirs=None,
|
|
78
|
+
cfg_encoding=DEFAULT_ENCODING,
|
|
79
|
+
use_chardet=True,
|
|
80
|
+
):
|
|
60
81
|
"""Initialize a BaseVmwareApplication object."""
|
|
61
82
|
self.req_vspheres = None
|
|
62
83
|
self.do_vspheres = []
|
|
63
84
|
|
|
64
|
-
|
|
85
|
+
if base_dir is None:
|
|
86
|
+
base_dir = pathlib.Path(os.getcwd()).resolve()
|
|
87
|
+
|
|
88
|
+
# Hash with all vSphere handler objects
|
|
65
89
|
self.vsphere = {}
|
|
66
90
|
|
|
67
91
|
super(BaseVmwareApplication, self).__init__(
|
|
68
|
-
appname=appname,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
92
|
+
appname=appname,
|
|
93
|
+
verbose=verbose,
|
|
94
|
+
version=version,
|
|
95
|
+
base_dir=base_dir,
|
|
96
|
+
description=description,
|
|
97
|
+
cfg_class=cfg_class,
|
|
98
|
+
append_appname_to_stems=append_appname_to_stems,
|
|
99
|
+
config_dir=config_dir,
|
|
100
|
+
additional_stems=additional_stems,
|
|
101
|
+
additional_cfgdirs=additional_cfgdirs,
|
|
102
|
+
cfg_encoding=cfg_encoding,
|
|
103
|
+
use_chardet=use_chardet,
|
|
104
|
+
initialized=False,
|
|
73
105
|
)
|
|
74
106
|
|
|
75
107
|
# -------------------------------------------------------------------------
|
|
@@ -78,6 +110,30 @@ class BaseVmwareApplication(FbConfigApplication):
|
|
|
78
110
|
if self.vsphere.keys():
|
|
79
111
|
self.cleaning_up()
|
|
80
112
|
|
|
113
|
+
# -------------------------------------------------------------------------
|
|
114
|
+
def as_dict(self, short=True):
|
|
115
|
+
"""
|
|
116
|
+
Transform the elements of the object into a dict.
|
|
117
|
+
|
|
118
|
+
@param short: don't include local properties in resulting dict.
|
|
119
|
+
@type short: bool
|
|
120
|
+
|
|
121
|
+
@return: structure as dict
|
|
122
|
+
@rtype: dict
|
|
123
|
+
"""
|
|
124
|
+
res = super(BaseVmwareApplication, self).as_dict(short=short)
|
|
125
|
+
|
|
126
|
+
res["xlate"]["fb_vmware"] = {
|
|
127
|
+
"__module_dir__": __xlate_module_dir__,
|
|
128
|
+
"__lib_dir__": __xlate_lib_dir__,
|
|
129
|
+
"__base_dir__": __xlate_base_dir__,
|
|
130
|
+
"LOCALE_DIR": LOCALE_DIR,
|
|
131
|
+
"DOMAIN": DOMAIN,
|
|
132
|
+
"__mo_file__": __xlate_mo_file__,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return res
|
|
136
|
+
|
|
81
137
|
# -------------------------------------------------------------------------
|
|
82
138
|
def post_init(self):
|
|
83
139
|
"""
|
|
@@ -95,10 +151,10 @@ class BaseVmwareApplication(FbConfigApplication):
|
|
|
95
151
|
super(BaseVmwareApplication, self).post_init()
|
|
96
152
|
|
|
97
153
|
if self.verbose > 2:
|
|
98
|
-
LOG.debug(_(
|
|
154
|
+
LOG.debug(_("{what} of {app} ...").format(what="post_init()", app=self.appname))
|
|
99
155
|
|
|
100
156
|
if not self.cfg.vsphere.keys():
|
|
101
|
-
msg = _(
|
|
157
|
+
msg = _("Did not found any configured vSphere environments.")
|
|
102
158
|
LOG.error(msg)
|
|
103
159
|
self.exit(3)
|
|
104
160
|
|
|
@@ -106,13 +162,13 @@ class BaseVmwareApplication(FbConfigApplication):
|
|
|
106
162
|
self.req_vspheres = []
|
|
107
163
|
all_found = True
|
|
108
164
|
for vs_name in self.args.req_vsphere:
|
|
109
|
-
LOG.debug(_(
|
|
165
|
+
LOG.debug(_("Checking for configured vSphere instance {!r} ...").format(vs_name))
|
|
110
166
|
vs = vs_name.strip().lower()
|
|
111
167
|
if vs not in self.cfg.vsphere.keys():
|
|
112
168
|
all_found = False
|
|
113
169
|
msg = _(
|
|
114
|
-
|
|
115
|
-
|
|
170
|
+
"vSphere {!r} not found in list of configured vSphere instances."
|
|
171
|
+
).format(vs_name)
|
|
116
172
|
LOG.error(msg)
|
|
117
173
|
else:
|
|
118
174
|
if vs not in self.req_vspheres:
|
|
@@ -134,22 +190,24 @@ class BaseVmwareApplication(FbConfigApplication):
|
|
|
134
190
|
super(BaseVmwareApplication, self).init_arg_parser()
|
|
135
191
|
|
|
136
192
|
self.arg_parser.add_argument(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
193
|
+
"--vs",
|
|
194
|
+
"--vsphere",
|
|
195
|
+
dest="req_vsphere",
|
|
196
|
+
nargs="*",
|
|
197
|
+
help=_("The vSphere names from configuration, in which the VMs should be searched."),
|
|
140
198
|
)
|
|
141
199
|
|
|
142
200
|
# -------------------------------------------------------------------------
|
|
143
201
|
def perform_arg_parser(self):
|
|
144
202
|
"""Evaluate the command line parameters. Maybe overridden."""
|
|
145
203
|
if self.verbose > 2:
|
|
146
|
-
LOG.debug(_(
|
|
204
|
+
LOG.debug(_("Got command line arguments:") + "\n" + pp(self.args))
|
|
147
205
|
|
|
148
206
|
# -------------------------------------------------------------------------
|
|
149
207
|
def init_vsphere_handlers(self):
|
|
150
|
-
"""Initialize all
|
|
208
|
+
"""Initialize all vSphere handlers."""
|
|
151
209
|
if self.verbose > 1:
|
|
152
|
-
LOG.debug(_(
|
|
210
|
+
LOG.debug(_("Initializing vSphere handlers ..."))
|
|
153
211
|
|
|
154
212
|
try:
|
|
155
213
|
for vsphere_name in self.do_vspheres:
|
|
@@ -160,36 +218,43 @@ class BaseVmwareApplication(FbConfigApplication):
|
|
|
160
218
|
|
|
161
219
|
# -------------------------------------------------------------------------
|
|
162
220
|
def init_vsphere_handler(self, vsphere_name):
|
|
163
|
-
"""Initialize the given
|
|
221
|
+
"""Initialize the given vSphere handler."""
|
|
164
222
|
if self.verbose > 2:
|
|
165
|
-
LOG.debug(_(
|
|
223
|
+
LOG.debug(_("Initializing handler for vSphere {!r} ...").format(vsphere_name))
|
|
166
224
|
|
|
167
225
|
vsphere_data = self.cfg.vsphere[vsphere_name]
|
|
168
226
|
|
|
169
227
|
vsphere = VsphereConnection(
|
|
170
|
-
vsphere_data,
|
|
171
|
-
|
|
172
|
-
|
|
228
|
+
vsphere_data,
|
|
229
|
+
auto_close=True,
|
|
230
|
+
simulate=self.simulate,
|
|
231
|
+
force=self.force,
|
|
232
|
+
appname=self.appname,
|
|
233
|
+
verbose=self.verbose,
|
|
234
|
+
base_dir=self.base_dir,
|
|
235
|
+
terminal_has_colors=self.terminal_has_colors,
|
|
236
|
+
initialized=False,
|
|
237
|
+
)
|
|
173
238
|
|
|
174
239
|
if vsphere:
|
|
175
240
|
self.vsphere[vsphere_name] = vsphere
|
|
176
241
|
vsphere.initialized = True
|
|
177
242
|
else:
|
|
178
|
-
msg = _(
|
|
179
|
-
msg +=
|
|
243
|
+
msg = _("Could not initialize {} object from:").format("VsphereConnection")
|
|
244
|
+
msg += "\n" + str(vsphere_data)
|
|
180
245
|
LOG.error(msg)
|
|
181
246
|
|
|
182
247
|
vsphere._check_credentials()
|
|
183
248
|
|
|
184
249
|
# -------------------------------------------------------------------------
|
|
185
250
|
def cleaning_up(self):
|
|
186
|
-
"""Close all
|
|
251
|
+
"""Close all vSphere connections and remove all vSphere handlers."""
|
|
187
252
|
if self.verbose > 1:
|
|
188
|
-
LOG.debug(_(
|
|
253
|
+
LOG.debug(_("Cleaning up ..."))
|
|
189
254
|
|
|
190
255
|
for vsphere_name in self.do_vspheres:
|
|
191
256
|
if vsphere_name in self.vsphere:
|
|
192
|
-
LOG.debug(_(
|
|
257
|
+
LOG.debug(_("Closing vSphere object {!r} ...").format(vsphere_name))
|
|
193
258
|
self.vsphere[vsphere_name].disconnect()
|
|
194
259
|
del self.vsphere[vsphere_name]
|
|
195
260
|
|
|
@@ -203,7 +268,7 @@ class BaseVmwareApplication(FbConfigApplication):
|
|
|
203
268
|
|
|
204
269
|
|
|
205
270
|
# =============================================================================
|
|
206
|
-
if __name__ ==
|
|
271
|
+
if __name__ == "__main__":
|
|
207
272
|
|
|
208
273
|
pass
|
|
209
274
|
|