Enable/Disable Services directory in DirectoryManager using ArcGIS API for python

599
6
Jump to solution
09-05-2021 07:27 PM
RobertDriessen1
New Contributor II

Hi

Does anyone have a sample of enabling or disabliing the services directory using the ArcGIS API for python?

Specifically, how to get the directoryManager object and then how to edit a specific setting using edit_services_directory

0 Kudos
1 Solution

Accepted Solutions
RobertDriessen1
New Contributor II

Finally figured out a way (if there is a better way then please let me know).

from arcgis.gis import server
from arcgis.gis import GIS
portal = GIS(<parameters for connecting to portal>)
#Get the server object from the portal as this has the required system property
hosting_server = portal.admin.servers.get(role="HOSTING_SERVER")[0]
DirManager=server.DirectoryManager(hosting_server.system)
dm_props=DirManager.properties
print("Initial Directory Manager Properties")
print(' --allowedOrigins: {} '.format(dm_props['allowedOrigins']))
print(' --arcgis.com.map: {} '.format(dm_props['arcgis.com.map']))
print(' --arcgis.com.map.text: {} '.format(dm_props['arcgis.com.map.text']))
print(' --jsapi.arcgis: {} '.format(dm_props['jsapi.arcgis']))
print(' --jsapi.arcgis.css: {} '.format(dm_props['jsapi.arcgis.css']))
print(' --jsapi.arcgis.sdk: {} '.format(dm_props['jsapi.arcgis.sdk']))
print(' --directory enabled: {} '.format(dm_props['enabled']))
if DirManager.edit_services_directory(allowedOrigins=dm_props['allowedOrigins'],\
arcgis_com_map=dm_props['arcgis.com.map'], \
arcgis_com_map_text=dm_props['arcgis.com.map.text'], \
jsapi_arcgis=dm_props['jsapi.arcgis'],\
jsapi_arcgis_css=dm_props['jsapi.arcgis.css'],\
jsapi_arcgis_css2='',\
jsapi_arcgis_sdk=dm_props['jsapi.arcgis.sdk'],\
serviceDirEnabled = True):
#jsapi_arcgis_css2 is deprecated but still reqiured - setting is not in properties
print('updated services directory')
else:print('did not update services directory')
dm_props=DirManager.properties
print("Final Directory Manager Properties:")
print(' --allowedOrigins: {} '.format(dm_props['allowedOrigins']))
print(' --arcgis.com.map: {} '.format(dm_props['arcgis.com.map']))
print(' --arcgis.com.map.text: {} '.format(dm_props['arcgis.com.map.text']))
print(' --jsapi.arcgis: {} '.format(dm_props['jsapi.arcgis']))
print(' --jsapi.arcgis.css: {} '.format(dm_props['jsapi.arcgis.css']))
print(' --jsapi.arcgis.sdk: {} '.format(dm_props['jsapi.arcgis.sdk']))
print(' --directory enabled: {} '.format(dm_props['enabled']))

 

 

View solution in original post

0 Kudos
6 Replies
MehdiPira1
Esri Contributor

@RobertDriessen1 ,

The following link provides details of managing services on your server via ArcGIS API for Python:

https://developers.arcgis.com/python/guide/managing-your-gis-servers/

Cheers

Mehdi

0 Kudos
RobertDriessen1
New Contributor II

Thanks @MehdiPira1, unfortunately minimal guidance in that link, I was hoping for an example.

0 Kudos
RobertDriessen1
New Contributor II

Finally figured out a way (if there is a better way then please let me know).

from arcgis.gis import server
from arcgis.gis import GIS
portal = GIS(<parameters for connecting to portal>)
#Get the server object from the portal as this has the required system property
hosting_server = portal.admin.servers.get(role="HOSTING_SERVER")[0]
DirManager=server.DirectoryManager(hosting_server.system)
dm_props=DirManager.properties
print("Initial Directory Manager Properties")
print(' --allowedOrigins: {} '.format(dm_props['allowedOrigins']))
print(' --arcgis.com.map: {} '.format(dm_props['arcgis.com.map']))
print(' --arcgis.com.map.text: {} '.format(dm_props['arcgis.com.map.text']))
print(' --jsapi.arcgis: {} '.format(dm_props['jsapi.arcgis']))
print(' --jsapi.arcgis.css: {} '.format(dm_props['jsapi.arcgis.css']))
print(' --jsapi.arcgis.sdk: {} '.format(dm_props['jsapi.arcgis.sdk']))
print(' --directory enabled: {} '.format(dm_props['enabled']))
if DirManager.edit_services_directory(allowedOrigins=dm_props['allowedOrigins'],\
arcgis_com_map=dm_props['arcgis.com.map'], \
arcgis_com_map_text=dm_props['arcgis.com.map.text'], \
jsapi_arcgis=dm_props['jsapi.arcgis'],\
jsapi_arcgis_css=dm_props['jsapi.arcgis.css'],\
jsapi_arcgis_css2='',\
jsapi_arcgis_sdk=dm_props['jsapi.arcgis.sdk'],\
serviceDirEnabled = True):
#jsapi_arcgis_css2 is deprecated but still reqiured - setting is not in properties
print('updated services directory')
else:print('did not update services directory')
dm_props=DirManager.properties
print("Final Directory Manager Properties:")
print(' --allowedOrigins: {} '.format(dm_props['allowedOrigins']))
print(' --arcgis.com.map: {} '.format(dm_props['arcgis.com.map']))
print(' --arcgis.com.map.text: {} '.format(dm_props['arcgis.com.map.text']))
print(' --jsapi.arcgis: {} '.format(dm_props['jsapi.arcgis']))
print(' --jsapi.arcgis.css: {} '.format(dm_props['jsapi.arcgis.css']))
print(' --jsapi.arcgis.sdk: {} '.format(dm_props['jsapi.arcgis.sdk']))
print(' --directory enabled: {} '.format(dm_props['enabled']))

 

 

0 Kudos
bshow
by
New Contributor II

Thank you Robert - do you know how to do this in AGOL instead of Portal?

0 Kudos
RobertDriessen1
New Contributor II

Not sure if this is possible in AGOL.  I suspect it is not possible to disable the services directory as it would afffect the entire AGOL site?

0 Kudos
bshow
by
New Contributor II

Robert - apologies - What I meant to ask was do you know of a way to enable/disable SYNC using ArcGIS API for python?  When I run my script it gets tripped up if someone exported a copy so it would be really nice to be able to enable/disable sync on all or specific services. Any help would be greatly appreciated!   This is on AGOL.

0 Kudos