Merge "Implement create with specified neutron net"
This commit is contained in:
commit
6efdfcad4f
@ -302,13 +302,19 @@ class ContainersController(base.Controller):
|
|||||||
neutron_api = neutron.NeutronAPI(context)
|
neutron_api = neutron.NeutronAPI(context)
|
||||||
requested_networks = []
|
requested_networks = []
|
||||||
for net in nets:
|
for net in nets:
|
||||||
if 'port' in net:
|
if net.get('port'):
|
||||||
port = neutron_api.get_neutron_port(net['port'])
|
port = neutron_api.get_neutron_port(net['port'])
|
||||||
neutron_api.ensure_neutron_port_usable(port)
|
neutron_api.ensure_neutron_port_usable(port)
|
||||||
requested_networks.append({'network': port['network_id'],
|
requested_networks.append({'network': port['network_id'],
|
||||||
'port': port['id'],
|
'port': port['id'],
|
||||||
'v4-fixed-ip': '',
|
'v4-fixed-ip': '',
|
||||||
'v6-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:
|
if not requested_networks:
|
||||||
# Find an available neutron net and create docker network by
|
# Find an available neutron net and create docker network by
|
||||||
|
@ -36,6 +36,22 @@ class NeutronAPI(object):
|
|||||||
nets.sort(key=lambda x: x['created_at'])
|
nets.sort(key=lambda x: x['created_at'])
|
||||||
return nets[0]
|
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):
|
def get_neutron_port(self, port):
|
||||||
if uuidutils.is_uuid_like(port):
|
if uuidutils.is_uuid_like(port):
|
||||||
ports = self.list_ports(id=port)['ports']
|
ports = self.list_ports(id=port)['ports']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user