Merge "Set binding:host_id on creating/updating port"

This commit is contained in:
Zuul 2019-02-14 04:06:29 +00:00 committed by Gerrit Code Review
commit 559065b007
3 changed files with 24 additions and 6 deletions

View File

@ -379,7 +379,8 @@ class DockerDriver(driver.ContainerDriver):
security_group_ids = utils.get_security_group_ids(
context, container.security_groups)
addresses, port = network_api.create_or_update_port(
container, docker_net_name, requested_network, security_group_ids)
container, docker_net_name, requested_network, security_group_ids,
set_binding_host=True)
container.addresses = {requested_network['network']: addresses}
ipv4_address = None
@ -1225,8 +1226,8 @@ class DockerDriver(driver.ContainerDriver):
network = requested_network['network']
if network in container.addresses:
raise exception.ZunException('Container %(container)s has '
'alreay connected to the network '
'%(network)s.'
'already connected to the '
'network %(network)s.'
% {'container': container.uuid,
'network': network})
self._get_or_create_docker_network(context, network_api, network)

View File

@ -36,6 +36,7 @@ LOG = logging.getLogger(__name__)
BINDING_PROFILE = 'binding:profile'
BINDING_HOST_ID = 'binding:host_id'
DEVICE_OWNER = 'compute:kuryr'
class KuryrNetwork(network.Network):
@ -201,13 +202,18 @@ class KuryrNetwork(network.Network):
return self.docker.networks(**kwargs)
def create_or_update_port(self, container, network_name,
requested_network, security_groups=None):
requested_network, security_groups=None,
set_binding_host=False):
if requested_network.get('port'):
neutron_port_id = requested_network.get('port')
neutron_port = self.neutron_api.get_neutron_port(neutron_port_id)
# update device_id in port
port_req_body = {'port': {'device_id': container.uuid}}
self.neutron_api.update_port(neutron_port_id, port_req_body)
if set_binding_host:
port_req_body['port']['device_owner'] = DEVICE_OWNER
port_req_body['port'][BINDING_HOST_ID] = container.host
self.neutron_api.update_port(neutron_port_id, port_req_body,
admin=True)
# If there is pci_request_id, it should be a sriov port.
# populate pci related info.
@ -232,12 +238,16 @@ class KuryrNetwork(network.Network):
'tenant_id': self.context.project_id,
'device_id': container.uuid,
}
if set_binding_host:
port_dict['device_owner'] = DEVICE_OWNER
port_dict[BINDING_HOST_ID] = container.host
ip_addr = requested_network.get("fixed_ip")
if ip_addr:
port_dict['fixed_ips'] = [{'ip_address': ip_addr}]
if security_groups is not None:
port_dict['security_groups'] = security_groups
neutron_port = self.neutron_api.create_port({'port': port_dict})
neutron_port = self.neutron_api.create_port({'port': port_dict},
admin=True)
neutron_port = neutron_port['port']
preserve_on_delete = requested_network['preserve_on_delete']

View File

@ -48,6 +48,13 @@ class NeutronAPI(object):
client = self.client
return client.update_port(port, body)
def create_port(self, body=None, admin=False):
if admin:
client = self._get_admin_client()
else:
client = self.client
return client.create_port(body)
def find_resourceid_by_name_or_id(self, resource, name_or_id,
project_id=None):
return neutronv20.find_resourceid_by_name_or_id(