Skip to content

Instantly share code, notes, and snippets.

@JayH5
Last active April 3, 2018 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JayH5/d5967f6cb45ff34793031e7c47cc5d5e to your computer and use it in GitHub Desktop.
Save JayH5/d5967f6cb45ff34793031e7c47cc5d5e to your computer and use it in GitHub Desktop.
Python example: Marathon networking mode
def networking_mode(app_json):
# Marathon 1.5+: there is a `networks` field
networks = app_json.get('networks')
if networks:
# Modes cannot be mixed, so assigning the last mode is fine
return networks[-1].get('mode', 'container')
# Older Marathon: determine equivalent network mode
container = app_json.get('container')
if container is not None and 'docker' in container:
docker_network = container['docker'].get('network')
if docker_network == 'USER':
return 'container'
elif docker_network == 'BRIDGE':
return 'container/bridge'
# Otherwise, give up and default to host networking mode
return 'host'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment