Skip to content

Commit 590ea59

Browse files
Added f5.bigip.resource.Stats to the list of allowed_lazy_attributes on f5.big.tm.ltm collection objects Nodes, Pools, Rules, Virtuals and Virtual_Address_s
This is to allow obtaining all item stats with a single request which may come in handy when stats on large collections are required and calling item.stats.load() in a loop causes massive REST calls and huge delay. Note that entries have to be mapped by the application, suggested criteria are item.fullPath and stat_entry['nestedStats']['entries']['tmName']['description'].
1 parent 8d3cdda commit 590ea59

10 files changed

Lines changed: 77 additions & 5 deletions

File tree

f5/bigip/tm/ltm/node.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@
2929

3030
from f5.bigip.resource import Collection
3131
from f5.bigip.resource import Resource
32+
from f5.bigip.resource import Stats
3233
from f5.sdk_exception import NodeStateModifyUnsupported
3334

3435

3536
class Nodes(Collection):
3637
"""BIG-IP® LTM node collection"""
3738
def __init__(self, ltm):
3839
super(Nodes, self).__init__(ltm)
39-
self._meta_data['allowed_lazy_attributes'] = [Node]
40+
self._meta_data['allowed_lazy_attributes'] = [Node, Stats]
4041
self._meta_data['attribute_registry'] =\
4142
{'tm:ltm:node:nodestate': Node}
4243

f5/bigip/tm/ltm/pool.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131

3232
from f5.bigip.resource import Collection
3333
from f5.bigip.resource import Resource
34+
from f5.bigip.resource import Stats
3435
from f5.sdk_exception import MemberStateModifyUnsupported
3536

3637

3738
class Pools(Collection):
3839
"""BIG-IP® LTM pool collection"""
3940
def __init__(self, ltm):
4041
super(Pools, self).__init__(ltm)
41-
self._meta_data['allowed_lazy_attributes'] = [Pool]
42+
self._meta_data['allowed_lazy_attributes'] = [Pool, Stats]
4243
self._meta_data['attribute_registry'] =\
4344
{'tm:ltm:pool:poolstate': Pool}
4445

f5/bigip/tm/ltm/rule.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929

3030
from f5.bigip.resource import Collection
3131
from f5.bigip.resource import Resource
32+
from f5.bigip.resource import Stats
3233

3334

3435
class Rules(Collection):
3536
"""BIG-IP® LTM rule collection"""
3637
def __init__(self, ltm):
3738
super(Rules, self).__init__(ltm)
38-
self._meta_data['allowed_lazy_attributes'] = [Rule]
39+
self._meta_data['allowed_lazy_attributes'] = [Rule, Stats]
3940
self._meta_data['attribute_registry'] =\
4041
{'tm:ltm:rule:rulestate': Rule}
4142

f5/bigip/tm/ltm/test/functional/test_node.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,15 @@ def test_get_collection(self, request, mgmt_root):
210210
nodes = sc.get_collection()
211211
assert len(nodes) >= 1
212212
assert [n for n in nodes if n.name == 'node1']
213+
214+
def test_stats(self, request, mgmt_root, opt_release):
215+
setup_node_test(request, mgmt_root, 'Common', 'node1', '192.168.100.1')
216+
nodes_stats = mgmt_root.tm.ltm.nodes.stats.load()
217+
stats_link = 'https://localhost/mgmt/tm/ltm/node/' +\
218+
'~Common~node1/stats'
219+
assert stats_link in nodes_stats.entries
220+
node_nested_stats = nodes_stats.entries[stats_link]['nestedStats']
221+
assert node_nested_stats['selfLink'] == stats_link+'?ver='+opt_release
222+
entries = node_nested_stats['entries']
223+
assert entries['tmName']['description'] == '/Common/node1'
224+
assert entries['status.enabledState']['description'] == 'enabled'

f5/bigip/tm/ltm/test/functional/test_pool.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,21 @@ def test_session_modify_error(self, request, mgmt_root):
259259
"'user-up' or 'user-down'"
260260

261261

262+
class TestPoolsStats(object):
263+
def test_stats(self, request, mgmt_root, opt_release):
264+
m1, pool = setup_member_test(request, mgmt_root, 'membertestpool1',
265+
'Common')
266+
pools_stats = mgmt_root.tm.ltm.pools.stats.load()
267+
stats_link = 'https://localhost/mgmt/tm/ltm/pool/' +\
268+
'~Common~membertestpool1/stats'
269+
assert stats_link in pools_stats.entries
270+
pool_nested_stats = pools_stats.entries[stats_link]['nestedStats']
271+
assert pool_nested_stats['selfLink'] == stats_link+'?ver='+opt_release
272+
entries = pool_nested_stats['entries']
273+
assert entries['tmName']['description'] == '/Common/membertestpool1'
274+
assert entries['status.enabledState']['description'] == 'enabled'
275+
276+
262277
class TestPool(object):
263278
def test_create_no_args(self, mgmt_root):
264279
pool1 = mgmt_root.tm.ltm.pools.pool

