getting_started_server_module

Getting started with server module

The server module is the latest addition to the API. As of early March 2017, this is still under development and has some rough edges. This part of the training is just to show what is coming. Use this with caution.

ArcGIS Servers in your ArcGIS Enterprise

ArcGIS Enterprise is a fully featured mapping and analytics platform. An enterprise consists of:

  • ArcGIS Server
    • GIS Server
    • Image Servier
    • GeoAnalytics Server
    • GeoEvent Server
  • ArcGIS Data Store
  • Portal for ArcGIS
  • ArcGIS Web Adaptor

Below is a simple deployment of ArcGIS Enterprise

Inspect ArcGIS Enterprise

Enterprise

GeoAnalytics server

Accessing your ArcGIS Servers

The server module contains the classes and methods to help you administer both stand-alone ArcGIS Servers and those that are federated to a Portal for ArcGIS deployment.

In [1]:
from arcgis.gis import GIS
from arcgis import server
from getpass import getpass
In [2]:
portal_pass = getpass()
········

Accessing from Portal for ArcGIS

In [3]:
portal_url = "https://esriwebgis.webgistesting.net/portal"
portal_username = "atma.mani"
gis = GIS(portal_url, portal_username, portal_pass)
Get the list of servers attached to the enterprise
In [4]:
gis.servers
Out[4]:
[<arcgis.server.managers.Server at 0x13c5e7efe80>,
 <arcgis.server.managers.Server at 0x13c5e7fd6a0>,
 <arcgis.server.managers.Server at 0x13c5e805b00>]

Inspect the properties available on a server object

In [5]:
server1 = gis.servers[0]
print(server1.connection.baseurl)
https://ESRIwebgis.webgistesting.net/server/rest/services

Let us print the URLs of all servers. Use the connection object to

In [6]:
server_list = gis.servers
print ("%s servers found" % len(server_list))
for s1 in server_list:
    print(s1.connection.baseurl)
3 servers found
https://ESRIwebgis.webgistesting.net/server/rest/services
https://ESRIgeoanalytics.webgistesting.net/server/rest/services
https://ESRIimageserver.webgistesting.net/arcgis/rest/services

Accessing a stand alone server

Create a server object directly using its constructor to connect to a stand-alone GIS server. In the example below, imagine the third server attached to the portal is stand alone for demo purposes.

In [9]:
stand_alone_server = server.Server(url='https://ESRIwebgis.webgistesting.net:6443/arcgis',
                                  username='atma.mani',
                                  password=portal_pass)
---------------------------------------------------------------------------
TimeoutError                              Traceback (most recent call last)
C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\urllib\request.py in do_open(self, http_class, req, **http_conn_args)
   1253             try:
-> 1254                 h.request(req.get_method(), req.selector, req.data, headers)
   1255             except OSError as err: # timeout error

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\http\client.py in request(self, method, url, body, headers)
   1106         """Send a complete request to the server."""
-> 1107         self._send_request(method, url, body, headers)
   1108 

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\http\client.py in _send_request(self, method, url, body, headers)
   1151             body = _encode(body, 'body')
-> 1152         self.endheaders(body)
   1153 

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\http\client.py in endheaders(self, message_body)
   1102             raise CannotSendHeader()
-> 1103         self._send_output(message_body)
   1104 

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\http\client.py in _send_output(self, message_body)
    933 
--> 934         self.send(msg)
    935         if message_body is not None:

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\http\client.py in send(self, data)
    876             if self.auto_open:
--> 877                 self.connect()
    878             else:

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\http\client.py in connect(self)
   1252 
-> 1253             super().connect()
   1254 

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\http\client.py in connect(self)
    848         self.sock = self._create_connection(
--> 849             (self.host,self.port), self.timeout, self.source_address)
    850         self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\socket.py in create_connection(address, timeout, source_address)
    711     if err is not None:
--> 712         raise err
    713     else:

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\socket.py in create_connection(address, timeout, source_address)
    702                 sock.bind(source_address)
--> 703             sock.connect(sa)
    704             return sock

TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

During handling of the above exception, another exception occurred:

