Optimize connect_container_to_network
In before, this method takes sandbox_id as a parameter, but we are going to make sandbox optional soon. This commit changes the interface to take a container object as a parameter and take sandbox_id as an optional parameter Change-Id: If29e0cbc64a42b1f039ade86d7924a6f54e548cb Partial-Implements: blueprint make-sandbox-optional
This commit is contained in:
parent
368ce78d74
commit
6a95bebb2c
@ -584,9 +584,11 @@ class DockerDriver(driver.ContainerDriver):
|
|||||||
container, 'bridge', sandbox_id=sandbox['Id'])
|
container, 'bridge', sandbox_id=sandbox['Id'])
|
||||||
addresses = {}
|
addresses = {}
|
||||||
for network in requested_networks:
|
for network in requested_networks:
|
||||||
|
network_name = network['network']
|
||||||
addrs = network_api.connect_container_to_network(
|
addrs = network_api.connect_container_to_network(
|
||||||
sandbox, network['network'], security_group_ids)
|
container, network_name, sandbox_id=sandbox['Id'],
|
||||||
addresses[network['network']] = addrs
|
security_groups=security_group_ids)
|
||||||
|
addresses[network_name] = addrs
|
||||||
container.addresses = addresses
|
container.addresses = addresses
|
||||||
container.save(context)
|
container.save(context)
|
||||||
|
|
||||||
|
@ -116,20 +116,24 @@ class KuryrNetwork(network.Network):
|
|||||||
return self.docker.networks(**kwargs)
|
return self.docker.networks(**kwargs)
|
||||||
|
|
||||||
def connect_container_to_network(self, container, network_name,
|
def connect_container_to_network(self, container, network_name,
|
||||||
security_group_ids):
|
sandbox_id=None, security_groups=None):
|
||||||
"""Connect container to the network
|
"""Connect container to the network
|
||||||
|
|
||||||
This method will create a neutron port, retrieve the ip address(es)
|
This method will create a neutron port, retrieve the ip address(es)
|
||||||
of the port, and pass them to docker.connect_container_to_network.
|
of the port, and pass them to docker.connect_container_to_network.
|
||||||
"""
|
"""
|
||||||
|
container_id = container.container_id
|
||||||
|
if sandbox_id:
|
||||||
|
container_id = sandbox_id
|
||||||
|
|
||||||
network = self.inspect_network(network_name)
|
network = self.inspect_network(network_name)
|
||||||
neutron_net_id = network['Options']['neutron.net.uuid']
|
neutron_net_id = network['Options']['neutron.net.uuid']
|
||||||
port_dict = {
|
port_dict = {
|
||||||
'network_id': neutron_net_id,
|
'network_id': neutron_net_id,
|
||||||
'tenant_id': self.context.project_id
|
'tenant_id': self.context.project_id
|
||||||
}
|
}
|
||||||
if security_group_ids is not None:
|
if security_groups is not None:
|
||||||
port_dict['security_groups'] = security_group_ids
|
port_dict['security_groups'] = security_groups
|
||||||
neutron_port = self.neutron.create_port({'port': port_dict})
|
neutron_port = self.neutron.create_port({'port': port_dict})
|
||||||
|
|
||||||
ipv4_address = None
|
ipv4_address = None
|
||||||
@ -159,7 +163,7 @@ class KuryrNetwork(network.Network):
|
|||||||
if ipv6_address:
|
if ipv6_address:
|
||||||
kwargs['ipv6_address'] = ipv6_address
|
kwargs['ipv6_address'] = ipv6_address
|
||||||
self.docker.connect_container_to_network(
|
self.docker.connect_container_to_network(
|
||||||
container['Id'], network_name, **kwargs)
|
container_id, network_name, **kwargs)
|
||||||
return addresses
|
return addresses
|
||||||
|
|
||||||
def disconnect_container_from_network(self, container, network_name,
|
def disconnect_container_from_network(self, container, network_name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user