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.
Files changed (48) hide show
  1. fb_vmware/__init__.py +3 -3
  2. fb_vmware/about.py +70 -59
  3. fb_vmware/app/__init__.py +104 -39
  4. fb_vmware/app/get_host_list.py +164 -97
  5. fb_vmware/app/get_network_list.py +200 -127
  6. fb_vmware/app/get_storage_cluster_list.py +139 -79
  7. fb_vmware/app/get_storage_list.py +453 -0
  8. fb_vmware/app/get_vm_info.py +115 -58
  9. fb_vmware/app/get_vm_list.py +226 -128
  10. fb_vmware/base.py +85 -57
  11. fb_vmware/cluster.py +165 -79
  12. fb_vmware/config/__init__.py +161 -115
  13. fb_vmware/connect.py +870 -405
  14. fb_vmware/controller.py +146 -106
  15. fb_vmware/datastore.py +255 -111
  16. fb_vmware/dc.py +95 -59
  17. fb_vmware/disk.py +145 -98
  18. fb_vmware/ds_cluster.py +160 -57
  19. fb_vmware/dvs.py +275 -160
  20. fb_vmware/errors.py +48 -40
  21. fb_vmware/ether.py +196 -141
  22. fb_vmware/host.py +274 -164
  23. fb_vmware/host_port_group.py +115 -68
  24. fb_vmware/iface.py +35 -24
  25. fb_vmware/network.py +165 -77
  26. fb_vmware/obj.py +72 -58
  27. fb_vmware/typed_dict.py +25 -26
  28. fb_vmware/vm.py +266 -164
  29. fb_vmware/xlate.py +24 -27
  30. fb_vmware-1.7.0.data/data/.gitkeep +0 -0
  31. fb_vmware-1.7.0.data/data/share/locale/de_DE/LC_MESSAGES/fb_vmware.mo +0 -0
  32. fb_vmware-1.7.0.data/data/share/locale/en_US/LC_MESSAGES/fb_vmware.mo +0 -0
  33. fb_vmware-1.7.0.dist-info/METADATA +54 -0
  34. fb_vmware-1.7.0.dist-info/RECORD +37 -0
  35. {fb_vmware-1.5.3.dist-info → fb_vmware-1.7.0.dist-info}/WHEEL +1 -2
  36. fb_vmware-1.7.0.dist-info/entry_points.txt +8 -0
  37. fb_vmware/local_version.py +0 -17
  38. fb_vmware-1.5.3.data/data/share/locale/de_DE/LC_MESSAGES/fb_vmware.mo +0 -0
  39. fb_vmware-1.5.3.data/data/share/locale/en_US/LC_MESSAGES/fb_vmware.mo +0 -0
  40. fb_vmware-1.5.3.data/scripts/get-vsphere-host-list +0 -71
  41. fb_vmware-1.5.3.data/scripts/get-vsphere-network-list +0 -71
  42. fb_vmware-1.5.3.data/scripts/get-vsphere-storage-cluster-list +0 -71
  43. fb_vmware-1.5.3.data/scripts/get-vsphere-vm-info +0 -71
  44. fb_vmware-1.5.3.data/scripts/get-vsphere-vm-list +0 -71
  45. fb_vmware-1.5.3.dist-info/METADATA +0 -51
  46. fb_vmware-1.5.3.dist-info/RECORD +0 -41
  47. fb_vmware-1.5.3.dist-info/top_level.txt +0 -1
  48. {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: The module for the application object of the get-vsphere-host-list application.
4
+ @summary: Print a list of all physical hosts 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 re
15
17
  import sys
16
18
  from operator import itemgetter
@@ -27,7 +29,7 @@ from .. import __version__ as GLOBAL_VERSION
27
29
  from ..errors import VSphereExpectedError
28
30
  from ..xlate import XLATOR
29
31
 
30
- __version__ = '1.2.0'
32
+ __version__ = "1.4.0"
31
33
  LOG = logging.getLogger(__name__)
32
34
 
33
35
  _ = XLATOR.gettext
@@ -45,19 +47,28 @@ class GetVmHostsAppError(VmwareAppError):
45
47
  class GetHostsListApplication(BaseVmwareApplication):
46
48
  """Class for the application object."""
47
49
 
48
- default_host_pattern = r'.*'
49
- avail_sort_keys = ('name', 'vsphere', 'cluster', 'vendor', 'model', 'os_version')
50
- default_sort_keys = ['name', 'vsphere']
50
+ default_host_pattern = r".*"
51
+ avail_sort_keys = ("name", "vsphere", "cluster", "vendor", "model", "os_version")
52
+ default_sort_keys = ["name", "vsphere"]
51
53
 
52
54
  # -------------------------------------------------------------------------
53
55
  def __init__(
54
- self, appname=None, verbose=0, version=GLOBAL_VERSION, base_dir=None,
55
- initialized=False, usage=None, description=None,
56
- argparse_epilog=None, argparse_prefix_chars='-', env_prefix=None):
56
+ self,
57
+ appname=None,
58
+ verbose=0,
59
+ version=GLOBAL_VERSION,
60
+ base_dir=None,
61
+ initialized=False,
62
+ usage=None,
63
+ description=None,
64
+ argparse_epilog=None,
65
+ argparse_prefix_chars="-",
66
+ env_prefix=None,
67
+ ):
57
68
  """Initialize a GetHostsListApplication object."""
