NSXP: loadbalancer monitor API
Change-Id: I88172cc5fee0fc3fa10ab431c50c7aba84b73c82
This commit is contained in:
parent
781a42aec3
commit
b9333e0e6f
|
@ -863,3 +863,132 @@ class TestPolicyLBPoolApi(test_resources.NsxPolicyLibTestCase):
|
|||
snat_translation=snat_translation,
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(update_call, expected_def)
|
||||
|
||||
|
||||
class TestPolicyLBMonitorProfileHttpApi(test_resources.NsxPolicyLibTestCase):
|
||||
|
||||
def setUp(self, *args, **kwargs):
|
||||
super(TestPolicyLBMonitorProfileHttpApi, self).setUp()
|
||||
self.resourceApi = (
|
||||
self.policy_lib.load_balancer.lb_monitor_profile_http)
|
||||
self.obj_def = lb_defs.LBHttpMonitorProfileDef
|
||||
|
||||
def test_create_with_id(self):
|
||||
name = 'd1'
|
||||
obj_id = '111'
|
||||
with mock.patch.object(self.policy_api,
|
||||
"create_or_update") as api_call:
|
||||
result = self.resourceApi.create_or_overwrite(
|
||||
lb_monitor_profile_id=obj_id,
|
||||
display_name=name,
|
||||
tenant=TEST_TENANT)
|
||||
expected_def = self.obj_def(
|
||||
lb_monitor_profile_id=obj_id,
|
||||
display_name=name,
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
self.assertEqual(obj_id, result)
|
||||
|
||||
def test_create_without_id(self):
|
||||
name = 'd1'
|
||||
with mock.patch.object(self.policy_api,
|
||||
"create_or_update") as api_call:
|
||||
result = self.resourceApi.create_or_overwrite(
|
||||
display_name=name,
|
||||
tenant=TEST_TENANT)
|
||||
expected_def = self.obj_def(
|
||||
lb_monitor_profile_id=mock.ANY,
|
||||
display_name=name,
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
self.assertIsNotNone(result)
|
||||
|
||||
def test_delete(self):
|
||||
obj_id = '111'
|
||||
with mock.patch.object(self.policy_api, "delete") as api_call:
|
||||
self.resourceApi.delete(obj_id, tenant=TEST_TENANT)
|
||||
expected_def = self.obj_def(
|
||||
lb_monitor_profile_id=obj_id,
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
|
||||
def test_get(self):
|
||||
obj_id = '111'
|
||||
with mock.patch.object(self.policy_api, "get",
|
||||
return_value={'id': obj_id}) as api_call:
|
||||
result = self.resourceApi.get(obj_id, tenant=TEST_TENANT)
|
||||
expected_def = self.obj_def(
|
||||
lb_monitor_profile_id=obj_id,
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
self.assertEqual(obj_id, result['id'])
|
||||
|
||||
def test_get_by_name(self):
|
||||
name = 'd1'
|
||||
with mock.patch.object(
|
||||
self.policy_api, "list",
|
||||
return_value={'results': [{'display_name': name}]}) as api_call:
|
||||
obj = self.resourceApi.get_by_name(name, tenant=TEST_TENANT)
|
||||
self.assertIsNotNone(obj)
|
||||
expected_def = self.obj_def(
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
|
||||
def test_list(self):
|
||||
with mock.patch.object(self.policy_api, "list",
|
||||
return_value={'results': []}) as api_call:
|
||||
result = self.resourceApi.list(tenant=TEST_TENANT)
|
||||
expected_def = self.obj_def(
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
self.assertEqual([], result)
|
||||
|
||||
def test_update(self):
|
||||
obj_id = '111'
|
||||
name = 'new name'
|
||||
with mock.patch.object(self.policy_api,
|
||||
"create_or_update") as update_call:
|
||||
self.resourceApi.update(obj_id,
|
||||
display_name=name,
|
||||
tenant=TEST_TENANT)
|
||||
expected_def = self.obj_def(
|
||||
lb_monitor_profile_id=obj_id,
|
||||
display_name=name,
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(update_call, expected_def)
|
||||
|
||||
|
||||
class TestPolicyLBMonitorProfileHttpsApi(TestPolicyLBMonitorProfileHttpApi):
|
||||
|
||||
def setUp(self, *args, **kwargs):
|
||||
super(TestPolicyLBMonitorProfileHttpsApi, self).setUp()
|
||||
self.resourceApi = (
|
||||
self.policy_lib.load_balancer.lb_monitor_profile_https)
|
||||
self.obj_def = lb_defs.LBHttpsMonitorProfileDef
|
||||
|
||||
|
||||
class TestPolicyLBMonitorProfileUdpApi(TestPolicyLBMonitorProfileHttpApi):
|
||||
|
||||
def setUp(self, *args, **kwargs):
|
||||
super(TestPolicyLBMonitorProfileUdpApi, self).setUp()
|
||||
self.resourceApi = (
|
||||
self.policy_lib.load_balancer.lb_monitor_profile_udp)
|
||||
self.obj_def = lb_defs.LBUdpMonitorProfileDef
|
||||
|
||||
|
||||
class TestPolicyLBMonitorProfileIcmpApi(TestPolicyLBMonitorProfileHttpApi):
|
||||
|
||||
def setUp(self, *args, **kwargs):
|
||||
super(TestPolicyLBMonitorProfileIcmpApi, self).setUp()
|
||||
self.resourceApi = (
|
||||
self.policy_lib.load_balancer.lb_monitor_profile_icmp)
|
||||
self.obj_def = lb_defs.LBIcmpMonitorProfileDef
|
||||
|
||||
|
||||
class TestPolicyLBMonitorProfileTcpApi(TestPolicyLBMonitorProfileHttpApi):
|
||||
|
||||
def setUp(self, *args, **kwargs):
|
||||
super(TestPolicyLBMonitorProfileTcpApi, self).setUp()
|
||||
self.resourceApi = (
|
||||
self.policy_lib.load_balancer.lb_monitor_profile_tcp)
|
||||
self.obj_def = lb_defs.LBTcpMonitorProfileDef
|
||||
|
|
|
@ -21,6 +21,7 @@ LB_VIRTUAL_SERVERS_PATH_PATTERN = TENANTS_PATH_PATTERN + "lb-virtual-servers/"
|
|||
LB_SERVICES_PATH_PATTERN = TENANTS_PATH_PATTERN + "lb-services/"
|
||||
LB_POOL_PATH_PATTERN = TENANTS_PATH_PATTERN + "lb-pools/"
|
||||
LB_APP_PROFILE_PATTERN = TENANTS_PATH_PATTERN + "lb-app-profiles/"
|
||||
LB_MONITOR_PROFILE_PATTERN = TENANTS_PATH_PATTERN + "lb-monitor-profiles/"
|
||||
LB_CLIENT_SSL_PROFILE_PATTERN = (TENANTS_PATH_PATTERN +
|
||||
"lb-client-ssl-profiles/")
|
||||
LB_PERSISTENCE_PROFILE_PATTERN = (TENANTS_PATH_PATTERN +
|
||||
|
@ -368,3 +369,64 @@ class LBServiceUsageDef(ResourceDef):
|
|||
@property
|
||||
def path_ids(self):
|
||||
return ('tenant', 'lb_service_id', '')
|
||||
|
||||
|
||||
class LBMonitorProfileBaseDef(ResourceDef):
|
||||
|
||||
body = ['interval', 'timeout', 'fall_count', 'rise_count']
|
||||
|
||||
@property
|
||||
def path_pattern(self):
|
||||
return LB_MONITOR_PROFILE_PATTERN
|
||||
|
||||
@property
|
||||
def path_ids(self):
|
||||
return ('tenant', 'lb_monitor_profile_id')
|
||||
|
||||
def get_obj_dict(self):
|
||||
body = super(LBMonitorProfileBaseDef, self).get_obj_dict()
|
||||
self._set_attrs_if_specified(body, self.body)
|
||||
return body
|
||||
|
||||
|
||||
class LBHttpMonitorProfileDef(LBMonitorProfileBaseDef):
|
||||
|
||||
body = LBMonitorProfileBaseDef.body + [
|
||||
'monitor_port', 'request_url', 'request_method', 'request_version',
|
||||
'request_headers', 'request_body', 'response_status_codes']
|
||||
|
||||
@staticmethod
|
||||
def resource_type():
|
||||
return "LBHttpMonitorProfile"
|
||||
|
||||
|
||||
class LBHttpsMonitorProfileDef(LBHttpMonitorProfileDef):
|
||||
|
||||
@staticmethod
|
||||
def resource_type():
|
||||
return "LBHttpsMonitorProfile"
|
||||
|
||||
|
||||
class LBUdpMonitorProfileDef(LBMonitorProfileBaseDef):
|
||||
|
||||
body = LBMonitorProfileBaseDef.body + ['monitor_port', 'receive', 'send']
|
||||
|
||||
@staticmethod
|
||||
def resource_type():
|
||||
return "LBUdpMonitorProfile"
|
||||
|
||||
|
||||
class LBIcmpMonitorProfileDef(LBMonitorProfileBaseDef):
|
||||
|
||||
@staticmethod
|
||||
def resource_type():
|
||||
return "LBIcmpMonitorProfile"
|
||||
|
||||
|
||||
class LBTcpMonitorProfileDef(LBMonitorProfileBaseDef):
|
||||
|
||||
body = LBMonitorProfileBaseDef.body + ['monitor_port']
|
||||
|
||||
@staticmethod
|
||||
def resource_type():
|
||||
return "LBTcpMonitorProfile"
|
||||
|
|
|
@ -14,7 +14,10 @@
|
|||
# under the License.
|
||||
#
|
||||
|
||||
import abc
|
||||
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
from vmware_nsxlib.v3.policy import constants
|
||||
from vmware_nsxlib.v3.policy import lb_defs
|
||||
|
@ -719,6 +722,302 @@ class NsxPolicyLoadBalancerVirtualServerAPI(NsxPolicyResourceBase):
|
|||
application_profile_id=app_profile_id)
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class NsxPolicyLBMonitorProfileBase(NsxPolicyResourceBase):
|
||||
"""NSX Policy LB monitor profile"""
|
||||
|
||||
def create_or_overwrite(self,
|
||||
lb_monitor_profile_id=None,
|
||||
tags=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT,
|
||||
**kwargs):
|
||||
lb_monitor_profile_id = self._init_obj_uuid(lb_monitor_profile_id)
|
||||
lb_monitor_profile_def = self._init_def(
|
||||
lb_monitor_profile_id=lb_monitor_profile_id,
|
||||
tags=tags,
|
||||
tenant=tenant,
|
||||
**kwargs)
|
||||
self._create_or_store(lb_monitor_profile_def)
|
||||
return lb_monitor_profile_id
|
||||
|
||||
def delete(self, lb_monitor_profile_id,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
lb_monitor_profile_def = self.entry_def(
|
||||
lb_monitor_profile_id=lb_monitor_profile_id,
|
||||
tenant=tenant)
|
||||
self.policy_api.delete(lb_monitor_profile_def)
|
||||
|
||||
def get(self, lb_monitor_profile_id,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
lb_monitor_profile_def = self.entry_def(
|
||||
lb_monitor_profile_id=lb_monitor_profile_id,
|
||||
tenant=tenant)
|
||||
return self.policy_api.get(lb_monitor_profile_def)
|
||||
|
||||
def list(self, tenant=constants.POLICY_INFRA_TENANT):
|
||||
lb_monitor_profile_def = self.entry_def(tenant=tenant)
|
||||
return self._list(lb_monitor_profile_def)
|
||||
|
||||
def update(self,
|
||||
lb_monitor_profile_id,
|
||||
display_name=IGNORE,
|
||||
tags=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT,
|
||||
**kwargs):
|
||||
self._update(
|
||||
lb_monitor_profile_id=lb_monitor_profile_id,
|
||||
display_name=display_name,
|
||||
tags=tags,
|
||||
tenant=tenant,
|
||||
**kwargs)
|
||||
|
||||
def get_path(self, lb_monitor_profile_id,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
mon_def = self.entry_def(lb_monitor_profile_id=lb_monitor_profile_id,
|
||||
tenant=tenant)
|
||||
return mon_def.get_resource_full_path()
|
||||
|
||||
|
||||
class NsxPolicyLBMonitorProfileHttpApi(NsxPolicyLBMonitorProfileBase):
|
||||
"""NSX Policy LB HTTP monitor profile"""
|
||||
|
||||
def create_or_overwrite(self,
|
||||
lb_monitor_profile_id=None,
|
||||
tags=IGNORE,
|
||||
display_name=IGNORE,
|
||||
interval=IGNORE,
|
||||
timeout=IGNORE,
|
||||
fall_count=IGNORE,
|
||||
rise_count=IGNORE,
|
||||
monitor_port=IGNORE,
|
||||
request_url=IGNORE,
|
||||
request_method=IGNORE,
|
||||
request_version=IGNORE,
|
||||
request_headers=IGNORE,
|
||||
request_body=IGNORE,
|
||||
response_status_codes=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
return super(NsxPolicyLBMonitorProfileHttpApi,
|
||||
self).create_or_overwrite(
|
||||
lb_monitor_profile_id=lb_monitor_profile_id,
|
||||
tags=tags,
|
||||
display_name=display_name,
|
||||
interval=interval,
|
||||
timeout=timeout,
|
||||
fall_count=fall_count,
|
||||
rise_count=rise_count,
|
||||
monitor_port=monitor_port,
|
||||
request_url=request_url,
|
||||
request_method=request_method,
|
||||
request_version=request_version,
|
||||
request_headers=request_headers,
|
||||
request_body=request_body,
|
||||
response_status_codes=response_status_codes,
|
||||
tenant=tenant)
|
||||
|
||||
def update(self,
|
||||
lb_monitor_profile_id,
|
||||
tags=IGNORE,
|
||||
display_name=IGNORE,
|
||||
interval=IGNORE,
|
||||
timeout=IGNORE,
|
||||
fall_count=IGNORE,
|
||||
rise_count=IGNORE,
|
||||
monitor_port=IGNORE,
|
||||
request_url=IGNORE,
|
||||
request_method=IGNORE,
|
||||
request_version=IGNORE,
|
||||
request_headers=IGNORE,
|
||||
request_body=IGNORE,
|
||||
response_status_codes=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
return super(NsxPolicyLBMonitorProfileHttpApi, self).update(
|
||||
lb_monitor_profile_id=lb_monitor_profile_id,
|
||||
tags=tags,
|
||||
display_name=display_name,
|
||||
interval=interval,
|
||||
timeout=timeout,
|
||||
fall_count=fall_count,
|
||||
rise_count=rise_count,
|
||||
monitor_port=monitor_port,
|
||||
request_url=request_url,
|
||||
request_method=request_method,
|
||||
request_version=request_version,
|
||||
request_headers=request_headers,
|
||||
request_body=request_body,
|
||||
response_status_codes=response_status_codes,
|
||||
tenant=tenant)
|
||||
|
||||
@property
|
||||
def entry_def(self):
|
||||
return lb_defs.LBHttpMonitorProfileDef
|
||||
|
||||
|
||||
class NsxPolicyLBMonitorProfileHttpsApi(NsxPolicyLBMonitorProfileHttpApi):
|
||||
"""NSX Policy LB HTTPS monitor profile"""
|
||||
|
||||
@property
|
||||
def entry_def(self):
|
||||
return lb_defs.LBHttpsMonitorProfileDef
|
||||
|
||||
|
||||
class NsxPolicyLBMonitorProfileUdpApi(NsxPolicyLBMonitorProfileBase):
|
||||
"""NSX Policy LB UDP monitor profile"""
|
||||
|
||||
def create_or_overwrite(self,
|
||||
lb_monitor_profile_id=None,
|
||||
tags=IGNORE,
|
||||
display_name=IGNORE,
|
||||
interval=IGNORE,
|
||||
timeout=IGNORE,
|
||||
fall_count=IGNORE,
|
||||
rise_count=IGNORE,
|
||||
monitor_port=IGNORE,
|
||||
receive=IGNORE,
|
||||
send=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
return super(NsxPolicyLBMonitorProfileUdpApi,
|
||||
self).create_or_overwrite(
|
||||
lb_monitor_profile_id=lb_monitor_profile_id,
|
||||
tags=tags,
|
||||
display_name=display_name,
|
||||
interval=interval,
|
||||
timeout=timeout,
|
||||
fall_count=fall_count,
|
||||
rise_count=rise_count,
|
||||
monitor_port=monitor_port,
|
||||
receive=receive,
|
||||
send=send,
|
||||
tenant=tenant)
|
||||
|
||||
def update(self,
|
||||
lb_monitor_profile_id,
|
||||
tags=IGNORE,
|
||||
display_name=IGNORE,
|
||||
interval=IGNORE,
|
||||
timeout=IGNORE,
|
||||
fall_count=IGNORE,
|
||||
rise_count=IGNORE,
|
||||
monitor_port=IGNORE,
|
||||
receive=IGNORE,
|
||||
send=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
return super(NsxPolicyLBMonitorProfileUdpApi, self).update(
|
||||
lb_monitor_profile_id=lb_monitor_profile_id,
|
||||
tags=tags,
|
||||
display_name=display_name,
|
||||
interval=interval,
|
||||
timeout=timeout,
|
||||
fall_count=fall_count,
|
||||
rise_count=rise_count,
|
||||
monitor_port=monitor_port,
|
||||
receive=receive,
|
||||
send=send,
|
||||
tenant=tenant)
|
||||
|
||||
@property
|
||||
def entry_def(self):
|
||||
return lb_defs.LBUdpMonitorProfileDef
|
||||
|
||||
|
||||
class NsxPolicyLBMonitorProfileIcmpApi(NsxPolicyLBMonitorProfileBase):
|
||||
"""NSX Policy LB ICMP monitor profile"""
|
||||
|
||||
def create_or_overwrite(self,
|
||||
lb_monitor_profile_id=None,
|
||||
tags=IGNORE,
|
||||
display_name=IGNORE,
|
||||
interval=IGNORE,
|
||||
timeout=IGNORE,
|
||||
fall_count=IGNORE,
|
||||
rise_count=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
return super(NsxPolicyLBMonitorProfileIcmpApi,
|
||||
self).create_or_overwrite(
|
||||
lb_monitor_profile_id=lb_monitor_profile_id,
|
||||
tags=tags,
|
||||
display_name=display_name,
|
||||
interval=interval,
|
||||
timeout=timeout,
|
||||
fall_count=fall_count,
|
||||
rise_count=rise_count,
|
||||
tenant=tenant)
|
||||
|
||||
def update(self,
|
||||
lb_monitor_profile_id,
|
||||
tags=IGNORE,
|
||||
display_name=IGNORE,
|
||||
interval=IGNORE,
|
||||
timeout=IGNORE,
|
||||
fall_count=IGNORE,
|
||||
rise_count=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
return super(NsxPolicyLBMonitorProfileIcmpApi, self).update(
|
||||
lb_monitor_profile_id=lb_monitor_profile_id,
|
||||
tags=tags,
|
||||
display_name=display_name,
|
||||
interval=interval,
|
||||
timeout=timeout,
|
||||
fall_count=fall_count,
|
||||
rise_count=rise_count,
|
||||
tenant=tenant)
|
||||
|
||||
@property
|
||||
def entry_def(self):
|
||||
return lb_defs.LBIcmpMonitorProfileDef
|
||||
|
||||
|
||||
class NsxPolicyLBMonitorProfileTcpApi(NsxPolicyLBMonitorProfileBase):
|
||||
"""NSX Policy LB TCP monitor profile"""
|
||||
|
||||
def create_or_overwrite(self,
|
||||
lb_monitor_profile_id=None,
|
||||
tags=IGNORE,
|
||||
display_name=IGNORE,
|
||||
interval=IGNORE,
|
||||
timeout=IGNORE,
|
||||
fall_count=IGNORE,
|
||||
rise_count=IGNORE,
|
||||
monitor_port=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
return super(NsxPolicyLBMonitorProfileTcpApi,
|
||||
self).create_or_overwrite(
|
||||
lb_monitor_profile_id=lb_monitor_profile_id,
|
||||
tags=tags,
|
||||
display_name=display_name,
|
||||
interval=interval,
|
||||
timeout=timeout,
|
||||
fall_count=fall_count,
|
||||
rise_count=rise_count,
|
||||
monitor_port=monitor_port,
|
||||
tenant=tenant)
|
||||
|
||||
def update(self,
|
||||
lb_monitor_profile_id,
|
||||
tags=IGNORE,
|
||||
display_name=IGNORE,
|
||||
interval=IGNORE,
|
||||
timeout=IGNORE,
|
||||
fall_count=IGNORE,
|
||||
rise_count=IGNORE,
|
||||
monitor_port=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
return super(NsxPolicyLBMonitorProfileTcpApi, self).update(
|
||||
lb_monitor_profile_id=lb_monitor_profile_id,
|
||||
tags=tags,
|
||||
display_name=display_name,
|
||||
interval=interval,
|
||||
timeout=timeout,
|
||||
fall_count=fall_count,
|
||||
rise_count=rise_count,
|
||||
monitor_port=monitor_port,
|
||||
tenant=tenant)
|
||||
|
||||
@property
|
||||
def entry_def(self):
|
||||
return lb_defs.LBTcpMonitorProfileDef
|
||||
|
||||
|
||||
class NsxPolicyLoadBalancerApi(object):
|
||||
"""This is the class that have all load balancer policy apis"""
|
||||
def __init__(self, *args):
|
||||
|
@ -734,3 +1033,9 @@ class NsxPolicyLoadBalancerApi(object):
|
|||
self.lb_service = NsxPolicyLoadBalancerServiceApi(*args)
|
||||
self.virtual_server = NsxPolicyLoadBalancerVirtualServerAPI(*args)
|
||||
self.lb_pool = NsxPolicyLoadBalancerPoolApi(*args)
|
||||
self.lb_monitor_profile_http = NsxPolicyLBMonitorProfileHttpApi(*args)
|
||||
self.lb_monitor_profile_https = (
|
||||
NsxPolicyLBMonitorProfileHttpsApi(*args))
|
||||
self.lb_monitor_profile_udp = NsxPolicyLBMonitorProfileUdpApi(*args)
|
||||
self.lb_monitor_profile_icmp = NsxPolicyLBMonitorProfileIcmpApi(*args)
|
||||
self.lb_monitor_profile_tcp = NsxPolicyLBMonitorProfileTcpApi(*args)
|
||||
|
|
Loading…
Reference in New Issue