Policy DHCP relay support
Change-Id: I925dcd150015c548e55e2a7a53598ce22c32c824
This commit is contained in:
parent
6464ba25ea
commit
570331ab44
|
@ -2669,6 +2669,55 @@ class TestPolicySegmentQosProfilesBinding(NsxPolicyLibTestCase):
|
|||
update_call, expected_def)
|
||||
|
||||
|
||||
class TestPolicyDhcpRelayConfig(NsxPolicyLibTestCase):
|
||||
|
||||
def setUp(self, *args, **kwargs):
|
||||
super(TestPolicyDhcpRelayConfig, self).setUp()
|
||||
self.resourceApi = self.policy_lib.dhcp_relay_config
|
||||
|
||||
def test_create(self):
|
||||
name = 'test'
|
||||
description = 'desc'
|
||||
server_addr = '1.1.1.1'
|
||||
|
||||
with mock.patch.object(self.policy_api,
|
||||
"create_or_update") as api_call:
|
||||
self.resourceApi.create_or_overwrite(
|
||||
name, description=description,
|
||||
server_addresses=[server_addr],
|
||||
tenant=TEST_TENANT)
|
||||
|
||||
expected_def = core_defs.DhcpRelayConfigDef(
|
||||
config_id=mock.ANY,
|
||||
name=name,
|
||||
description=description,
|
||||
server_addresses=[server_addr],
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
|
||||
def test_delete(self):
|
||||
config_id = '111'
|
||||
with mock.patch.object(self.policy_api, "delete") as api_call:
|
||||
self.resourceApi.delete(config_id, tenant=TEST_TENANT)
|
||||
expected_def = core_defs.DhcpRelayConfigDef(config_id=config_id,
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
|
||||
def test_get(self):
|
||||
config_id = '111'
|
||||
with mock.patch.object(self.policy_api, "get") as api_call:
|
||||
self.resourceApi.get(config_id, tenant=TEST_TENANT)
|
||||
expected_def = core_defs.DhcpRelayConfigDef(config_id=config_id,
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
|
||||
def test_list(self):
|
||||
with mock.patch.object(self.policy_api, "list") as api_call:
|
||||
self.resourceApi.list(tenant=TEST_TENANT)
|
||||
expected_def = core_defs.DhcpRelayConfigDef(tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
|
||||
|
||||
class TestPolicyLBClientSSLProfileApi(NsxPolicyLibTestCase):
|
||||
|
||||
def setUp(self, *args, **kwargs):
|
||||
|
|
|
@ -99,6 +99,7 @@ class NsxPolicyLib(lib.NsxLibBase):
|
|||
self.segment_port_qos_profiles = (
|
||||
core_resources.SegmentPortQosProfilesBindingMapApi(
|
||||
*args))
|
||||
self.dhcp_relay_config = core_resources.NsxDhcpRelayConfigApi(*args)
|
||||
self.load_balancer = lb_resources.NsxPolicyLoadBalancerApi(*args)
|
||||
|
||||
@property
|
||||
|
|
|
@ -47,6 +47,7 @@ MAC_DISCOVERY_PROFILES_PATH_PATTERN = (TENANTS_PATH_PATTERN +
|
|||
"mac-discovery-profiles/")
|
||||
|
||||
REALIZATION_PATH = "infra/realized-state/realized-entities?intent_path=%s"
|
||||
DHCP_REALY_PATTERN = TENANTS_PATH_PATTERN + "dhcp-relay-configs/"
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
|
@ -1385,6 +1386,29 @@ class MacDiscoveryProfileDef(ResourceDef):
|
|||
return body
|
||||
|
||||
|
||||
class DhcpRelayConfigDef(ResourceDef):
|
||||
|
||||
@property
|
||||
def path_pattern(self):
|
||||
return DHCP_REALY_PATTERN
|
||||
|
||||
@property
|
||||
def path_ids(self):
|
||||
return ('tenant', 'config_id')
|
||||
|
||||
@staticmethod
|
||||
def resource_type():
|
||||
return 'DhcpRelayConfig'
|
||||
|
||||
def path_defs(self):
|
||||
return (TenantDef,)
|
||||
|
||||
def get_obj_dict(self):
|
||||
body = super(DhcpRelayConfigDef, self).get_obj_dict()
|
||||
self._set_attr_if_specified(body, 'server_addresses')
|
||||
return body
|
||||
|
||||
|
||||
class NsxPolicyApi(object):
|
||||
|
||||
def __init__(self, client):
|
||||
|
|
|
@ -2633,3 +2633,52 @@ class NsxMacDiscoveryProfileApi(NsxSegmentProfileBaseApi):
|
|||
tenant=tenant)
|
||||
self._create_or_store(profile_def)
|
||||
return profile_id
|
||||
|
||||
|
||||
class NsxDhcpRelayConfigApi(NsxPolicyResourceBase):
|
||||
@property
|
||||
def entry_def(self):
|
||||
return core_defs.DhcpRelayConfigDef
|
||||
|
||||
def create_or_overwrite(self, name,
|
||||
config_id=None,
|
||||
description=None,
|
||||
server_addresses=IGNORE,
|
||||
tags=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
|
||||
config_id = self._init_obj_uuid(config_id)
|
||||
config_def = self._init_def(
|
||||
config_id=config_id,
|
||||
name=name,
|
||||
description=description,
|
||||
server_addresses=server_addresses,
|
||||
tags=tags,
|
||||
tenant=tenant)
|
||||
self._create_or_store(config_def)
|
||||
return config_id
|
||||
|
||||
def delete(self, config_id, tenant=constants.POLICY_INFRA_TENANT):
|
||||
config_def = self.entry_def(config_id=config_id, tenant=tenant)
|
||||
self.policy_api.delete(config_def)
|
||||
|
||||
def get(self, config_id, tenant=constants.POLICY_INFRA_TENANT,
|
||||
silent=False):
|
||||
config_def = self.entry_def(config_id=config_id, tenant=tenant)
|
||||
return self.policy_api.get(config_def, silent=silent)
|
||||
|
||||
def list(self, tenant=constants.POLICY_INFRA_TENANT):
|
||||
config_def = self.entry_def(tenant=tenant)
|
||||
return self._list(config_def)
|
||||
|
||||
def update(self, config_id, name=IGNORE,
|
||||
description=IGNORE,
|
||||
server_addresses=IGNORE,
|
||||
tags=IGNORE,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
self._update(config_id=config_id,
|
||||
name=name,
|
||||
description=description,
|
||||
server_addresses=server_addresses,
|
||||
tags=tags,
|
||||
tenant=tenant)
|
||||
|
|
Loading…
Reference in New Issue