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
- #!/usr/bin/env python
1
+ #!/usr/bin/env python3
2
2
  # -*- coding: utf-8 -*-
3
3
  """
4
- @summary: The module for the application object of the get-vsphere-storage-cluster-list application.
4
+ @summary: Print a list of all storage clusters 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
 
@@ -23,19 +25,20 @@ from fb_tools.spinner import Spinner
23
25
  from fb_tools.xlate import format_list
24
26
 
25
27
  # Own modules
26
- from . import BaseVmwareApplication, VmwareAppError
28
+ from . import BaseVmwareApplication
29
+ from . import VmwareAppError
27
30
  from .. import __version__ as GLOBAL_VERSION
28
- # from ..ds_cluster import VsphereDsCluster
29
31
  from ..ds_cluster import VsphereDsClusterDict
30
32
  from ..errors import VSphereExpectedError
31
33
  from ..xlate import XLATOR
32
34
 
33
- __version__ = '1.1.0'
35
+ __version__ = "1.3.1"
34
36
  LOG = logging.getLogger(__name__)
35
37
 
36
38
  _ = XLATOR.gettext
37
39
  ngettext = XLATOR.ngettext
38
40
 
41
+
39
42
  # =============================================================================
40
43
  class GetVmStorageClustersAppError(VmwareAppError):
41
44
  """Base exception class for all exceptions in this application."""
@@ -48,18 +51,33 @@ class GetStorageClusterListApp(BaseVmwareApplication):
48
51
  """Class for the application object."""
49
52
 
50
53
  avail_sort_keys = (
51
- 'cluster_name', 'vsphere_name', 'capacity', 'free_space', 'usage', 'usage_pc')
52
- default_sort_keys = ['vsphere_name', 'cluster_name']
54
+ "cluster_name",
55
+ "vsphere_name",
56
+ "capacity",
57
+ "free_space",
58
+ "usage",
59
+ "usage_pc",
60
+ )
61
+ default_sort_keys = ["vsphere_name", "cluster_name"]
53
62
 
54
63
  # -------------------------------------------------------------------------
55
64
  def __init__(
56
- self, appname=None, verbose=0, version=GLOBAL_VERSION, base_dir=None,
57
- initialized=False, usage=None, description=None,
58
- argparse_epilog=None, argparse_prefix_chars='-', env_prefix=None):
65
+ self,
66
+ appname=None,
67
+ verbose=0,
68
+ version=GLOBAL_VERSION,
69
+ base_dir=None,
70
+ initialized=False,
71
+ usage=None,
72
+ description=None,
73
+ argparse_epilog=None,
74
+ argparse_prefix_chars="-",
75
+ env_prefix=None,
76
+ ):
59
77
  """Initialize a GetStorageClusterListApp object."""
60
78
  desc = _(
61
- 'Tries to get a list of all datastore clusters in '
62
- 'VMWare VSphere and print it out.')
79
+ "Tries to get a list of all datastore clusters in " "VMware vSphere and print it out."
80
+ )
63
81
 
64
82
  self.st_clusters = []
65
83
  self._print_total = True
@@ -67,8 +85,12 @@ class GetStorageClusterListApp(BaseVmwareApplication):
67
85
  self.sort_keys = self.default_sort_keys
68
86
 
69
87
  super(GetStorageClusterListApp, self).__init__(
70
- appname=appname, verbose=verbose, version=version, base_dir=base_dir,
71
- description=desc, initialized=False,
88
+ appname=appname,
89
+ verbose=verbose,
90
+ version=version,
91
+ base_dir=base_dir,
92
+ description=desc,
93
+ initialized=False,
72
94
  )
73
95
 
74
96
  self.initialized = True
@@ -91,7 +113,7 @@ class GetStorageClusterListApp(BaseVmwareApplication):
91
113
  @rtype: dict
92
114
  """
93
115
  res = super(GetStorageClusterListApp, self).as_dict(short=short)
94
- res['print_total'] = self.print_total
116
+ res["print_total"] = self.print_total
95
117
 
96
118
  return res
97
119
 
@@ -100,20 +122,30 @@ class GetStorageClusterListApp(BaseVmwareApplication):
100
122
  """Public available method to initiate the argument parser."""
101
123
  super(GetStorageClusterListApp, self).init_arg_parser()
102
124
 
103
- output_options = self.arg_parser.add_argument_group(_('Output options'))
125
+ output_options = self.arg_parser.add_argument_group(_("Output options"))
104
126
 
