Policy: Add connection information to enforcement points

Adding edge-cluster-id and transport-zone-id to the enforcement points
connection info

Change-Id: I98ebb3130a3f6e62d36895a6709d33683d9e6093
This commit is contained in:
Adit Sarfaty 2018-02-27 11:59:31 +02:00
parent 31f2095cc1
commit e0ad9472e5
3 changed files with 30 additions and 0 deletions

View File

@ -841,6 +841,8 @@ class TestPolicyEnforcementPoint(NsxPolicyLibTestCase):
username = 'admin'
password = 'zzz'
thumbprint = 'abc'
edge_cluster_id = 'ec1'
transport_zone_id = 'tz1'
with mock.patch.object(self.policy_api,
"create_or_update") as api_call:
self.resourceApi.create_or_overwrite(
@ -849,6 +851,8 @@ class TestPolicyEnforcementPoint(NsxPolicyLibTestCase):
thumbprint=thumbprint,
username=username,
password=password,
edge_cluster_id=edge_cluster_id,
transport_zone_id=transport_zone_id,
tenant=TEST_TENANT)
expected_def = policy_defs.EnforcementPointDef(
@ -859,6 +863,8 @@ class TestPolicyEnforcementPoint(NsxPolicyLibTestCase):
username=username,
thumbprint=thumbprint,
password=password,
edge_cluster_id=edge_cluster_id,
transport_zone_id=transport_zone_id,
tenant=TEST_TENANT)
self.assert_called_with_def(api_call, expected_def)
@ -901,6 +907,8 @@ class TestPolicyEnforcementPoint(NsxPolicyLibTestCase):
password = 'zzz'
ip_address = '1.1.1.1'
thumbprint = 'abc'
edge_cluster_id = 'ec1'
transport_zone_id = 'tz1'
with mock.patch.object(self.policy_api,
"create_or_update") as update_call,\
mock.patch.object(self.policy_api, "get", return_value={'id': id}):
@ -910,6 +918,8 @@ class TestPolicyEnforcementPoint(NsxPolicyLibTestCase):
password=password,
ip_address=ip_address,
thumbprint=thumbprint,
edge_cluster_id=edge_cluster_id,
transport_zone_id=transport_zone_id,
tenant=TEST_TENANT)
expected_def = policy_defs.EnforcementPointDef(ep_id=id,
tenant=TEST_TENANT)
@ -921,6 +931,8 @@ class TestPolicyEnforcementPoint(NsxPolicyLibTestCase):
'password': password,
'thumbprint': thumbprint,
'enforcement_point_address': ip_address,
'edge_cluster_ids': [edge_cluster_id],
'transport_zone_ids': [transport_zone_id],
'resource_type': 'NSXTConnectionInfo'}}
self.assert_called_with_def_and_dict(
update_call, expected_def, expected_dict)

View File

@ -463,6 +463,8 @@ class EnforcementPointDef(ResourceDef):
username=None,
password=None,
thumbprint=None,
edge_cluster_id=None,
transport_zone_id=None,
tenant=policy_constants.POLICY_INFRA_TENANT):
super(EnforcementPointDef, self).__init__()
self.id = ep_id
@ -473,6 +475,8 @@ class EnforcementPointDef(ResourceDef):
self.password = password
self.ip_address = ip_address
self.thumbprint = thumbprint
self.edge_cluster_id = edge_cluster_id
self.transport_zone_id = transport_zone_id
self.parent_ids = (tenant)
@property
@ -488,6 +492,8 @@ class EnforcementPointDef(ResourceDef):
'username': self.username,
'password': self.password,
'enforcement_point_address': self.ip_address,
'edge_cluster_ids': [self.edge_cluster_id],
'transport_zone_ids': [self.transport_zone_id],
'resource_type': 'NSXTConnectionInfo'}
body['resource_type'] = 'EnforcementPoint'
return body
@ -510,6 +516,12 @@ class EnforcementPointDef(ResourceDef):
body['connection_info'][body_attr] = kwargs[attr]
del kwargs[attr]
for attr in ('edge_cluster_id', 'transport_zone_id'):
if kwargs.get(attr) is not None:
body_attr = attr + 's'
body['connection_info'][body_attr] = [kwargs[attr]]
del kwargs[attr]
super(EnforcementPointDef, self).update_attributes_in_body(
body=body, **kwargs)

View File

@ -583,6 +583,7 @@ class NsxPolicyEnforcementPointApi(NsxPolicyResourceBase):
def create_or_overwrite(self, name, ep_id=None, description=None,
ip_address=None, username=None,
password=None, thumbprint=None,
edge_cluster_id=None, transport_zone_id=None,
tenant=policy_constants.POLICY_INFRA_TENANT):
if not ip_address or not username or password is None:
err_msg = (_("Cannot create an enforcement point without "
@ -597,6 +598,8 @@ class NsxPolicyEnforcementPointApi(NsxPolicyResourceBase):
username=username,
password=password,
thumbprint=thumbprint,
edge_cluster_id=edge_cluster_id,
transport_zone_id=transport_zone_id,
tenant=tenant)
return self.policy_api.create_or_update(ep_def)
@ -619,6 +622,7 @@ class NsxPolicyEnforcementPointApi(NsxPolicyResourceBase):
def update(self, ep_id, name=None, description=None,
ip_address=None, username=None,
password=None, thumbprint=None,
edge_cluster_id=None, transport_zone_id=None,
tenant=policy_constants.POLICY_INFRA_TENANT):
"""Update the enforcement point.
@ -638,6 +642,8 @@ class NsxPolicyEnforcementPointApi(NsxPolicyResourceBase):
ip_address=ip_address,
username=username,
password=password,
edge_cluster_id=edge_cluster_id,
transport_zone_id=transport_zone_id,
thumbprint=thumbprint)
# update the backend
return self.policy_api.create_or_update(ep_def)