f5/bigip/tm/ltm/test/functional/test_rule.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,17 @@ def test_rule_collection(self, request, mgmt_root):
174174
assert isinstance(rc, list)
175175
assert len(rc)
176176
assert isinstance(rc[0], Rule)
177+
178+
179+
class TestRulesStats(object):
180+
def test_stats(self, request, mgmt_root, opt_release):
181+
setup_basic_test(request, mgmt_root, 'rule1', 'Common')
182+
rules_stats = mgmt_root.tm.ltm.rules.stats.load()
183+
stats_link = 'https://localhost/mgmt/tm/ltm/rule/' +\
184+
'~Common~rule1:CLIENT_ACCEPTED/stats'
185+
assert stats_link in rules_stats.entries
186+
rule_nested_stats = rules_stats.entries[stats_link]['nestedStats']
187+
assert rule_nested_stats['selfLink'] == stats_link+'?ver='+opt_release
188+
entries = rule_nested_stats['entries']
189+
assert entries['tmName']['description'] == '/Common/rule1'
190+
assert entries['totalExecutions']['value'] == 0

f5/bigip/tm/ltm/test/functional/test_virtual.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,17 @@ def test_collection(self, virtual_setup, policy_setup):
253253
pclst = v1.policies_s.get_collection()
254254
assert len(pclst) > 0
255255
assert isinstance(pclst[0], Policies)
256+
257+
258+
class TestVirtualsStats(object):
259+
def test_stats(self, request, mgmt_root, opt_release):
260+
setup_virtual_test(request, mgmt_root, 'Common', 'tv1')
261+
vs_stats = mgmt_root.tm.ltm.virtuals.stats.load()
262+
stats_link = 'https://localhost/mgmt/tm/ltm/virtual/' +\
263+
'~Common~tv1/stats'
264+
assert stats_link in vs_stats.entries
265+
vs_nested_stats = vs_stats.entries[stats_link]['nestedStats']
266+
assert vs_nested_stats['selfLink'] == stats_link+'?ver='+opt_release
267+
entries = vs_nested_stats['entries']
268+
assert entries['tmName']['description'] == '/Common/tv1'
269+
assert entries['status.enabledState']['description'] == 'enabled'

f5/bigip/tm/ltm/test/functional/test_virtual_address.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ def test_get_collection(self, request, mgmt_root):
4141
assert len(vac) >= 1
4242
assert [va for va in vac if va.name == '0.0.0.0']
4343

44+
def test_stats(self, request, mgmt_root, opt_release):
45+
setup_virtual_address_s_test(request, mgmt_root, 'va_vs_test-1', 'Common')
46+
va_stats = mgmt_root.tm.ltm.virtual_address_s.stats.load()
47+
stats_link = 'https://localhost/mgmt/tm/ltm/virtual-address/' +\
48+
'~Common~0.0.0.0/stats'
49+
assert stats_link in va_stats.entries
50+
va_nested_stats = va_stats.entries[stats_link]['nestedStats']
51+
assert va_nested_stats['selfLink'] == stats_link+'?ver='+opt_release
52+
entries = va_nested_stats['entries']
53+
assert entries['tmName']['description'] == '/Common/0.0.0.0'
54+
assert entries['status.enabledState']['description'] == 'enabled'
55+
4456

4557
class TestVirtualAddress(object):
4658
def test_CURDLE(self, request, mgmt_root):

f5/bigip/tm/ltm/virtual.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from f5.bigip.mixins import ExclusiveAttributesMixin
3434
from f5.bigip.resource import Collection
3535
from f5.bigip.resource import Resource
36+
from f5.bigip.resource import Stats
3637
from f5.sdk_exception import NonExtantVirtualPolicy
3738
from f5.sdk_exception import UnregisteredKind
3839
from f5.sdk_exception import URICreationCollision
@@ -44,7 +45,7 @@ class Virtuals(Collection):
4445
"""BIG-IP® LTM virtual collection"""
4546
def __init__(self, ltm):
4647
super(Virtuals, self).__init__(ltm)
47-
self._meta_data['allowed_lazy_attributes'] = [Virtual]
48+
self._meta_data['allowed_lazy_attributes'] = [Virtual, Stats]
4849
self._meta_data['attribute_registry'] =\
4950
{'tm:ltm:virtual:virtualstate': Virtual}
5051

f5/bigip/tm/ltm/virtual_address.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030

3131
from f5.bigip.resource import Collection
3232
from f5.bigip.resource import Resource
33+
from f5.bigip.resource import Stats
3334

3435

3536
class Virtual_Address_s(Collection):
3637
"""BIG-IP® LTM virtual address collection."""
3738
def __init__(self, ltm):
3839
super(Virtual_Address_s, self).__init__(ltm)
39-
self._meta_data['allowed_lazy_attributes'] = [Virtual_Address]
40+
self._meta_data['allowed_lazy_attributes'] = [Virtual_Address, Stats]
4041
self._meta_data['attribute_registry'] =\
4142
{'tm:ltm:virtual-address:virtual-addressstate': Virtual_Address}
4243

0 commit comments

Comments
 (0)