105
127
  output_options.add_argument(
106
- '-N', '--no-totals', action='store_true', dest='no_totals',
128
+ "-N",
129
+ "--no-totals",
130
+ action="store_true",
131
+ dest="no_totals",
107
132
  help=_("Don't print the totals of all storage clusters."),
108
133
  )
109
134
 
110
135
  output_options.add_argument(
111
- '-S', '--sort', metavar='KEY', nargs='+', dest='sort_keys',
112
- choices=self.avail_sort_keys, help=_(
113
- 'The keys for sorting the output. Available keys are: {avail}. '
114
- 'The default sorting keys are: {default}.').format(
136
+ "-S",
137
+ "--sort",
138
+ metavar="KEY",
139
+ nargs="+",
140
+ dest="sort_keys",
141
+ choices=self.avail_sort_keys,
142
+ help=_(
143
+ "The keys for sorting the output. Available keys are: {avail}. "
144
+ "The default sorting keys are: {default}."
145
+ ).format(
115
146
  avail=format_list(self.avail_sort_keys, do_repr=True),
116
- default=format_list(self.default_sort_keys, do_repr=True))
147
+ default=format_list(self.default_sort_keys, do_repr=True),
148
+ ),
117
149
  )
118
150
 
119
151
  # -------------------------------------------------------------------------
@@ -124,14 +156,13 @@ class GetStorageClusterListApp(BaseVmwareApplication):
124
156
  if self.args.sort_keys:
125
157
  self.sort_keys = self.args.sort_keys
126
158
 
127
- if getattr(self.args, 'no_totals', False):
159
+ if getattr(self.args, "no_totals", False):
128
160
  self._print_total = False
129
161
 
130
162
  # -------------------------------------------------------------------------
131
163
  def _run(self):
132
164
 
133
- LOG.debug(_('Starting {a!r}, version {v!r} ...').format(
134
- a=self.appname, v=self.version))
165
+ LOG.debug(_("Starting {a!r}, version {v!r} ...").format(a=self.appname, v=self.version))
135
166
 
136
167
  ret = 0
137
168
  try:
@@ -143,7 +174,7 @@ class GetStorageClusterListApp(BaseVmwareApplication):
143
174
 
144
175
  # -------------------------------------------------------------------------
145
176
  def get_datastore_clusters(self, vsphere_name):
146
- """Get all datastore clusters in a VMWare VSPhere."""
177
+ """Get all datastore clusters in a VMware vSphere."""
147
178
  storage_clusters = []
148
179
 
149
180
  vsphere = self.vsphere[vsphere_name]
@@ -177,16 +208,16 @@ class GetStorageClusterListApp(BaseVmwareApplication):
177
208
  _get_all_storage_clusters()
178
209
 
179
210
  else:
180
- spin_prompt = _('Getting all VSPhere storage clusters ...')
211
+ spin_prompt = _("Getting all vSphere storage clusters ...")
181
212
  spinner_name = self.get_random_spinner_name()
182
213
  with Spinner(spin_prompt, spinner_name):
183
214
  _get_all_storage_clusters()
184
- sys.stdout.write(' ' * len(spin_prompt))
185
- sys.stdout.write('\r')
215
+ sys.stdout.write(" " * len(spin_prompt))
216
+ sys.stdout.write("\r")
186
217
  sys.stdout.flush()
187
218
 
188
219
  if self.verbose > 2:
189
- LOG.debug(_('Found datastore clusters:') + '\n' + pp(all_storage_clusters))
220
+ LOG.debug(_("Found datastore clusters:") + "\n" + pp(all_storage_clusters))
190
221
 
191
222
  self.print_clusters(all_storage_clusters)
192
223
 
@@ -205,52 +236,54 @@ class GetStorageClusterListApp(BaseVmwareApplication):
205
236
 
206
237
  cl = clusters[vsphere_name][cluster_name]
207
238
  cluster = {}
208
- cluster['is_total'] = False
239
+ cluster["is_total"] = False
209
240
 
210
- cluster['cluster_name'] = cluster_name
241
+ cluster["cluster_name"] = cluster_name
211
242
 
212
- cluster['vsphere_name'] = vsphere_name
243
+ cluster["vsphere_name"] = vsphere_name
244
+ cluster["dc"] = cl.dc_name
213
245
 
