Browse Source

Add realtime LB service statistics

Change-Id: Ifad152c41a0525d883531de813645345f62160a3
changes/97/761097/2
asarfaty 2 months ago
committed by Adit Sarfaty
parent
commit
d3bb9caffe
3 changed files with 25 additions and 1 deletions
  1. +16
    -0
      vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py
  2. +7
    -0
      vmware_nsxlib/v3/policy/lb_defs.py
  3. +2
    -1
      vmware_nsxlib/v3/policy/lb_resources.py

+ 16
- 0
vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py View File

@@ -800,8 +800,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
- 0
vmware_nsxlib/v3/policy/lb_defs.py View File

@@ -393,8 +393,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


+ 2
- 1
vmware_nsxlib/v3/policy/lb_resources.py View File

@@ -664,12 +664,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