Merge "Implement create with specified neutron net"

This commit is contained in:
Jenkins 2017-08-14 15:18:09 +00:00 committed by Gerrit Code Review
commit 6efdfcad4f
2 changed files with 23 additions and 1 deletions

View File

@ -302,13 +302,19 @@ class ContainersController(base.Controller):
neutron_api = neutron.NeutronAPI(context)
requested_networks = []
for net in nets:
if 'port' in net:
if net.get('port'):
port = neutron_api.get_neutron_port(net['port'])
neutron_api.ensure_neutron_port_usable(port)
requested_networks.append({'network': port['network_id'],
'port': port['id'],
'v4-fixed-ip': '',
'v6-fixed-ip': ''})
elif net.get('network'):
network = neutron_api.get_neutron_network(net['network'])
requested_networks.append({'network': network['id'],
'port': '',
'v4-fixed-ip': '',
'v6-fixed-ip': ''})
if not requested_networks:
# Find an available neutron net and create docker network by

View File

@ -36,6 +36,22 @@ class NeutronAPI(object):
nets.sort(key=lambda x: x['created_at'])
return nets[0]
def get_neutron_network(self, network):
if uuidutils.is_uuid_like(network):
networks = self.neutron.list_networks(id=network)['networks']
else:
networks = self.neutron.list_networks(name=network)['networks']
if len(networks) == 0:
raise exception.NetworkNotFound(network=network)
elif len(networks) > 1:
raise exception.Conflict(_(
'Multiple neutron networks exist with same name. '
'Please use the uuid instead.'))
network = networks[0]
return network
def get_neutron_port(self, port):
if uuidutils.is_uuid_like(port):
ports = self.list_ports(id=port)['ports']