ArcGIS API for Python - How to manage Datastores?

1163
2
Jump to solution
03-04-2021 12:18 PM
JoanneMcGraw
Occasional Contributor III

Hello,

I am working with a stand-alone site consisting of two 10.8.1 ArcGIS Servers; i.e., no Portal. I am currently trying to script the addition/deletion (register/unregister, whatever the appropropriate terminology is here) of some folder fileShares. I have done this in the past for 10.4.1 using Python 2.7 with the REST API but am trying to do same with the newer "ArcGIS API for Python" available with the installation. I'm new to this, having trouble working through the documentation and not finding much in the way of examples.

I have an arcgis.gis.server.Server object instantiated and I can search() on its datastores to find the "fileShares" folders but...then what? It's just a list of my datastore information as dictionaries, how do I use this to instantiate an arcgis.gis.server.Datastore so I can update() it (if that's what I want to do; same would be true for delete())?

The documentation (https://developers.arcgis.com/python/api-reference/arcgis.gis.server.html#arcgis.gis.server.Datastor...) indicates the following parameters are necessary to instantiate a Database object: datastore, path, datadict=None, **kwargs. I assume the path is the "path" in the dictionary returned by the search and the datadict is the "info" in the dictionary (with the updates that I will ultimately want applied), but what is the first datastore parameter referring to? More importantly, how does the update() know what Server this Datasource is supposed to be found on?

I don't get it...

Any explanation or direction re: what I'm missing in this would be appreciated. I'm sure it's something pretty fundamental.

Cheers,
jtm

0 Kudos
1 Solution

Accepted Solutions
JoanneMcGraw
Occasional Contributor III

Okay, well, I got the something to work but still can't get anything returned with the DataStoreManager get(). I'll post what I've got in case there's anyone else having trouble with this stuff...

import arcgis.gis.server

url = "https://<my_domain>/arcgis"

url_admin = url + "/admin"
url_token = url + "/tokens/generateToken"

my_server = arcgis.gis.server.Server(
    url=url_admin,
    token_url=url_token,
    username="<my_admin_username>",
    password="<my_admin_password>",
    all_ssl=True
)

my_ds_manager = arcgis.gis.server.DataStoreManager(
    url=my_server.url + "/data",
    gis=my_server
)

my_str = "my_tst_ds"
my_ds_manager.add_folder(my_str, "<my_server_path>", "<my_client_path>")

datastores = my_ds_manager.list()
for datastore in datastores:
    if datastore.properties["path"] == "/fileShares/" + my_str:
        print("Deleting", datastore.properties["path"])
        datastore.delete()
    else:
        print("Not deleting", datastore.properties["path"])

 

View solution in original post

0 Kudos
2 Replies
JoanneMcGraw
Occasional Contributor III

Okay, so I can get a arcgis.gis.server.DataStoreManager and the description of the get() suggests that I can receive a DataStore, but I'm not sure what "path" I'm supposed to put in. I've tried using the path returned in the search (that is, "/fileShares/<my_datastore_name>") but it returns an "Item not found" error.

Still pluggin' away...

And later...

I'm able to add a folder using that DataStoreManager but, directly after I make it (and verify it has been added to the site through the ArcGIS Server Manager), I still can't "get" it. I've tried using just the name of the DataStore folder item I just created, as well as "/fileShares/<that_name>". Just passing the name, returns None and passing "/fileShares/<name>" returns the "Item not found" error noted above.

0 Kudos
JoanneMcGraw
Occasional Contributor III

Okay, well, I got the something to work but still can't get anything returned with the DataStoreManager get(). I'll post what I've got in case there's anyone else having trouble with this stuff...

import arcgis.gis.server

url = "https://<my_domain>/arcgis"

url_admin = url + "/admin"
url_token = url + "/tokens/generateToken"

my_server = arcgis.gis.server.Server(
    url=url_admin,
    token_url=url_token,
    username="<my_admin_username>",
    password="<my_admin_password>",
    all_ssl=True
)

my_ds_manager = arcgis.gis.server.DataStoreManager(
    url=my_server.url + "/data",
    gis=my_server
)

my_str = "my_tst_ds"
my_ds_manager.add_folder(my_str, "<my_server_path>", "<my_client_path>")

datastores = my_ds_manager.list()
for datastore in datastores:
    if datastore.properties["path"] == "/fileShares/" + my_str:
        print("Deleting", datastore.properties["path"])
        datastore.delete()
    else:
        print("Not deleting", datastore.properties["path"])

 

0 Kudos