Is there a way to see the services properties of a arc server (federated with portal) using ArcGIS Python API 1.5.2? I am using python 3 for the same.

2914
12
Jump to solution
01-22-2019 05:21 AM
VaibhavSingh
New Contributor II

I want to have a list of the services own by a specific owner and want to delete those Is there any way I can achieve that through python.

I was successfully able to access the services but is there any way to check their running instances , whether they are getting utilized or not, if not can we delete them?

0 Kudos
1 Solution

Accepted Solutions
simoxu
by MVP Regular Contributor
MVP Regular Contributor

Like you can't really delete the services on the federated servers in the portal web interface, you can't delete a service using the GIS module in the ArcGIS Python API, Because, GIS module is the equivalent to your Web GIS (Portal or AGOL).

To delete a service, you mean manage the ArcGIS server, you need the following python modules:

arcgis.gis.server module — arcgis 1.5.2 documentation 

arcgis.gis.admin module — arcgis 1.5.2 documentation 

I did a quick test in my environment, and it seems working fine:

from arcgis.gis.server import Server

# this is NOT your portal url, it's your server admin url
gis_server = Server(url="https://your_server_name:6443/arcgis/admin",username="site admin name",password="admin password")

service_manager = gis_server.services

# list the services in the test folder, make sure you see the service your want to delete
test_services = service_manager.list(folder="test")
print(test_services)

# for example, it's the 3rd item in the list
test = test_services[2]

# this will work, and return "True"
test.delete()‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Please reference the aforementioned document to find the detailed the syntax for the construction of the Server instance 

Hope it helps

View solution in original post

12 Replies
JoshuaBixby
MVP Esteemed Contributor

I don't have access this morning to any federated GIS servers, so I can't test any code to respond to the first part of your question, but I will comment on:

whether they are getting utilized or not, if not can we delete them?

When you check whether a service is running, that only answers the question of whether a service is getting utilized at or shortly before you checked it.  It is common for services, especially lower-usage ones, to have the minimum number of running instances set to zero.  If you check and a service isn't running, it really doesn't give you any information beyond was someone using that service at or shortly before you checked.

Monitoring utilization is much more involved than just checking whether a service is running once, it is about looking at information over time, and that is why Esri created ArcGIS Monitor.

VaibhavSingh
New Contributor II

Thanks for the Information Joshua, 

What about deleting it?

I am able to access the service but the delete command is not working on them 

The item is of type service, and I am getting the below error:

AttributeError: 'Item' object has no attribute '_user_id'
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

What happens if you pass the dry_run argument to the delete method, same error?

0 Kudos
VaibhavSingh
New Contributor II

Hi Joshua, while trying this it is giving the error that dry_run cannot be identified.

0 Kudos
VaibhavSingh
New Contributor II

layer_item.delete(dry_run=True)

this is giving me the same error :

type error: 'Item' object has no attribute '_user_id'
In [30]:
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I can replicate the issue using our internal, federated GIS servers.  It really looks to be a defect to me, I would open a case with Esri Support.  I tried a couple of workarounds, but I keep getting the same error.

0 Kudos
VaibhavSingh
New Contributor II

Thanks Joshua, please let me know if you find any other workaround for this.

0 Kudos
simoxu
by MVP Regular Contributor
MVP Regular Contributor

Like you can't really delete the services on the federated servers in the portal web interface, you can't delete a service using the GIS module in the ArcGIS Python API, Because, GIS module is the equivalent to your Web GIS (Portal or AGOL).

To delete a service, you mean manage the ArcGIS server, you need the following python modules:

arcgis.gis.server module — arcgis 1.5.2 documentation 

arcgis.gis.admin module — arcgis 1.5.2 documentation 

I did a quick test in my environment, and it seems working fine:

from arcgis.gis.server import Server

# this is NOT your portal url, it's your server admin url
gis_server = Server(url="https://your_server_name:6443/arcgis/admin",username="site admin name",password="admin password")

service_manager = gis_server.services

# list the services in the test folder, make sure you see the service your want to delete
test_services = service_manager.list(folder="test")
print(test_services)

# for example, it's the 3rd item in the list
test = test_services[2]

# this will work, and return "True"
test.delete()‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Please reference the aforementioned document to find the detailed the syntax for the construction of the Server instance 

Hope it helps

VaibhavSingh
New Contributor II

Thanks Simo xu, 
but I am getting error 

AttributeError: 'Server' object has no attribute 'services'

I even checked for the other objects, it is giving the same error for machines also.

---------------------------------------------------------------------------KeyError                                  Traceback (most recent call last)~\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\server\_common\_base.py in __getattr__(self, name)     81         try:---> 82             return self._properties.__getitem__(name)     83         except:~\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\_impl\common\_mixins.py in __getitem__(self, key)    339         """--> 340         return self._mapping[key]    341  KeyError: 'machines'  During handling of the above exception, another exception occurred: AttributeError                            Traceback (most recent call last)<ipython-input-60-04a36060757d> in <module>      9 )     10 '''service_manager = gis_server.services'''---> 11 machines = gis_server.machines     12      13  ~\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\server\_common\_base.py in __getattr__(self, name)     85                 if k.lower() == name.lower():     86                     return v---> 87             raise AttributeError("'%s' object has no attribute '%s'" % (type(self).__name__, name))     88     #----------------------------------------------------------------------     89     def __getitem__(self, key):AttributeError: 'Server' object has no attribute 'machines'
0 Kudos