def validate_app(app): if app['id'] is None: raise MissingFieldException("App doesn't contain a valid App ID", 'id') if 'labels' not in app: raise MissingFieldException( "No labels found. Please define the" " HAPROXY_DEPLOYMENT_GROUP label", 'label') if 'HAPROXY_DEPLOYMENT_GROUP' not in app['labels']: raise MissingFieldException( "Please define the " "HAPROXY_DEPLOYMENT_GROUP label", 'HAPROXY_DEPLOYMENT_GROUP') if 'HAPROXY_DEPLOYMENT_ALT_PORT' not in app['labels']: raise MissingFieldException( "Please define the " "HAPROXY_DEPLOYMENT_ALT_PORT label", 'HAPROXY_DEPLOYMENT_ALT_PORT')
def get_service_port(app): portMappings = get_app_port_mappings(app) if len(portMappings) > 0: servicePort = portMappings[0].get('servicePort') if servicePort: return servicePort portDefinitions = app.get('portDefinitions', []) if len(portDefinitions) > 0: port = ['portDefinitions'][0].get('port') if port: return int(port) ports = app.get('ports', []) if len(ports) > 0: return int(ports[0]) raise MissingFieldException("App doesn't contain a service port", 'container.portMappings')