URLError                                  Traceback (most recent call last)
<ipython-input-9-54300a81b052> in <module>()
      1 stand_alone_server = server.Server(url='https://ESRIwebgis.webgistesting.net:6443/arcgis',
      2                                   username='atma.mani',
----> 3                                   password=portal_pass)

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\site-packages\arcgis\server\managers.py in __init__(self, url, tokenurl, username, password, verify_cert, portal_connection, **kwargs)
     48                               proxy_port,
     49                               portal_connection,
---> 50                               initialize)
     51         self._con = self._server.connection
     52         self._sm = self._server.site_manager

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\site-packages\arcgis\server\_view\catalog.py in __init__(self, url, tokenurl, username, password, key_file, cert_file, expiration, all_ssl, referer, proxy_host, proxy_port, portal_connection, initialize)
     46                                 proxy_host=proxy_host,
     47                                 proxy_port=proxy_port,
---> 48                                 portal_connection=portal_connection)
     49 
     50         super(ServerManager, self).__init__(url=self._url,

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\site-packages\arcgis\server\_common\_connection.py in __init__(self, baseurl, tokenurl, username, password, key_file, cert_file, expiration, all_ssl, referer, proxy_host, proxy_port, portal_connection)
    273         # Login if credentials were provided
    274         if username and password:
--> 275             self.login(username, password, expiration)
    276         elif username or password:
    277             _log.warning('Both username and password required for login')

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\site-packages\arcgis\server\_common\_connection.py in login(self, username, password, expiration)
    365         try:
    366             newtoken = self.generate_token(username,
--> 367                                            password, expiration)
    368             self._REFRESH_WHEN = datetime.datetime.now() + datetime.timedelta(seconds=expiration)
    369             if newtoken:

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\site-packages\arcgis\server\_common\_connection.py in generate_token(self, username, password, expiration)
    357         else:
    358             resp = self.post(path=self._tokenurl, postdata=postdata,
--> 359                              ssl=True, add_token=False)
    360         if resp:
    361             return resp.get('token')

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\site-packages\arcgis\server\_common\_connection.py in post(self, path, postdata, files, ssl, compress, is_retry, use_ordered_dict, add_token, verify_cert, token, **kwargs)
    748             opener.addheaders = headers
    749             #print("***"+url)
--> 750             resp = opener.open(url, data=encoded_postdata.encode())
    751             resp_data = self._process_response(resp)
    752 

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\urllib\request.py in open(self, fullurl, data, timeout)
    464             req = meth(req)
    465 
--> 466         response = self._open(req, data)
    467 
    468         # post-process response

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\urllib\request.py in _open(self, req, data)
    482         protocol = req.type
    483         result = self._call_chain(self.handle_open, protocol, protocol +
--> 484                                   '_open', req)
    485         if result:
    486             return result

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
    442         for handler in handlers:
    443             func = getattr(handler, meth_name)
--> 444             result = func(*args)
    445             if result is not None:
    446                 return result

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\urllib\request.py in https_open(self, req)
   1295         def https_open(self, req):
   1296             return self.do_open(http.client.HTTPSConnection, req,
-> 1297                 context=self._context, check_hostname=self._check_hostname)
   1298 
   1299         https_request = AbstractHTTPHandler.do_request_

C:\Users\atma6951\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\geonuma_server\lib\urllib\request.py in do_open(self, http_class, req, **http_conn_args)
   1254                 h.request(req.get_method(), req.selector, req.data, headers)
   1255             except OSError as err: # timeout error
-> 1256                 raise URLError(err)
   1257             r = h.getresponse()
   1258         except:

URLError: <urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>

We are connecting to the port because the webadaptor on this machine is used for Portal instead of server

In [8]:
stand_alone_server.connection.baseurl
Out[8]:
'https://ESRIwebgis.webgistesting.net:6443/arcgis/rest/services'
In [11]:
stand_alone_server2 = server.Server(url='https://ESRIgeoanalytics.webgistesting.net/server',
                                   username='admin',password=portal_pass)

This is an example where you connect to the server using its web adaptor url

In [12]:
stand_alone_server2.connection.baseurl
Out[12]:
'https://ESRIgeoanalytics.webgistesting.net/server/rest/services'
In [13]:
stand_alone_server2.connection.product
Out[13]:
'SERVER'