remove_datastore method

920
3
Jump to solution
09-01-2021 05:24 PM
AzinSharaf
Occasional Contributor II

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

 

0 Kudos
1 Solution

Accepted Solutions
MehdiPira1
Esri Contributor

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.

View solution in original post

0 Kudos
3 Replies
MehdiPira1
Esri Contributor

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.

0 Kudos
AzinSharaf
Occasional Contributor II

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

 

MehdiPira1
Esri Contributor

@AzinSharaf ,

Not a problem. Glad that helped!

0 Kudos