Fixed issues post testing.

This commit is contained in:
chouseknecht 2016-05-30 15:04:43 -04:00
parent 8cd028bd8e
commit 3292121e6d
No known key found for this signature in database
GPG key ID: 78F1698C5705A81B

View file

@ -689,8 +689,8 @@ class TaskParameters(DockerBaseClass):
for network in self.networks: for network in self.networks:
if not network.get('name'): if not network.get('name'):
self.fail("Parameter error: network must have a name attribute.") self.fail("Parameter error: network must have a name attribute.")
id = self._get_network_id(network['name']) network['id'] = self._get_network_id(network['name'])
if not id: if not network['id']:
self.fail("Parameter error: network named %s could not be found. Does it exist?" % network['name']) self.fail("Parameter error: network named %s could not be found. Does it exist?" % network['name'])
def fail(self, msg): def fail(self, msg):
@ -1231,13 +1231,14 @@ class Container(DockerBaseClass):
if network.get('ipv6_address') and network['ipv6_address'] != connected_networks[network['name']].get('GlobalIPv6Address'): if network.get('ipv6_address') and network['ipv6_address'] != connected_networks[network['name']].get('GlobalIPv6Address'):
diff = True diff = True
if network.get('aliases') and network['aliases'] != connected_networks[network['name']].get('Aliases'): if network.get('aliases') and network['aliases'] != connected_networks[network['name']].get('Aliases'):
self.log('network aliases different')
diff = True diff = True
if network.get('links') and network['links'] != connected_networks[network['name']].get('Links'): if network.get('links') and network['links'] != connected_networks[network['name']].get('Links'):
diff = True diff = True
if diff: if diff:
different = True different = True
differences.append(dict( differences.append(dict(
prarameter=network, parameter=network,
container=dict( container=dict(
name=network['name'], name=network['name'],
ipv4_address=connected_networks[network['name']].get('IPAddress'), ipv4_address=connected_networks[network['name']].get('IPAddress'),
@ -1246,6 +1247,7 @@ class Container(DockerBaseClass):
links=connected_networks[network['name']].get('Links') links=connected_networks[network['name']].get('Links')
) )
)) ))
self.log(differences, pretty_print=True)
return different, differences return different, differences
def has_extra_networks(self): def has_extra_networks(self):
@ -1268,7 +1270,7 @@ class Container(DockerBaseClass):
keep = True keep = True
if not keep: if not keep:
extra = True extra = True
extra_networks.append(dict(name=netowork, id=network_config['NetworkID'])) extra_networks.append(dict(name=network, id=network_config['NetworkID']))
return extra, extra_networks return extra, extra_networks
def _get_expected_entrypoint(self, image): def _get_expected_entrypoint(self, image):
@ -1480,25 +1482,7 @@ class ContainerManager(DockerBaseClass):
self.diff['image_different'] = True self.diff['image_different'] = True
container = self.update_limits(container) container = self.update_limits(container)
container = self.update_networks(container)
has_network_differences, network_differences = container.has_network_differences()
if has_network_differences:
if self.diff.get('differences'):
self.diff['differences'].append(dict(network_differences=network_differences))
else:
self.diff['differences'] = dict(network_differences=network_differences)
self.results['changed'] = True
container = self.update_networks(container, network_differences)
if self.parameters.purge_networks:
has_extra_networks, extra_networks = container.has_extra_networks()
if has_extra_networks:
if self.diff.get('differences'):
self.diff['differences'].append(dict(purge_networks=extra_networks))
else:
self.diff['differences'] = dict(purge_networks=extra_networks)
self.results['changed'] = True
container = self.remove_networks(container, extra_networks)
if state == 'started' and not container.running: if state == 'started' and not container.running:
container = self.container_start(container.Id) container = self.container_start(container.Id)
@ -1562,7 +1546,29 @@ class ContainerManager(DockerBaseClass):
return self._get_container(container.Id) return self._get_container(container.Id)
return container return container
def update_networks(self, container, differences): def update_networks(self, container):
has_network_differences, network_differences = container.has_network_differences()
updated_container = container
if has_network_differences:
if self.diff.get('differences'):
self.diff['differences'].append(dict(network_differences=network_differences))
else:
self.diff['differences'] = dict(network_differences=network_differences)
self.results['changed'] = True
updated_container = self._add_networks(container, network_differences)
if self.parameters.purge_networks:
has_extra_networks, extra_networks = container.has_extra_networks()
if has_extra_networks:
if self.diff.get('differences'):
self.diff['differences'].append(dict(purge_networks=extra_networks))
else:
self.diff['differences'] = dict(purge_networks=extra_networks)
self.results['changed'] = True
updated_container = self._purge_networks(container, extra_networks)
return updated_container
def _add_networks(self, container, differences):
for diff in differences: for diff in differences:
# remove the container from the network, if connected # remove the container from the network, if connected
if diff.get('container'): if diff.get('container'):
@ -1582,13 +1588,16 @@ class ContainerManager(DockerBaseClass):
) )
self.results['actions'].append(dict(added_to_network=diff['parameter']['name'], network_parameters=params)) self.results['actions'].append(dict(added_to_network=diff['parameter']['name'], network_parameters=params))
if not self.check_mode: if not self.check_mode:
self.log("network diffs:")
self.log(diff, pretty_print=True)
try: try:
self.log("Connecting conainer to network %s" % diff['parameter']['id'])
self.client.connect_container_to_network(container.Id, diff['parameter']['id'], **params) self.client.connect_container_to_network(container.Id, diff['parameter']['id'], **params)
except Exception, exc: except Exception, exc:
self.fail("Error connecting container to network %s - %s" % (diff['parameter']['name'], str(exc))) self.fail("Error connecting container to network %s - %s" % (diff['parameter']['name'], str(exc)))
return self._get_container(container.Id) return self._get_container(container.Id)
def remove_networks(self, container, networks): def _purge_networks(self, container, networks):
for network in networks: for network in networks:
self.results['actions'].append(dict(removed_from_network=network['name'])) self.results['actions'].append(dict(removed_from_network=network['name']))
if not self.check_mode: if not self.check_mode: