Skip to content

Commit

Permalink
Merge branch 'release-v3.5.3'
Browse files Browse the repository at this point in the history
* release-v3.5.3:
  Add a template commodity enumeration utility
  • Loading branch information
rastern committed Mar 3, 2021
2 parents 76e5ddf + a97144e commit 4cea5ed
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 3.5.2
current_version = 3.5.3
commit = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<release>[a-z]+)(?P<build>\d*))?
serialize =
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
# built documents.
#
# The short X.Y version.
version = u'3.5.2'
version = u'3.5.3'
# The full version, including alpha/beta/rc tags.
release = u'3.5.2'
release = u'3.5.3'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion vmtconnect/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

__title__ = 'vmtconnect'
__description__ = 'Turbonomic API Client'
__version__ = '3.5.2'
__version__ = '3.5.3'
__author__ = 'R.A. Stern'
__author_email__ = '[email protected]'
__license__ = 'Apache 2.0'
Expand Down
51 changes: 51 additions & 0 deletions vmtconnect/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@



_template_resources = [
'computeResources',
'infrastructureResources',
'storageResources'
]



def enumerate_stats(data, entity=None, period=None, stat=None):
"""Enumerates stats endpoint results
Expand Down Expand Up @@ -62,6 +70,49 @@ def enumerate_stats(data, entity=None, period=None, stat=None):
yield v2['date'], v3


def enumerate_template_resources(data, restype=None, res=None):
"""Enumerates template commodities
Provides an iterator for more intuitive and cleaner parsing of nested
template resource data. Each iteration returns a tuple containing the
resource type, as well as the next resource entry as a dictionary.
Args:
data (list): Template data to parse.
restype (function, optional): Optional resource type level filter function.
res (function, optional): Optional resource level filter function.
Notes:
Filter functions must return ``True``, to continue processing, or ``False``
to skip processing the current level element.
Examples:
.. code-block:: python
# filter stats for a single type
desired_res = 'computeResources'
enumerate_template_resources(data, restype=lambda x: x == desired_res)
# filter specific stats for all IDs
blacklist = ['diskConsumedFactor']
enumerate_template_resources(data, res=lambda x: x['name'] not in blacklist)
"""
if isinstance(data, list):
data = data[0]

for r in _template_resources:
if restype is not None and not restype(r):
continue

try:
for k1, v1 in enumerate(data[r][0]['stats']):
if res is not None and not res(v1):
continue
yield r, v1
except KeyError:
pass


def unit_cast(value, ufrom, uto, factor, unit_list, precision=False):
offset = unit_list.index(uto) - unit_list.index(ufrom)
chg = Decimal(pow(factor, abs(offset)))
Expand Down

0 comments on commit 4cea5ed

Please sign in to comment.