Update interface about NSX IPAM and CIF API change
Change-Id: I224b8778cbb519ec9bc4ebebf9f1b3fbf4326b4d
This commit is contained in:
parent
96aa73b17c
commit
f601978eda
@ -69,12 +69,14 @@ FAKE_CONTAINER_PORT = {
|
|||||||
"admin_state": "UP",
|
"admin_state": "UP",
|
||||||
"attachment": {
|
"attachment": {
|
||||||
"id": "9ca8d413-f7bf-4276-b4c9-62f42516bdb2",
|
"id": "9ca8d413-f7bf-4276-b4c9-62f42516bdb2",
|
||||||
"attachment_type": "CIF",
|
"attachment_type": "VIF",
|
||||||
"context": {
|
"context": {
|
||||||
"vlan_tag": 122,
|
"vlan_tag": 122,
|
||||||
"container_host_vif_id": "c6f817a0-4e36-421e-98a6-8a2faed880bc",
|
"container_host_vif_id": "c6f817a0-4e36-421e-98a6-8a2faed880bc",
|
||||||
"key_values": [],
|
"resource_type": "VifAttachmentContext",
|
||||||
"resource_type": "CifAttachmentContext",
|
"app_id": "container-1",
|
||||||
|
"vif_type": "CHILD",
|
||||||
|
"allocate_addresses": "Both",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"switching_profile_ids": [
|
"switching_profile_ids": [
|
||||||
|
@ -319,21 +319,26 @@ class LogicalPortTestCase(nsxlib_testcase.NsxClientTestCase):
|
|||||||
fake_port['logical_switch_id'],
|
fake_port['logical_switch_id'],
|
||||||
fake_port['attachment']['id'],
|
fake_port['attachment']['id'],
|
||||||
parent_vif_id=fake_container_host_vif_id,
|
parent_vif_id=fake_container_host_vif_id,
|
||||||
parent_tag=fake_port_ctx['vlan_tag'],
|
traffic_tag=fake_port_ctx['vlan_tag'],
|
||||||
address_bindings=pkt_classifiers,
|
address_bindings=pkt_classifiers,
|
||||||
switch_profile_ids=switch_profile.build_switch_profile_ids(
|
switch_profile_ids=switch_profile.build_switch_profile_ids(
|
||||||
mock.Mock(), *profile_dicts))
|
mock.Mock(), *profile_dicts),
|
||||||
|
vif_type=fake_port_ctx['vif_type'], app_id=fake_port_ctx['app_id'],
|
||||||
|
allocate_addresses=fake_port_ctx['allocate_addresses'])
|
||||||
|
|
||||||
resp_body = {
|
resp_body = {
|
||||||
'logical_switch_id': fake_port['logical_switch_id'],
|
'logical_switch_id': fake_port['logical_switch_id'],
|
||||||
'switching_profile_ids': fake_port['switching_profile_ids'],
|
'switching_profile_ids': fake_port['switching_profile_ids'],
|
||||||
'attachment': {
|
'attachment': {
|
||||||
'attachment_type': 'CIF',
|
'attachment_type': 'VIF',
|
||||||
'id': fake_port['attachment']['id'],
|
'id': fake_port['attachment']['id'],
|
||||||
'context': {
|
'context': {
|
||||||
'vlan_tag': fake_port_ctx['vlan_tag'],
|
'resource_type': 'VifAttachmentContext',
|
||||||
'container_host_vif_id': fake_container_host_vif_id,
|
'allocate_addresses': 'Both',
|
||||||
'resource_type': 'CifAttachmentContext'
|
'parent_vif_id': fake_container_host_vif_id,
|
||||||
|
'traffic_tag': fake_port_ctx['vlan_tag'],
|
||||||
|
'app_id': fake_port_ctx['app_id'],
|
||||||
|
'vif_type': 'CHILD',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'admin_state': 'UP',
|
'admin_state': 'UP',
|
||||||
@ -345,55 +350,6 @@ class LogicalPortTestCase(nsxlib_testcase.NsxClientTestCase):
|
|||||||
'https://1.2.3.4/api/v1/logical-ports',
|
'https://1.2.3.4/api/v1/logical-ports',
|
||||||
data=jsonutils.dumps(resp_body, sort_keys=True))
|
data=jsonutils.dumps(resp_body, sort_keys=True))
|
||||||
|
|
||||||
def test_create_logical_port_for_container_with_ip_pool_key_value(self):
|
|
||||||
"""Test creating for container port returns correct response
|
|
||||||
|
|
||||||
"""
|
|
||||||
fake_port = test_constants.FAKE_CONTAINER_PORT.copy()
|
|
||||||
fake_port_ctx = fake_port['attachment']['context']
|
|
||||||
fake_container_host_vif_id = fake_port_ctx['container_host_vif_id']
|
|
||||||
profile_dicts = []
|
|
||||||
for profile_id in fake_port['switching_profile_ids']:
|
|
||||||
profile_dicts.append({'resource_type': profile_id['key'],
|
|
||||||
'id': profile_id['value']})
|
|
||||||
|
|
||||||
key_values = [{'key': 'IP_POOL_ID',
|
|
||||||
'value': test_constants.FAKE_IP_POOL_UUID}]
|
|
||||||
|
|
||||||
mocked_resource = self._mocked_lport()
|
|
||||||
|
|
||||||
switch_profile = resources.SwitchingProfile
|
|
||||||
mocked_resource.create(
|
|
||||||
fake_port['logical_switch_id'],
|
|
||||||
fake_port['attachment']['id'],
|
|
||||||
parent_vif_id=fake_container_host_vif_id,
|
|
||||||
parent_tag=[],
|
|
||||||
switch_profile_ids=switch_profile.build_switch_profile_ids(
|
|
||||||
mock.Mock(), *profile_dicts),
|
|
||||||
key_values=key_values)
|
|
||||||
|
|
||||||
resp_body = {
|
|
||||||
'logical_switch_id': fake_port['logical_switch_id'],
|
|
||||||
'switching_profile_ids': fake_port['switching_profile_ids'],
|
|
||||||
'attachment': {
|
|
||||||
'attachment_type': 'CIF',
|
|
||||||
'id': fake_port['attachment']['id'],
|
|
||||||
'context': {
|
|
||||||
'container_host_vif_id': fake_container_host_vif_id,
|
|
||||||
'resource_type': 'CifAttachmentContext',
|
|
||||||
'vlan_tag': [],
|
|
||||||
'key_values': key_values
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'admin_state': 'UP',
|
|
||||||
'address_bindings': []
|
|
||||||
}
|
|
||||||
|
|
||||||
test_client.assert_json_call(
|
|
||||||
'post', mocked_resource,
|
|
||||||
'https://1.2.3.4/api/v1/logical-ports',
|
|
||||||
data=jsonutils.dumps(resp_body, sort_keys=True))
|
|
||||||
|
|
||||||
def test_create_logical_port_admin_down(self):
|
def test_create_logical_port_admin_down(self):
|
||||||
"""Test creating port with admin_state down."""
|
"""Test creating port with admin_state down."""
|
||||||
fake_port = test_constants.FAKE_PORT
|
fake_port = test_constants.FAKE_PORT
|
||||||
|
@ -168,7 +168,8 @@ class NsxLibLogicalSwitch(utils.NsxLibApiBase):
|
|||||||
|
|
||||||
def create(self, display_name, transport_zone_id, tags,
|
def create(self, display_name, transport_zone_id, tags,
|
||||||
replication_mode=nsx_constants.MTEP,
|
replication_mode=nsx_constants.MTEP,
|
||||||
admin_state=True, vlan_id=None):
|
admin_state=True, vlan_id=None, ip_pool_id=None,
|
||||||
|
mac_pool_id=None):
|
||||||
# TODO(salv-orlando): Validate Replication mode and admin_state
|
# TODO(salv-orlando): Validate Replication mode and admin_state
|
||||||
# NOTE: These checks might be moved to the API client library if one
|
# NOTE: These checks might be moved to the API client library if one
|
||||||
# that performs such checks in the client is available
|
# that performs such checks in the client is available
|
||||||
@ -187,6 +188,12 @@ class NsxLibLogicalSwitch(utils.NsxLibApiBase):
|
|||||||
if vlan_id:
|
if vlan_id:
|
||||||
body['vlan'] = vlan_id
|
body['vlan'] = vlan_id
|
||||||
|
|
||||||
|
if ip_pool_id:
|
||||||
|
body['ip_pool_id'] = ip_pool_id
|
||||||
|
|
||||||
|
if mac_pool_id:
|
||||||
|
body['mac_pool_id'] = mac_pool_id
|
||||||
|
|
||||||
return self.client.create(resource, body)
|
return self.client.create(resource, body)
|
||||||
|
|
||||||
def delete(self, lswitch_id):
|
def delete(self, lswitch_id):
|
||||||
@ -495,17 +502,18 @@ class NsxLibIpBlockSubnet(utils.NsxLibApiBase):
|
|||||||
|
|
||||||
def create(self, ip_block_id, subnet_size):
|
def create(self, ip_block_id, subnet_size):
|
||||||
"""Create a IP block subnet on the backend."""
|
"""Create a IP block subnet on the backend."""
|
||||||
resource = 'pools/ip-blocks/%s/subnets' % ip_block_id
|
resource = 'pools/ip-subnets'
|
||||||
body = {'size': subnet_size}
|
body = {'size': subnet_size,
|
||||||
|
'block_id': ip_block_id}
|
||||||
return self.client.create(resource, body)
|
return self.client.create(resource, body)
|
||||||
|
|
||||||
def delete(self, ip_block_id, subnet_id):
|
def delete(self, subnet_id):
|
||||||
"""Delete a IP block subnet on the backend."""
|
"""Delete a IP block subnet on the backend."""
|
||||||
resource = 'pools/ip-blocks/%s/subnets/%s' % (ip_block_id, subnet_id)
|
resource = 'pools/ip-subnets/%s' % subnet_id
|
||||||
self.client.delete(resource)
|
self.client.delete(resource)
|
||||||
|
|
||||||
def list(self, ip_block_id):
|
def list(self, ip_block_id):
|
||||||
resource = 'pools/ip-blocks/%s/subnets' % ip_block_id
|
resource = 'pools/ip-subnets?block_id=%s' % ip_block_id
|
||||||
return self.client.get(resource)
|
return self.client.get(resource)
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,12 +22,13 @@ MTEP = "MTEP"
|
|||||||
|
|
||||||
# Port attachment types
|
# Port attachment types
|
||||||
ATTACHMENT_VIF = "VIF"
|
ATTACHMENT_VIF = "VIF"
|
||||||
ATTACHMENT_CIF = "CIF"
|
|
||||||
ATTACHMENT_LR = "LOGICALROUTER"
|
ATTACHMENT_LR = "LOGICALROUTER"
|
||||||
ATTACHMENT_DHCP = "DHCP_SERVICE"
|
ATTACHMENT_DHCP = "DHCP_SERVICE"
|
||||||
ATTACHMENT_MDPROXY = "METADATA_PROXY"
|
ATTACHMENT_MDPROXY = "METADATA_PROXY"
|
||||||
|
|
||||||
CIF_RESOURCE_TYPE = "CifAttachmentContext"
|
VIF_RESOURCE_TYPE = "VifAttachmentContext"
|
||||||
|
|
||||||
|
ALLOCATE_ADDRESS_NONE = "None"
|
||||||
|
|
||||||
# NSXv3 L2 Gateway constants
|
# NSXv3 L2 Gateway constants
|
||||||
BRIDGE_ENDPOINT = "BRIDGEENDPOINT"
|
BRIDGE_ENDPOINT = "BRIDGEENDPOINT"
|
||||||
|
@ -244,17 +244,20 @@ class LogicalPort(AbstractRESTResource):
|
|||||||
|
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def _prepare_attachment(self, vif_uuid, parent_vif_id, parent_tag,
|
def _prepare_attachment(self, attachment_type, vif_uuid,
|
||||||
address_bindings, attachment_type, key_values):
|
allocate_addresses, vif_type,
|
||||||
|
parent_vif_id, traffic_tag, app_id):
|
||||||
if attachment_type and vif_uuid:
|
if attachment_type and vif_uuid:
|
||||||
attachment = {'attachment_type': attachment_type,
|
attachment = {'attachment_type': attachment_type,
|
||||||
'id': vif_uuid}
|
'id': vif_uuid}
|
||||||
if parent_vif_id:
|
if vif_type:
|
||||||
context = {'vlan_tag': parent_tag,
|
context = {'resource_type': nsx_constants.VIF_RESOURCE_TYPE,
|
||||||
'container_host_vif_id': parent_vif_id,
|
'allocate_addresses': allocate_addresses,
|
||||||
'resource_type': nsx_constants.CIF_RESOURCE_TYPE}
|
'vif_type': vif_type}
|
||||||
if key_values is not None:
|
if parent_vif_id:
|
||||||
context['key_values'] = key_values
|
context['parent_vif_id'] = parent_vif_id
|
||||||
|
context['traffic_tag'] = traffic_tag
|
||||||
|
context['app_id'] = app_id
|
||||||
attachment['context'] = context
|
attachment['context'] = context
|
||||||
return attachment
|
return attachment
|
||||||
elif attachment_type is None and vif_uuid is None:
|
elif attachment_type is None and vif_uuid is None:
|
||||||
@ -273,18 +276,18 @@ class LogicalPort(AbstractRESTResource):
|
|||||||
def create(self, lswitch_id, vif_uuid, tags=None,
|
def create(self, lswitch_id, vif_uuid, tags=None,
|
||||||
attachment_type=nsx_constants.ATTACHMENT_VIF,
|
attachment_type=nsx_constants.ATTACHMENT_VIF,
|
||||||
admin_state=True, name=None, address_bindings=None,
|
admin_state=True, name=None, address_bindings=None,
|
||||||
parent_vif_id=None, parent_tag=None,
|
parent_vif_id=None, traffic_tag=None,
|
||||||
switch_profile_ids=None, key_values=None):
|
switch_profile_ids=None, vif_type=None, app_id=None,
|
||||||
|
allocate_addresses=nsx_constants.ALLOCATE_ADDRESS_NONE):
|
||||||
tags = tags or []
|
tags = tags or []
|
||||||
|
|
||||||
body = {'logical_switch_id': lswitch_id}
|
body = {'logical_switch_id': lswitch_id}
|
||||||
# NOTE(arosen): If parent_vif_id is specified we need to use
|
# NOTE(arosen): If parent_vif_id is specified we need to use
|
||||||
# CIF attachment type.
|
# CIF attachment type.
|
||||||
if parent_vif_id:
|
attachment = self._prepare_attachment(attachment_type, vif_uuid,
|
||||||
attachment_type = nsx_constants.ATTACHMENT_CIF
|
allocate_addresses, vif_type,
|
||||||
attachment = self._prepare_attachment(vif_uuid, parent_vif_id,
|
parent_vif_id, traffic_tag,
|
||||||
parent_tag, address_bindings,
|
app_id)
|
||||||
attachment_type, key_values)
|
|
||||||
body.update(self._build_body_attrs(
|
body.update(self._build_body_attrs(
|
||||||
display_name=name,
|
display_name=name,
|
||||||
admin_state=admin_state, tags=tags,
|
admin_state=admin_state, tags=tags,
|
||||||
@ -308,7 +311,9 @@ class LogicalPort(AbstractRESTResource):
|
|||||||
address_bindings=None, switch_profile_ids=None,
|
address_bindings=None, switch_profile_ids=None,
|
||||||
tags_update=None,
|
tags_update=None,
|
||||||
attachment_type=nsx_constants.ATTACHMENT_VIF,
|
attachment_type=nsx_constants.ATTACHMENT_VIF,
|
||||||
parent_vif_id=None, parent_tag=None, key_values=None):
|
parent_vif_id=None, traffic_tag=None,
|
||||||
|
vif_type=None, app_id=None,
|
||||||
|
allocate_addresses=nsx_constants.ALLOCATE_ADDRESS_NONE):
|
||||||
# Using internal method so we can access max_attempts in the decorator
|
# Using internal method so we can access max_attempts in the decorator
|
||||||
@utils.retry_upon_exception(
|
@utils.retry_upon_exception(
|
||||||
exceptions.StaleRevision,
|
exceptions.StaleRevision,
|
||||||
@ -323,9 +328,10 @@ class LogicalPort(AbstractRESTResource):
|
|||||||
if addr_bindings is None:
|
if addr_bindings is None:
|
||||||
addr_bindings = self._build_address_bindings(
|
addr_bindings = self._build_address_bindings(
|
||||||
lport.get('address_bindings'))
|
lport.get('address_bindings'))
|
||||||
attachment = self._prepare_attachment(vif_uuid, parent_vif_id,
|
attachment = self._prepare_attachment(attachment_type, vif_uuid,
|
||||||
parent_tag, addr_bindings,
|
allocate_addresses, vif_type,
|
||||||
attachment_type, key_values)
|
parent_vif_id, traffic_tag,
|
||||||
|
app_id)
|
||||||
lport.update(self._build_body_attrs(
|
lport.update(self._build_body_attrs(
|
||||||
display_name=name,
|
display_name=name,
|
||||||
admin_state=admin_state, tags=tags,
|
admin_state=admin_state, tags=tags,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user