214
- cluster['capacity'] = cl.capacity_gb
215
- cluster['capacity_gb'] = format_decimal(cl.capacity_gb, format='#,##0')
246
+ cluster["capacity"] = cl.capacity_gb
247
+ cluster["capacity_gb"] = format_decimal(cl.capacity_gb, format="#,##0")
216
248
  total_capacity += cl.capacity_gb
217
249
 
218
- cluster['free_space'] = cl.free_space_gb
219
- cluster['free_space_gb'] = format_decimal(cl.free_space_gb, format='#,##0')
250
+ cluster["free_space"] = cl.free_space_gb
251
+ cluster["free_space_gb"] = format_decimal(cl.free_space_gb, format="#,##0")
220
252
  total_free += cl.free_space_gb
221
253
 
222
254
  used = cl.capacity_gb - cl.free_space_gb
223
- cluster['usage'] = used
224
- cluster['usage_gb'] = format_decimal(used, format='#,##0')
255
+ cluster["usage"] = used
256
+ cluster["usage_gb"] = format_decimal(used, format="#,##0")
225
257
 
226
258
  if cl.capacity_gb:
227
259
  usage_pc = used / cl.capacity_gb
228
- cluster['usage_pc'] = usage_pc
229
- cluster['usage_pc_out'] = format_decimal(usage_pc, format='0.0 %')
260
+ cluster["usage_pc"] = usage_pc
261
+ cluster["usage_pc_out"] = format_decimal(usage_pc, format="0.0 %")
230
262
  else:
231
- cluster['usage_pc_out'] = '- %'
263
+ cluster["usage_pc_out"] = "- %"
232
264
 
233
265
  cluster_list.append(cluster)
234
266
 
235
267
  if self.print_total:
236
268
  total_used = total_capacity - total_free
237
269
  total_used_pc = None
238
- total_used_pc_out = '- %'
270
+ total_used_pc_out = "- %"
239
271
  if total_capacity:
240
272
  total_used_pc = total_used / total_capacity
241
- total_used_pc_out = format_decimal(total_used_pc, format='0.0 %')
273
+ total_used_pc_out = format_decimal(total_used_pc, format="0.0 %")
242
274
 
243
275
  self.totals = {
244
- 'cluster_name': _('Total'),
245
- 'vsphere_name': '',
246
- 'is_total': True,
247
- 'capacity_gb': format_decimal(total_capacity, format='#,##0'),
248
- 'free_space_gb': format_decimal(total_free, format='#,##0'),
249
- 'usage_gb': format_decimal(total_used, format='#,##0'),
250
- 'usage_pc_out': total_used_pc_out,
276
+ "cluster_name": _("Total"),
277
+ "vsphere_name": "",
278
+ "dc": "",
279
+ "is_total": True,
280
+ "capacity_gb": format_decimal(total_capacity, format="#,##0"),
281
+ "free_space_gb": format_decimal(total_free, format="#,##0"),
282
+ "usage_gb": format_decimal(total_used, format="#,##0"),
283
+ "usage_pc_out": total_used_pc_out,
251
284
  }
252
285
  if not self.quiet:
253
- self.totals['cluster_name'] += ':'
286
+ self.totals["cluster_name"] += ":"
254
287
 
255
288
  return cluster_list
256
289
 
@@ -280,17 +313,24 @@ class GetStorageClusterListApp(BaseVmwareApplication):
280
313
  def print_clusters(self, clusters):
281
314
  """Print on STDOUT all information about all datastore clusters."""
282
315
  labels = {
283
- 'cluster_name': 'Cluster',
284
- 'vsphere_name': 'VSPhere',
285
- 'capacity_gb': _('Capacity in GB'),
286
- 'free_space_gb': _('Free space in GB'),
287
- 'usage_gb': _('Calculated usage in GB'),
288
- 'usage_pc_out': _('Usage in percent'),
316
+ "cluster_name": "Cluster",
317
+ "vsphere_name": "vSphere",
318
+ "dc": _("Data Center"),
319
+ "capacity_gb": _("Capacity in GB"),
320
+ "free_space_gb": _("Free space in GB"),
321
+ "usage_gb": _("Calculated usage in GB"),
322
+ "usage_pc_out": _("Usage in percent"),
289
323
  }
290
324
 
291
325
  label_list = (
292
- 'cluster_name', 'vsphere_name', 'capacity_gb',
293
- 'usage_gb', 'usage_pc_out', 'free_space_gb')
326
+ "cluster_name",
327
+ "vsphere_name",
328
+ "dc",
329
+ "capacity_gb",
330
+ "usage_gb",
331
+ "usage_pc_out",
332
+ "free_space_gb",
333
+ )
294
334
 
