Skip to content
This repository has been archived by the owner on Aug 3, 2020. It is now read-only.

Commit

Permalink
Allow hostname to be set when net is none
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Jellick committed Mar 8, 2016
1 parent 782342c commit 9fafb15
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
9 changes: 6 additions & 3 deletions cattle/plugins/docker/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,12 @@ def _setup_hostname(self, create_config, instance):
def _setup_networking(self, instance, host, create_config, start_config):
client = docker_client()

ports_supported = setup_network_mode(instance, self, client,
create_config, start_config)
setup_mac_and_ip(instance, create_config, set_mac=ports_supported)
ports_supported, hostname_supported = setup_network_mode(instance,
self, client,
create_config,
start_config)
setup_mac_and_ip(instance, create_config, set_mac=ports_supported,
set_hostname=hostname_supported)
setup_ports(instance, create_config, start_config, ports_supported)
setup_links(instance, create_config, start_config)
setup_ipsec(instance, host, create_config, start_config)
Expand Down
10 changes: 7 additions & 3 deletions cattle/plugins/docker/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ def setup_network_mode(instance, compute, client, create_config, start_config):
all other configurations we assume bridge mode
"""
ports_supported = True
hostname_support = True
try:
kind = instance.nics[0].network.kind
if kind == 'dockerHost':
ports_supported = False
hostname_support = False
start_config['network_mode'] = 'host'
del start_config['links']
elif kind == 'dockerNone':
Expand All @@ -27,6 +29,7 @@ def setup_network_mode(instance, compute, client, create_config, start_config):
del start_config['links']
elif kind == 'dockerContainer':
ports_supported = False
hostname_support = False
id = instance.networkContainer.uuid
other = compute.get_container(client, instance.networkContainer)
if other is not None:
Expand All @@ -36,10 +39,10 @@ def setup_network_mode(instance, compute, client, create_config, start_config):
except (KeyError, AttributeError, IndexError):
pass

return ports_supported
return ports_supported, hostname_support


def setup_mac_and_ip(instance, create_config, set_mac=True):
def setup_mac_and_ip(instance, create_config, set_mac=True, set_hostname=True):
"""
Configures the mac address and primary ip address for the the supplied
container. The mac_address is configured directly as part of the native
Expand All @@ -64,7 +67,8 @@ def setup_mac_and_ip(instance, create_config, set_mac=True):

if set_mac:
create_config["mac_address"] = mac_address
else:

if not set_hostname:
del create_config['hostname']

try:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_docker_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ def test_network_mode_none(agent, responses):
def pre(req):
instance = req['data']['instanceHostMap']['instance']
instance['nics'][0]['network']['kind'] = 'dockerNone'
instance['hostname'] = 'nameisset'

def post(req, resp):
instance_data = resp['data']['instanceHostMap']['instance']['+data']
docker_inspect = instance_data['dockerInspect']
assert docker_inspect['Config']['NetworkDisabled']
assert docker_inspect['Config']['Hostname'] == 'nameisset'

event_test(agent, 'docker/instance_activate', pre_func=pre,
post_func=post, diff=False)
Expand All @@ -26,12 +28,14 @@ def test_network_mode_host(agent, responses):
def pre(req):
instance = req['data']['instanceHostMap']['instance']
instance['nics'][0]['network']['kind'] = 'dockerHost'
instance['hostname'] = 'nameisset'

def post(req, resp):
instance_data = resp['data']['instanceHostMap']['instance']['+data']
docker_inspect = instance_data['dockerInspect']
assert not docker_inspect['Config']['NetworkDisabled']
assert docker_inspect['HostConfig']['NetworkMode'] == 'host'
assert docker_inspect['Config']['Hostname'] != 'nameisset'

event_test(agent, 'docker/instance_activate', pre_func=pre,
post_func=post, diff=False)
Expand Down

0 comments on commit 9fafb15

Please sign in to comment.