Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

3. Administering ArcGIS for Server site: introduction

AlexArcPy edited this page May 25, 2016 · 2 revisions

Exploring ArcGIS for Server resources and operations

Let’s get started using ArcREST for administering ArcGIS for Server site.

You would start by establishing an administrator connection to the site (just like you would when using the ArcGIS Server Administrator Directory accessible at http://localhost:6080/arcgis/admin/ on your ArcGIS for Server machine). To log in into the site, you would need to provide the ArcGIS for Server site URL as well as site administrator credentials.

from arcrest.manageags import AGSAdministration
from arcrest import AGSTokenSecurityHandler

ags_admin_url = r"http://localhost:6080/arcgis/admin"
ags_security_handler = AGSTokenSecurityHandler(username="psa",
                                           password="psa",
                                           org_url=ags_admin_url)

ags_obj = AGSAdministration(ags_admin_url, ags_security_handler)

ags_obj is your AGSAdministration object which is the main entry point into the REST interface of your ArcGIS for Server site. AGSTokenSecurityHandler object supplied will help you obtain the token and log in into the site. At this moment, in a basic ArcGIS for Server deployment, you don't need anything else to get started administering the site.

It may be very helpful to have Administrator Directory open to see what resources and supported operations your ArcGIS for Server installation has. If you type ags_obj. in your Python IDE, you will see a list of accessible resources (such as machines, services, and logs) as well as operations (such as exportSite and deleteSite).

In other words, Administrator Directory can help you find out what methods should you invoke in ArcREST to perform the operation needed. Keep in mind that as a rule:

  • resources are implemented as AGSAdministration class instance object properties;
  • operations are implemented as AGSAdministration class instance object methods.

Printing ags_obj.info will tell you that you access the info resource for your site; printing info.fullVersion properties will give bits of information about your site.

print ags_obj.info
>>> arcrest.manageags._info.Info object

print ags_obj.info.fullVersion 
>>> '10.3.1'
ags_obj.info.loggedInUserPrivilege
>>> 'ADMINISTER'

Tip: most of the objects you will be working with have a __dict__ property that will let you see all the attribute references the object has.

To see all of the attributes of the object (i.e., all of the resources and interfaces implemented in the REST API for this object), you could do print ags_obj.info.__dict__ which would give you a dictionary with all of the properties your Site Info resource has plus some of the useful information that is used by ArcREST internally.

{'_currentbuild': '4959',
 '_currentversion': '10.3.1',
 '_fullVersion': '10.3.1',
 '_json': '{"fullVersion": "10.3.1", "loggedInUser": "psa", "currentbuild": "4959", "loggedInUserPrivilege": "ADMINISTER", 
 "currentversion": "10.3.1", "timezone": {"daylightsavings": "", "windowsid": "", "olsonid": "", "displayname": ""}}',
 '_loggedInUser': 'psa',
 '_loggedInUserPrivilege': 'ADMINISTER',
 '_proxy_port': None,
 '_proxy_url': None,
 '_securityHandler': <arcrest.security.security.AGSTokenSecurityHandler object at 0x0000000009C16438>,
 '_timezone': {'daylightsavings': '',
	           'displayname': '',
	           'olsonid': '',
	           'windowsid': ''},
 '_url': 'http://localhost:6080/arcgis/admin/info'}	

Managing ArcGIS for Server site resources

Now when we know how to establish a connection to an ArcGIS for Server site, let's see how we can edit some property in the site and manage its resources. For now, we will clean all the existing log records that were logged and then change the log level to "DEBUG". Because we are going to work with logs, we need to access the ags_obj.logs object. Let's clean all the log records first.

ags_obj.logs.clean()
>>> {'status': 'success'}

Note: Keep in mind that most of the operations performed return a dictionary with the status of the operation which can be checked to verify that the operation was completed successfully. Alternatively, {'success': True} dictionary can also be returned for successfully completed operations.

What is the current log level in the site?

print ags_obj.logs.logSettings
>>>	{'logDir': 'C:\\arcgisserver\\logs\\',
 'logLevel': 'FINE',
 'maxErrorReportsCount': 10,
 'maxLogFileAge': 90,
 'statisticsConfig': {'enabled': True,
	                  'maxHistory': 0,
	                  'samplingInterval': 28,
	                  'statisticsDir': 'C:\\arcgisserver\\directories\\arcgissystem'},
 'usageMeteringEnabled': False}

Now when we know what is the current level of the logging ('FINE'), let's change it to 'DEBUG'. In order to do that, we need to invoke a method editLogSettings of the ags_obj.logs object supplying the parameter logLevel.

ags_obj.logs.editLogSettings(logLevel="DEBUG")
>>> {'settings': {'logDir': 'C:\\arcgisserver\\logs\\',
	          'logLevel': 'DEBUG',
	          'maxErrorReportsCount': 10,
	          'maxLogFileAge': 90,
	          'statisticsConfig': {'enabled': True,
	                               'maxHistory': 0,
	                               'samplingInterval': 28,
	                               'statisticsDir': 'C:\\arcgisserver\\directories\\arcgissystem'},
	          'usageMeteringEnabled': False},
'status': 'success'}

In this case, we get back a dictionary with two keys: 'status' with the status of the operation and 'settings' with the current logging settings.

Tip: you can verify whether the operation was completed successfully by visiting the Administrator Directory page. In this case, you would browse to http://localhost:6080/arcgis/admin/logs/settings to check the current logging level.