I finally solved my problem adding a new function in wsgiwps.py:
def dynUpdateConfigurationURLs(new_url):
'''
Update dynamically PyWPS configuration to match public IP:port of this server into the cluster.
PyWPS servers are meant to be deployed into a dynamic Mesos Cluster. Their IP:port are therefore auto-assigned by Marathon,
and are not deterministic.
The values of 'serveraddress' and 'outputURL' in wpsserver.conf can't be forecasted in advance.
This function is meant to be called the client emit a request.
The base URL requested by the client is retrieved and reinjected in PyWPS configuration, so that the client can poll and get the result seamlessly.
'''
confFile = os.environ.get('PYWPS_CFG', '/var/www/wps/pywps.cfg')
configpar = ConfigParser.ConfigParser()
configpar.read('/var/www/wps/pywps.cfg')
# Old values
oldServerAddress = configpar.get('wps', 'serveraddress')
oldOutputURL = configpar.get('server', 'outputUrl')
# New values
new_url = re.sub('^https?://', '', new_url) # Remove http[s] if present
newServerAddress = 'http://' + new_url
newOutputURL = newServerAddress + '/wps/wpsoutputs/'
# Update the config is URLs are not the same as the one used for this HTTP requet.
if (oldServerAddress != newServerAddress) or (oldOutputURL != newOutputURL):
configpar.set('wps', 'serveraddress', newServerAddress)
configpar.set('server', 'outputUrl', newOutputURL)
with open(confFile, 'wb') as configfilePtr:
configpar.write(configfilePtr)
print('--------------------------------------------------------------------------------------------------------------------------')
print('Dynamically update PyWPS config \'serveraddress\' to \'%s\' and \'outputUrl\' to \'%s\'' % (newServerAddress, newOutputURL))
def application(environ, start_response):
dynUpdateConfigurationURLs(environ['HTTP_HOST']) # Ex: 'HTTP_HOST': '172.16.10.21',
......