Support getting realtime LBS usage in policy
In current implementation, the LBS get_usage function returns the number of current realized resources. This could potentially break the l4 autoscaling logic. Thus we need to get the realtime usage of LBS, which includes the resources in progress Change-Id: I5454a572cd751d2dd2a51135122d902031a0eaf3
This commit is contained in:
parent
86e303b5da
commit
c9fabb82ee
@ -667,6 +667,19 @@ class TestPolicyLBService(test_resources.NsxPolicyLibTestCase):
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
|
||||
def test_get_usage(self):
|
||||
lbs_id = 'test_vs'
|
||||
with mock.patch.object(self.policy_api, "get") as api_call:
|
||||
self.resourceApi.get_usage(
|
||||
lbs_id, realtime=True, tenant=TEST_TENANT)
|
||||
expected_def = lb_defs.LBServiceUsageDef(
|
||||
lb_service_id=lbs_id,
|
||||
realtime=True,
|
||||
tenant=TEST_TENANT)
|
||||
expected_path = '%s/lb-services/%s/service-usage?source=realtime'
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
self.assertEqual(expected_def.path_pattern, expected_path)
|
||||
|
||||
|
||||
class TestPolicyLBVirtualServer(test_resources.NsxPolicyLibTestCase):
|
||||
|
||||
|
@ -406,8 +406,15 @@ class LBServiceStatusDef(ResourceDef):
|
||||
|
||||
class LBServiceUsageDef(ResourceDef):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.realtime = kwargs.pop('realtime')
|
||||
super(LBServiceUsageDef, self).__init__(**kwargs)
|
||||
|
||||
@property
|
||||
def path_pattern(self):
|
||||
if self.realtime:
|
||||
return (LB_SERVICES_PATH_PATTERN +
|
||||
'%s/service-usage?source=realtime')
|
||||
return LB_SERVICES_PATH_PATTERN + '%s/service-usage/'
|
||||
|
||||
@property
|
||||
|
@ -611,10 +611,10 @@ class NsxPolicyLoadBalancerServiceApi(NsxPolicyResourceBase):
|
||||
tenant=tenant))
|
||||
return self.policy_api.get(lb_vs_status_def)
|
||||
|
||||
def get_usage(self, lb_service_id):
|
||||
def get_usage(self, lb_service_id, realtime=False,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
lb_service_status_def = lb_defs.LBServiceUsageDef(
|
||||
lb_service_id=lb_service_id,
|
||||
tenant=constants.POLICY_INFRA_TENANT)
|
||||
lb_service_id=lb_service_id, realtime=realtime, tenant=tenant)
|
||||
return self.policy_api.get(lb_service_status_def)
|
||||
|
||||
def get_path(self, lb_service_id,
|
||||
|
Loading…
x
Reference in New Issue
Block a user