Select to view content in your preferred language

Get request address within server geoprocessing job

3741
2
05-13-2015 09:43 PM
StevenHaslemore
Occasional Contributor

I'm wanting to know if a server arcpy geoprocessing job has any awareness of the url it was requested by, or what web adapter instance it is running on.

Let say I want a geoprocessing script that will stop all running mapserver instances on its server, and I want to deploy this same script across multiple servers, each with different web adaptors

To stop the services I need to get an admin token from the server it is running on.

So given the two servers below, is it possible to have the same gp task published on each of them, know what server to request the token from? Without explicitly passing it in as parameter of the job.

https://myaddress.com/arcgisONE/rest/services/gpService/stopMaps/GPServer

https://myaddress.com/arcgis/rest/services/gpService/stopMaps/GPServer

I'm thinking something like

arcpy.env.server.hostname == myaddress.com

arcpy.env.server.instance == arcgisONE

so it could construct  https://myaddress.com/arcgisONE/tokens   to request the required token

Cheers,

Steven

Tags (2)
0 Kudos
2 Replies
OwenEarley
Regular Contributor

You can use the socket module to get the hostname:

import socket
...
hostname = socket.gethostname()

Not sure about the server instance. Does each instance have a different arcpy.env.scratchWorkspace that could be used to differentiate them?

StevenHaslemore
Occasional Contributor

Yeah, so this will give us the server name, from here we can assume the standard port to hit the arcgis server directly.

Not quite what I was fishing for but could solve my example case.

Different example

If it was a clustered server scenario, running different services on each server, accessed through the same web adapter, and we had to request a service back from the cluster, we'd need to hit the web adapter to find our service.