DatastoreManager class has add_database() method but it seems it doesn't have the remove method. How can I remove an existing registered datastore item using this class or other arcgis api for python classes?
https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.DatastoreManager
Solved! Go to Solution.
Hi @AzinSharaf ,
The following code snippet unregisters a datastore:
gis_servers = gis_portal.admin.servers.list()
# Select the relevant server
server1 = gis_servers[1]
dataStore_list = server1.datastores.list()
# select the datastore you want to unregister,let's say the 4th one
dataStore_list[3].delete()
I hope that's helpful.
Hi @AzinSharaf ,
The following code snippet unregisters a datastore:
gis_servers = gis_portal.admin.servers.list()
# Select the relevant server
server1 = gis_servers[1]
dataStore_list = server1.datastores.list()
# select the datastore you want to unregister,let's say the 4th one
dataStore_list[3].delete()
I hope that's helpful.
hi @MehdiPira1
Thanks for your guidance. I was able to delete the registered datastore with the following code. I couldn't rely on datastore list index so I edited your code.
def delete_registered_ds(ds_name, gis):
"""
:param ds_name: a string in datastore's name
:param gis: a GIS class
:return:
"""
arcpy.AddMessage("Deleting the registered data store from GIS server...")
gis_servers = gis.admin.servers.list()
for gis_server in gis_servers:
if "A_PORTAL_NAME" in gis_server.url.lower():
data_store_list = gis_server.datastores.list()
for ds in data_store_list:
if ds.type == "egdb":
if ds_name.lower() in ds.path.lower():
ds.delete()
break
Not a problem. Glad that helped!