295
335
  cluster_list = self._get_cluster_list(clusters)
296
336
  field_length = self._get_cluster_fields_len(cluster_list, labels)
@@ -304,26 +344,26 @@ class GetStorageClusterListApp(BaseVmwareApplication):
304
344
  max_len += field_length[label]
305
345
 
306
346
  if self.verbose > 2:
307
- LOG.debug('Label length:\n' + pp(field_length))
308
- LOG.debug('Max line length: {} chars'.format(max_len))
309
- LOG.debug('Datastore clusters:\n' + pp(cluster_list))
347
+ LOG.debug("Label length:\n" + pp(field_length))
348
+ LOG.debug("Max line length: {} chars".format(max_len))
349
+ LOG.debug("Datastore clusters:\n" + pp(cluster_list))
310
350
 
311
- tpl = ''
351
+ tpl = ""
312
352
  for label in label_list:
313
- if tpl != '':
314
- tpl += ' '
315
- if label in ('cluster_name', 'vsphere_name'):
316
- tpl += '{{{la}:<{le}}}'.format(la=label, le=field_length[label])
353
+ if tpl != "":
354
+ tpl += " "
355
+ if label in ("cluster_name", "vsphere_name", "dc"):
356
+ tpl += "{{{la}:<{le}}}".format(la=label, le=field_length[label])
317
357
  else:
318
- tpl += '{{{la}:>{le}}}'.format(la=label, le=field_length[label])
358
+ tpl += "{{{la}:>{le}}}".format(la=label, le=field_length[label])
319
359
  if self.verbose > 1:
320
- LOG.debug(_('Line template: {}').format(tpl))
360
+ LOG.debug(_("Line template: {}").format(tpl))
321
361
 
322
362
  if self.sort_keys:
323
- LOG.debug('Sorting keys: ' + pp(self.sort_keys))
363
+ LOG.debug("Sorting keys: " + pp(self.sort_keys))
324
364
  self.sort_keys.reverse()
325
365
  for key in self.sort_keys:
326
- if key in ('cluster_name', 'vsphere_name'):
366
+ if key in ("cluster_name", "vsphere_name"):
327
367
  cluster_list.sort(key=itemgetter(key))
328
368
  else:
329
369
  cluster_list.sort(key=itemgetter(key), reverse=True)
@@ -331,32 +371,52 @@ class GetStorageClusterListApp(BaseVmwareApplication):
331
371
  if not self.quiet:
332
372
  print()
333
373
  print(tpl.format(**labels))
334
- print('-' * max_len)
374
+ print("-" * max_len)
335
375
 
336
376
  for cluster in cluster_list:
337
377
  print(tpl.format(**cluster))
338
378
 
339
379
  if self.totals:
340
380
  if not self.quiet:
341
- print('-' * max_len)
381
+ print("-" * max_len)
342
382
  print(tpl.format(**self.totals))
343
383
 
344
384
  if not self.quiet:
345
385
  print()
346
386
  if count:
347
387
  msg = ngettext(
348
- 'Found one VMWare storage cluster.',
349
- 'Found {} VMWare storage clusters.'.format(count),
350
- count)
388
+ "Found one VMware storage cluster.",
389
+ "Found {} VMware storage clusters.",
390
+ count,
391
+ ).format(count)
351
392
  else:
352
- msg = _('No VMWare storage clusters found.')
393
+ msg = _("No VMware storage clusters found.")
353
394
 
354
395
  print(msg)
355
396
  print()
356
397
 
357
398
 
358
399
  # =============================================================================
359
- if __name__ == '__main__':
400
+ def main():
401
+ """Entrypoint for get-vsphere-storage-cluster-list."""
402
+ my_path = pathlib.Path(__file__)
403
+ appname = my_path.name
404
+
405
+ locale.setlocale(locale.LC_ALL, "")
406
+
407
+ app = GetStorageClusterListApp(appname=appname)
408
+ app.initialized = True
409
+
410
+ if app.verbose > 2:
411
+ print(_("{c}-Object:\n{a}").format(c=app.__class__.__name__, a=app), file=sys.stderr)
412
+
413
+ app()
414
+
415
+ sys.exit(0)
416
+
417
+
418
+ # =============================================================================
419
+ if __name__ == "__main__":
360
420
 
361
421
  pass
362
422