Last active
April 3, 2018 10:01
-
-
Save JayH5/d5967f6cb45ff34793031e7c47cc5d5e to your computer and use it in GitHub Desktop.
Python example: Marathon networking mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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