diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py index aede9890..afa0d8c4 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py @@ -731,6 +731,25 @@ class TestPolicyLBService(test_resources.NsxPolicyLibTestCase): relax_scale_validation=relax_scale_validation) self.assert_called_with_def(update_call, expected_def) + def test_update_customized(self): + obj_id = '111' + name = 'name' + tags = [{'tag': '1', 'scope': '2'}] + + def update_callback(body): + body['tags'] = tags + + with self.mock_get(obj_id, name), \ + mock.patch.object(self.policy_api.client, "update") as update_call: + self.resourceApi.update_customized( + obj_id, update_callback) + + update_call.assert_called_once_with( + 'infra/lb-services/%s' % obj_id, + {'id': obj_id, 'display_name': name, + 'resource_type': 'LBService', + 'tags': tags}) + def test_get_status(self): obj_id = '111' with mock.patch.object(self.policy_api, "get") as api_call: diff --git a/vmware_nsxlib/v3/policy/lb_resources.py b/vmware_nsxlib/v3/policy/lb_resources.py index b9f606c7..fea46829 100644 --- a/vmware_nsxlib/v3/policy/lb_resources.py +++ b/vmware_nsxlib/v3/policy/lb_resources.py @@ -615,6 +615,30 @@ class NsxPolicyLoadBalancerServiceApi(NsxPolicyResourceBase): relax_scale_validation=relax_scale_validation, tenant=tenant) + def update_customized(self, lb_service_id, update_payload_cbk, + tenant=constants.POLICY_INFRA_TENANT): + """Update the LB service using GET & PUT + + Changing the body with a customized callback + """ + + lb_service_def = self.entry_def( + lb_service_id=lb_service_id, tenant=tenant) + lb_service_path = lb_service_def.get_resource_path() + + @utils.retry_upon_exception( + nsxlib_exc.StaleRevision, + max_attempts=self.policy_api.client.max_attempts) + def _update(): + # Get the current data of service + lb_service_body = self.policy_api.get(lb_service_def) + # Update the body with the supplied callback + update_payload_cbk(lb_service_body) + # Update the backend using PUT + self.policy_api.client.update(lb_service_path, lb_service_body) + + _update() + def get_statistics(self, lb_service_id, tenant=constants.POLICY_INFRA_TENANT): lb_service_stats_def = (