Rename URL components for native DHCP support
Also update metadata route (with VM's IP as next_hop) when users change the IP of a VM. Change-Id: Iab1daee0c6a0c4f45b6a057cc5c52e7a23551a5a
This commit is contained in:
parent
03eea64ef9
commit
90301b487b
@ -440,19 +440,6 @@ class LogicalRouterPort(AbstractRESTResource):
|
||||
operation="get router link port")
|
||||
|
||||
|
||||
class DhcpProfile(AbstractRESTResource):
|
||||
|
||||
@property
|
||||
def uri_segment(self):
|
||||
return 'dhcp/server-profiles'
|
||||
|
||||
def create(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def update(self, uuid, *args, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
class MetaDataProxy(AbstractRESTResource):
|
||||
|
||||
@property
|
||||
@ -466,11 +453,24 @@ class MetaDataProxy(AbstractRESTResource):
|
||||
pass
|
||||
|
||||
|
||||
class DhcpProfile(AbstractRESTResource):
|
||||
|
||||
@property
|
||||
def uri_segment(self):
|
||||
return 'dhcp/server-profiles'
|
||||
|
||||
def create(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def update(self, uuid, *args, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
class LogicalDhcpServer(AbstractRESTResource):
|
||||
|
||||
@property
|
||||
def uri_segment(self):
|
||||
return 'dhcp/services'
|
||||
return 'dhcp/servers'
|
||||
|
||||
def _construct_server(self, body, dhcp_profile_id=None, server_ip=None,
|
||||
dns_servers=None, domain_name=None, gateway_ip=None,
|
||||
@ -517,11 +517,11 @@ class LogicalDhcpServer(AbstractRESTResource):
|
||||
body['lease_time'] = lease_time
|
||||
if options:
|
||||
body['options'] = options
|
||||
url = "%s/bindings" % server_uuid
|
||||
url = "%s/static-bindings" % server_uuid
|
||||
return self._client.url_post(url, body)
|
||||
|
||||
def get_binding(self, server_uuid, binding_uuid):
|
||||
url = "%s/bindings/%s" % (server_uuid, binding_uuid)
|
||||
url = "%s/static-bindings/%s" % (server_uuid, binding_uuid)
|
||||
return self._client.url_get(url)
|
||||
|
||||
@utils.retry_upon_exception_nsxv3(
|
||||
@ -530,9 +530,9 @@ class LogicalDhcpServer(AbstractRESTResource):
|
||||
def update_binding(self, server_uuid, binding_uuid, **kwargs):
|
||||
body = self.get_binding(server_uuid, binding_uuid)
|
||||
body.update(kwargs)
|
||||
url = "%s/bindings/%s" % (server_uuid, binding_uuid)
|
||||
url = "%s/static-bindings/%s" % (server_uuid, binding_uuid)
|
||||
return self._client.url_put(url, body)
|
||||
|
||||
def delete_binding(self, server_uuid, binding_uuid):
|
||||
url = "%s/bindings/%s" % (server_uuid, binding_uuid)
|
||||
url = "%s/static-bindings/%s" % (server_uuid, binding_uuid)
|
||||
return self._client.url_delete(url)
|
||||
|
@ -1459,7 +1459,8 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
bindings = nsx_db.get_nsx_dhcp_bindings(context.session,
|
||||
old_port['id'])
|
||||
if ip_change:
|
||||
# If IP address is changed, update associated DHCP bindings.
|
||||
# If IP address is changed, update associated DHCP bindings,
|
||||
# metadata route, and default hostname.
|
||||
# Mac address (if changed) will be updated at the same time.
|
||||
if ([subnet_id for (subnet_id, ip) in ips_to_add] ==
|
||||
[subnet_id for (subnet_id, ip) in ips_to_delete]):
|
||||
@ -1496,9 +1497,14 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
|
||||
def _update_dhcp_binding_on_server(self, context, binding, mac, ip):
|
||||
try:
|
||||
data = {'mac_address': mac, 'ip_address': ip}
|
||||
if ip != binding['ip_address']:
|
||||
data['host_name'] = 'host-%s' % ip.replace('.', '-')
|
||||
data['options'] = {'option121': {'static_routes': [
|
||||
{'network': '%s' % nsx_rpc.METADATA_DHCP_ROUTE,
|
||||
'next_hop': ip}]}}
|
||||
self._dhcp_server.update_binding(
|
||||
binding['nsx_service_id'], binding['nsx_binding_id'],
|
||||
mac_address=mac, ip_address=ip)
|
||||
binding['nsx_service_id'], binding['nsx_binding_id'], **data)
|
||||
LOG.info(_LI("Updated static binding (mac: %(mac)s, ip: %(ip)s) "
|
||||
"for port %(port)s on logical DHCP server "
|
||||
"%(server)s"),
|
||||
|
@ -1050,7 +1050,11 @@ class NsxNativeDhcpTestCase(NsxV3PluginTestCaseMixin):
|
||||
new_ip = '10.0.0.4'
|
||||
update_data = {'port': {'fixed_ips': [
|
||||
{'subnet_id': subnet['subnet']['id'], 'ip_address': new_ip}]}}
|
||||
assert_data = {'ip_address': new_ip}
|
||||
assert_data = {'host_name': 'host-%s' % new_ip.replace('.', '-'),
|
||||
'ip_address': new_ip,
|
||||
'options': {'option121': {'static_routes': [
|
||||
{'network': '%s' % nsx_rpc.METADATA_DHCP_ROUTE,
|
||||
'next_hop': new_ip}]}}}
|
||||
self._verify_dhcp_binding(subnet, port_data, update_data,
|
||||
assert_data)
|
||||
|
||||
@ -1076,7 +1080,12 @@ class NsxNativeDhcpTestCase(NsxV3PluginTestCaseMixin):
|
||||
new_ip = '10.0.0.4'
|
||||
update_data = {'port': {'mac_address': new_mac, 'fixed_ips': [
|
||||
{'subnet_id': subnet['subnet']['id'], 'ip_address': new_ip}]}}
|
||||
assert_data = {'mac_address': new_mac, 'ip_address': new_ip}
|
||||
assert_data = {'host_name': 'host-%s' % new_ip.replace('.', '-'),
|
||||
'mac_address': new_mac,
|
||||
'ip_address': new_ip,
|
||||
'options': {'option121': {'static_routes': [
|
||||
{'network': '%s' % nsx_rpc.METADATA_DHCP_ROUTE,
|
||||
'next_hop': new_ip}]}}}
|
||||
self._verify_dhcp_binding(subnet, port_data, update_data,
|
||||
assert_data)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user