def get_number_of_app_ports(app):
mode = _get_networking_mode(app)<EOL>ports_list = None<EOL>if mode == '<STR_LIT:host>':<EOL><INDENT>ports_list = _get_port_definitions(app)<EOL><DEDENT>elif mode == '<STR_LIT>':<EOL><INDENT>ports_list = _get_port_definitions(app)<EOL>if ports_list is None:<EOL><INDENT>ports_list = _get_container_port_mappings(app)<EOL><DEDENT><DEDENT>elif mode == '<STR_LIT>':<EOL><INDENT>ports_list = _get_ip_address_discovery_ports(app)<EOL>if not ports_list:<EOL><INDENT>ports_list = _get_container_port_mappings(app)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise RuntimeError(<EOL>"<STR_LIT>".format(mode))<EOL><DEDENT>return len(ports_list)<EOL>
Get the number of ports for the given app JSON. This roughly follows the
logic in marathon-lb for finding app IPs/ports, although we are only
interested in the quantity of ports an app should have and don't consider
the specific IPs/ports of individual tasks:
https://github.com/mesosphere/marathon-lb/blob/v1.10.3/utils.py#L393-L415

:param app: The app JSON from the Marathon API.
:return: The number of ports for the app.