58
69
  desc = _(
59
- 'Tries to get a list of all physical hosts in '
60
- 'VMWare VSphere and print it out.')
70
+ "Tries to get a list of all physical hosts in " "VMware vSphere and print it out."
71
+ )
61
72
 
62
73
  self._host_pattern = self.default_host_pattern
63
74
  self.sort_keys = self.default_sort_keys
@@ -65,8 +76,12 @@ class GetHostsListApplication(BaseVmwareApplication):
65
76
  self.hosts = []
66
77
 
67
78
  super(GetHostsListApplication, self).__init__(
68
- appname=appname, verbose=verbose, version=version, base_dir=base_dir,
69
- description=desc, initialized=False,
79
+ appname=appname,
80
+ verbose=verbose,
81
+ version=version,
82
+ base_dir=base_dir,
83
+ description=desc,
84
+ initialized=False,
70
85
  )
71
86
 
72
87
  self.initialized = True
@@ -89,8 +104,8 @@ class GetHostsListApplication(BaseVmwareApplication):
89
104
  @rtype: dict
90
105
  """
91
106
  res = super(GetHostsListApplication, self).as_dict(short=short)
92
- res['host_pattern'] = self.host_pattern
93
- res['default_host_pattern'] = self.default_host_pattern
107
+ res["host_pattern"] = self.host_pattern
108
+ res["default_host_pattern"] = self.default_host_pattern
94
109
 
95
110
  return res
96
111
 
@@ -99,36 +114,55 @@ class GetHostsListApplication(BaseVmwareApplication):
99
114
  """Public available method to initiate the argument parser."""
100
115
  super(GetHostsListApplication, self).init_arg_parser()
101
116
 
102
- filter_group = self.arg_parser.add_argument_group(_('Filter options'))
117
+ filter_group = self.arg_parser.add_argument_group(_("Filter options"))
103
118
 
104
119
  filter_group.add_argument(
105
- '-p', '--pattern', '--search-pattern',
106
- dest='host_pattern', metavar='REGEX', action=RegexOptionAction,
107
- topic=_('for names of hosts'), re_options=re.IGNORECASE,
120
+ "-p",
121
+ "--pattern",
122
+ "--search-pattern",
123
+ dest="host_pattern",
124
+ metavar="REGEX",
125
+ action=RegexOptionAction,
126
+ topic=_("for names of hosts"),
127
+ re_options=re.IGNORECASE,
108
128
  help=_(
109
- 'A regular expression to filter the output list of hosts by their name '
110
- '(Default: {!r}).').format(self.default_host_pattern)
129
+ "A regular expression to filter the output list of hosts by their name "
130
+ "(Default: {!r})."
131
+ ).format(self.default_host_pattern),
111
132
  )
112
133
 
113
134
  online_filter = filter_group.add_mutually_exclusive_group()
114
135
  online_filter.add_argument(
115
- '--on', '--online', action='store_true', dest='online',
116
- help=_('Filter output for online hosts.')
136
+ "--on",
137
+ "--online",
138
+ action="store_true",
139
+ dest="online",
140
+ help=_("Filter output for online hosts."),
117
141
  )
118
142
  online_filter.add_argument(
119
- '--off', '--offline', action='store_true', dest='offline',
120
- help=_('Filter output for offline hosts and templates.')
143
+ "--off",
144
+ "--offline",
145
+ action="store_true",
146
+ dest="offline",
147
+ help=_("Filter output for offline hosts and templates."),
121
148
  )
122
149
 
123
- output_options = self.arg_parser.add_argument_group(_('Output options'))
150
+ output_options = self.arg_parser.add_argument_group(_("Output options"))
124
151
 
125
152
  output_options.add_argument(
126
- '-S', '--sort', metavar='KEY', nargs='+', dest='sort_keys',
127
- choices=self.avail_sort_keys, help=_(
128
- 'The keys for sorting the output. Available keys are: {avail}. '
129
- 'The default sorting keys are: {default}.').format(
153
+ "-S",
154
+ "--sort",
155
+ metavar="KEY",
156
+ nargs="+",
157
+ dest="sort_keys",
158
+ choices=self.avail_sort_keys,
159
+ help=_(
160
+ "The keys for sorting the output. Available keys are: {avail}. "
161
+ "The default sorting keys are: {default}."
162
+ ).format(
130
163
  avail=format_list(self.avail_sort_keys, do_repr=True),
131
- default=format_list(self.default_sort_keys, do_repr=True))
164
+ default=format_list(self.default_sort_keys, do_repr=True),
165
+ ),
132
166
  )
133
167
 
134
168
  # -------------------------------------------------------------------------
@@ -139,11 +173,12 @@ class GetHostsListApplication(BaseVmwareApplication):
139
173
  if self.args.host_pattern:
140
174
  try:
141
175
  re_name = re.compile(self.args.host_pattern, re.IGNORECASE)
142
- LOG.debug(_('Regular expression for filtering: {!r}').format(re_name.pattern))
176
+ LOG.debug(_("Regular expression for filtering: {!r}").format(re_name.pattern))
143
177
  self._host_pattern = self.args.host_pattern
144
178
  except Exception as e:
145
- msg = _('Got a {c} for pattern {p!r}: {e}').format(
146
- c=e.__class__.__name__, p=self.args.host_pattern, e=e)
179
+ msg = _("Got a {c} for pattern {p!r}: {e}").format(
180
+ c=e.__class__.__name__, p=self.args.host_pattern, e=e
181
+ )
147
182
  LOG.error(msg)
148
183
 
149
184
  if self.args.sort_keys:
@@ -152,8 +187,7 @@ class GetHostsListApplication(BaseVmwareApplication):
152
187
  # -------------------------------------------------------------------------
153
188
  def _run(self):
154
189
 
155
- LOG.debug(_('Starting {a!r}, version {v!r} ...').format(
156
- a=self.appname, v=self.version))
190
+ LOG.debug(_("Starting {a!r}, version {v!r} ...").format(a=self.appname, v=self.version))
157
191
 
158
192
  ret = 0
159
193
  try:
@@ -168,7 +202,7 @@ class GetHostsListApplication(BaseVmwareApplication):
168
202
 
169
203
  # -------------------------------------------------------------------------
170
204
  def get_all_hosts(self):
171
- """Collect all physical VMWare hosts."""
205
+ """Collect all physical VMware hosts."""
172
206
  ret = 0
173
207
  all_hosts = []
174
208
 
@@ -176,13 +210,13 @@ class GetHostsListApplication(BaseVmwareApplication):
176
210
  for vsphere_name in self.vsphere:
177
211
  all_hosts += self.get_hosts(vsphere_name)
178
212
  elif not self.quiet:
179
- spin_prompt = _('Getting all VSPhere hosts ...') + ' '
213
+ spin_prompt = _("Getting all vSphere hosts ...") + " "
180
214
  spinner_name = self.get_random_spinner_name()
181
215
  with Spinner(spin_prompt, spinner_name):
182
216
  for vsphere_name in self.vsphere:
183
217
  all_hosts += self.get_hosts(vsphere_name)
184
- sys.stdout.write(' ' * len(spin_prompt))
185
- sys.stdout.write('\r')
218
+ sys.stdout.write(" " * len(spin_prompt))
219
+ sys.stdout.write("\r")
186
220
  sys.stdout.flush()
187
221
 
188
222
  first = True
@@ -190,7 +224,7 @@ class GetHostsListApplication(BaseVmwareApplication):
190
224
 
191
225
  for host in all_hosts:
192
226
  if self.verbose > 1 and first:
193
- LOG.debug(_('First found host:') + '\n' + pp(host.as_dict()))
227
+ LOG.debug(_("First found host:") + "\n" + pp(host.as_dict()))
194
228
  first = False
195
229
  is_online = True
196
230
  if not host.connection_state or host.maintenance:
@@ -205,7 +239,7 @@ class GetHostsListApplication(BaseVmwareApplication):
205
239
  continue
206
240
  out_hosts.append(self.create_host_summary(host))
207
241
  if self.verbose > 1:
208
- LOG.debug('All hosts:\n{}'.format(pp(out_hosts)))
242
+ LOG.debug("All hosts:\n{}".format(pp(out_hosts)))
209
243
 
210
244
  self.print_hosts(out_hosts)
211
245
 
@@ -216,27 +250,28 @@ class GetHostsListApplication(BaseVmwareApplication):
216
250
  """Return a dict with host properties as a summary for the given host."""
217
251
  summary = {}
218
252
 
219
- summary['vsphere'] = host.vsphere
220
- summary['cluster'] = host.cluster_name
221
- summary['name'] = host.name
222
- summary['connection_state'] = host.connection_state
223
- cpu_cores = '-'
253
+ summary["vsphere"] = host.vsphere
254
+ summary["dc"] = host.dc_name
255
+ summary["cluster"] = host.cluster_name
256
+ summary["name"] = host.name
257
+ summary["connection_state"] = host.connection_state
258
+ cpu_cores = "-"
224
259
  if host.cpu_cores:
225
260
  cpu_cores = host.cpu_cores
226
- cpu_threads = '-'
261
+ cpu_threads = "-"
227
262
  if host.cpu_threads:
228
263
  cpu_threads = host.cpu_threads
229
- summary['cpus'] = '{co}/{thr}'.format(co=cpu_cores, thr=cpu_threads)
230
- summary['memory_gb'] = host.memory_gb
231
- summary['vendor'] = host.vendor
232
- summary['model'] = host.model
233
- summary['maintenance'] = host.maintenance
234
- summary['online'] = host.online
235
- summary['no_portgroups'] = str(len(host.portgroups))
236
- summary['power_state'] = host.power_state
237
- summary['os_name'] = host.product.name
238
- summary['os_version'] = host.product.os_version
239
- summary['quarantaine'] = host.quarantaine
264
+ summary["cpus"] = "{co}/{thr}".format(co=cpu_cores, thr=cpu_threads)
265
+ summary["memory_gb"] = host.memory_gb
266
+ summary["vendor"] = host.vendor
267
+ summary["model"] = host.model
268
+ summary["maintenance"] = host.maintenance
269
+ summary["online"] = host.online
270
+ summary["no_portgroups"] = str(len(host.portgroups))
271
+ summary["power_state"] = host.power_state
272
+ summary["os_name"] = host.product.name
273
+ summary["os_version"] = host.product.os_version
274
+ summary["quarantaine"] = host.quarantaine
240
275
 
241
276
  return summary
242
277
 
@@ -244,27 +279,40 @@ class GetHostsListApplication(BaseVmwareApplication):
244
279
  def print_hosts(self, hosts):
245
280
  """Print on STDOUT all information about all hosts in a human readable format."""
246
281
  labels = {
247
- 'vsphere': 'VSPhere',
248
- 'cluster': 'Cluster',
249
- 'name': 'Host',
250
- 'connection_state': _('Connect state'),
251
- 'cpus': _('CPU cores/threads'),
252
- 'memory_gb': _('Memory in GiB'),
253
- 'vendor': _('Vendor'),
254
- 'model': _('Model'),
255
- 'maintenance': _('Maintenance'),
256
- 'online': _('Online'),
282
+ "vsphere": "vSphere",
283
+ "dc": "DC",
284
+ "cluster": "Cluster",
285
+ "name": "Host",
286
+ "connection_state": _("Connect state"),
287
+ "cpus": _("CPU cores/threads"),
288
+ "memory_gb": _("Memory in GiB"),
289
+ "vendor": _("Vendor"),
290
+ "model": _("Model"),
291
+ "maintenance": _("Maintenance"),
292
+ "online": _("Online"),
257
293
  # 'no_portgroups': _('Portgroups'),
258
- 'power_state': _('Power State'),
259
- 'os_name': _('OS Name'),
260
- 'os_version': _('OS Version'),
294
+ "power_state": _("Power State"),
295
+ "os_name": _("OS Name"),
296
+ "os_version": _("OS Version"),
261
297
  # 'quarantaine': _('Quarantaine'),
262
298
  }
263
299
 
264
300
  label_list = (
265
- 'name', 'vsphere', 'cluster', 'vendor', 'model', 'os_name', 'os_version', 'cpus',
266
- 'memory_gb', 'power_state', 'connection_state', 'online',
267
- 'maintenance')
301
+ "name",
302
+ "dc",
303
+ "vsphere",
304
+ "cluster",
305
+ "vendor",
306
+ "model",
307
+ "os_name",
308
+ "os_version",
309
+ "cpus",
310
+ "memory_gb",
311
+ "power_state",
312
+ "connection_state",
313
+ "online",
314
+ "maintenance",
315
+ )
268
316
 
269
317
  str_lengths = {}
270
318
  for label in labels:
@@ -276,17 +324,17 @@ class GetHostsListApplication(BaseVmwareApplication):
276
324
  for label in labels.keys():
277
325
  val = host[label]
278
326
  if val is None:
279
- val = '-'
327
+ val = "-"
280
328
  host[label] = val
281
329
  else:
282
- if label == 'memory_gb':
283
- val = '{:7.1f}'.format(val)
330
+ if label == "memory_gb":
331
+ val = "{:7.1f}".format(val)
284
332
  host[label] = val
285
- elif label in ('connection_state', 'maintenance', 'online', 'quarantaine'):
333
+ elif label in ("connection_state", "maintenance", "online", "quarantaine"):
286
334
  if val:
287
- val = _('Yes')
335
+ val = _("Yes")
288
336
  else:
289
- val = _('No')
337
+ val = _("No")
290
338
  host[label] = val
291
339
  if len(val) > str_lengths[label]:
292
340
  str_lengths[label] = len(val)
@@ -297,24 +345,24 @@ class GetHostsListApplication(BaseVmwareApplication):
297
345
  max_len += str_lengths[label]
298
346
 
299
347
  if self.verbose > 1:
300
- LOG.debug('Label length:\n' + pp(str_lengths))
301
- LOG.debug('Max line length: {} chars'.format(max_len))
348
+ LOG.debug("Label length:\n" + pp(str_lengths))
349
+ LOG.debug("Max line length: {} chars".format(max_len))
302
350
 
303
- tpl = ''
351
+ tpl = ""
304
352
  for label in label_list:
305
- if tpl != '':
306
- tpl += ' '
307
- if label in ('memory_gb', 'cpus', 'no_portgroups'):
308
- tpl += '{{{la}:>{le}}}'.format(la=label, le=str_lengths[label])
353
+ if tpl != "":
354
+ tpl += " "
355
+ if label in ("memory_gb", "cpus", "no_portgroups"):
356
+ tpl += "{{{la}:>{le}}}".format(la=label, le=str_lengths[label])
309
357
  else:
310
- tpl += '{{{la}:<{le}}}'.format(la=label, le=str_lengths[label])
358
+ tpl += "{{{la}:<{le}}}".format(la=label, le=str_lengths[label])
311
359
  if self.verbose > 1:
312
- LOG.debug(_('Line template: {}').format(tpl))
360
+ LOG.debug(_("Line template: {}").format(tpl))
313
361
 
314
362
  if not self.quiet:
315
363
  print()
316
364
  print(tpl.format(**labels))
317
- print('-' * max_len)
365
+ print("-" * max_len)
318
366
 
319
367
  hosts.sort(key=itemgetter(*self.sort_keys))
320
368
 
@@ -325,21 +373,21 @@ class GetHostsListApplication(BaseVmwareApplication):
325
373
  if not self.quiet:
326
374
  print()
327
375
  if count == 0:
328
- msg = _('Found no VMWare hosts.')
376
+ msg = _("Found no VMware hosts.")
329
377
  else:
330
- msg = ngettext(
331
- 'Found one VMWare host.',
332
- 'Found {} VMWare hosts.', count).format(count)
378
+ msg = ngettext("Found one VMware host.", "Found {} VMware hosts.", count).format(
379
+ count
380
+ )
333
381
  print(msg)
334
382
  print()
335
383
 
336
384
  # -------------------------------------------------------------------------
337
385
  def get_hosts(self, vsphere_name):
338
- """Get all host of all physical hosts in a VMWare VSPhere."""
386
+ """Get all host of all physical hosts in a VMware vSphere."""
339
387
  hosts = []
340
388
 
341
389
  vsphere = self.vsphere[vsphere_name]
342
- vsphere.get_datacenter()
390
+ # vsphere.get_datacenter()
343
391
 
344
392
  re_name = None
345
393
  if self.host_pattern is not None:
@@ -355,7 +403,26 @@ class GetHostsListApplication(BaseVmwareApplication):
355
403
 
356
404
 
357
405
  # =============================================================================
358
- if __name__ == '__main__':
406
+ def main():
407
+ """Entrypoint for get-vsphere-host-list."""
408
+ my_path = pathlib.Path(__file__)
409
+ appname = my_path.name
410
+
411
+ locale.setlocale(locale.LC_ALL, "")
412
+
413
+ app = GetHostsListApplication(appname=appname)
414
+ app.initialized = True
415
+
416
+ if app.verbose > 2:
417
+ print(_("{c}-Object:\n{a}").format(c=app.__class__.__name__, a=app), file=sys.stderr)
418
+
419
+ app()
420
+
421
+ sys.exit(0)
422
+
423
+
424
+ # =============================================================================
425
+ if __name__ == "__main__":
359
426
 
360
427
  pass
361
428