forked from Cintruenigo/ArcGIS-Server-Stuff
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsharedinstances.py
88 lines (72 loc) · 4.57 KB
/
sharedinstances.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import sys
import argparse
import urllib
def parseInputParameters():
parser = argparse.ArgumentParser(description='List and optionally update map services in an ArcGIS Server site.')
parser.add_argument('--server', help='The URL of the ArcGIS Server site to work against. Only built-in authentication is supported.', required=True)
parser.add_argument('--user', help='Username of the administrative account', required=True)
parser.add_argument('--password', help='Password of the specified user account.', required=True)
parser.add_argument('--update', action='store_true', help='Specify this parameter to change all Pro-based services from dedicated to shared instances.')
args = parser.parse_args()
return args
def listServices(server):
arcmapsvcs = []
prosvcs = []
sharedinstancesvcs = []
for folder in server.services.folders:
# skip the system folders
if folder in ['Hosted', 'DataStoreCatalogs', 'System', 'Utilities']: continue
for service in server.services.list(folder=folder):
# bug reports suggest that some services don't have a type.. this is odd, but we skip them to avoid a crash
if 'type' not in service.properties: continue
# skip everything that's not a map service; we don't support anything else in the shared pool at 10.7.x - 10.9.x
if service.properties['type'] != 'MapServer': continue
# the provider value is case-sensitive!
if service.properties['provider'] == 'ArcObjects': # provider='ArcObjects' means the service is running under the ArcMap runtime i.e. published from ArcMap
arcmapsvcs.append(service)
elif service.properties['provider'] == 'ArcObjects11': # provider='ArcObjects11' means the service is running under the ArcGIS Pro runtime i.e. published from ArcGIS Pro
prosvcs.append(service)
elif service.properties['provider'] == 'DMaps': # provider='DMaps' means the service is running in the shared instance pool (and thus running under the ArcGIS Pro provider runtime)
sharedinstancesvcs.append(service)
else: pass # whoa nelly! unknown type of provider.. must be a fancy new server released after this script was written
return (arcmapsvcs, prosvcs, sharedinstancesvcs)
args = parseInputParameters()
print('Connecting to %s..' % args.server)
import arcgis.gis.server
server = arcgis.gis.server.Server(args.server, username=args.user, password=args.password)
print("Connected, enumerating services..")
(arcmapsvcs, prosvcs, sharedinstancesvcs) = listServices(server)
print()
if len(arcmapsvcs) == 0:
print('There are no services published from ArcMap. Impressive!')
else:
print('Services from ArcMap not eligible to run in the shared instance pool:')
for service in arcmapsvcs:
print('- ' + service.properties['serviceName'])
# imagine what uncommenting this would do..
#if args.update:
# data = urllib.parse.urlencode({ 'token' : service._con.token, 'provider' : 'ArcObjects11', 'f' : 'json' }).encode('ascii')
# with urllib.request.urlopen(service.url + '/changeProvider', data) as f:
# print(f.read().decode('utf-8'))
print()
if len(prosvcs) == 0:
print('There are no services published from ArcGIS Pro that are running with dedicated instances.')
else:
print('Services from ArcGIS Pro that may be eligible to run in the shared instance pool:')
for service in prosvcs:
print('- ' + service.properties['serviceName'])
# switch Pro-based service to shared instance pool
if args.update:
# updating the provider can only be done via the dedicated changeProvider operation, it can't be done by
# simply editing the service properties directly (backwards compatibility concession to avoid older
# ArcGIS Desktop clients from modifying this property incorrectly)
data = urllib.parse.urlencode({ 'token' : service._con.token, 'provider' : 'DMaps', 'f' : 'json' }).encode('ascii')
with urllib.request.urlopen(service.url + '/changeProvider', data) as f:
print(f.read().decode('utf-8'))
print()
if len(sharedinstancesvcs) == 0:
print('There are no services published from ArcGIS Pro that are running in the shared instance pool.')
else:
print('Services from ArcGIS Pro already running in the shared instance pool:')
for service in sharedinstancesvcs:
print('- ' + service.properties['serviceName'])