Browse Source

Add realtime LB service statistics

Change-Id: Ifad152c41a0525d883531de813645345f62160a3
changes/91/761091/2
asarfaty 2 years ago
parent
commit
20ec669402
  1. 16
      vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py
  2. 7
      vmware_nsxlib/v3/policy/lb_defs.py
  3. 3
      vmware_nsxlib/v3/policy/lb_resources.py

16
vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py

@ -931,8 +931,24 @@ class TestPolicyLBService(test_resources.NsxPolicyLibTestCase):
self.resourceApi.get_statistics(obj_id, tenant=TEST_TENANT)
expected_def = lb_defs.LBServiceStatisticsDef(
lb_service_id=obj_id,
realtime=False,
tenant=TEST_TENANT)
self.assert_called_with_def(api_call, expected_def)
self.assertEqual('%s/lb-services/%s/statistics/',
expected_def.path_pattern)
def test_get_statistics_realtime(self):
obj_id = '111'
with mock.patch.object(self.policy_api, "get") as api_call:
self.resourceApi.get_statistics(obj_id, realtime=True,
tenant=TEST_TENANT)
expected_def = lb_defs.LBServiceStatisticsDef(
lb_service_id=obj_id,
realtime=True,
tenant=TEST_TENANT)
self.assert_called_with_def(api_call, expected_def)
self.assertEqual('%s/lb-services/%s/statistics?source=realtime',
expected_def.path_pattern)
def test_get_virtual_server_status(self):
obj_id = '111'

7
vmware_nsxlib/v3/policy/lb_defs.py

@ -444,8 +444,15 @@ class LBServiceDef(ResourceDef):
class LBServiceStatisticsDef(ResourceDef):
def __init__(self, **kwargs):
self.realtime = kwargs.pop('realtime')
super(LBServiceStatisticsDef, self).__init__(**kwargs)
@property
def path_pattern(self):
if self.realtime:
return (LB_SERVICES_PATH_PATTERN +
'%s/statistics?source=realtime')
return LB_SERVICES_PATH_PATTERN + '%s/statistics/'
@property

3
vmware_nsxlib/v3/policy/lb_resources.py

@ -718,12 +718,13 @@ class NsxPolicyLoadBalancerServiceApi(NsxPolicyResourceBase):
_update()
def get_statistics(self, lb_service_id,
def get_statistics(self, lb_service_id, realtime=False,
tenant=constants.POLICY_INFRA_TENANT,
silent=False):
lb_service_stats_def = (
lb_defs.LBServiceStatisticsDef(
lb_service_id=lb_service_id,
realtime=realtime,
tenant=tenant))
return self.policy_api.get(lb_service_stats_def, silent=silent)

Loading…
Cancel
Save