How to switch all services from “Dedicated” to “Shared” in one go?

557
3
Jump to solution
10-04-2019 02:16 AM
JamalNUMAN
Esteemed Contributor

How to switch all services from “Dedicated” to “Shared” in one go?

 

I couldn’t figure out how to switch all services from “Dedicated” to “Shared” in one go

----------------------------------------
Jamal Numan
Geomolg Geoportal for Spatial Information
Ramallah, West Bank, Palestine
1 Solution

Accepted Solutions
JonathanQuinn
Esri Frequent Contributor

Any request to the Admin API can be scripted. If there isn't a built-in function within the Python API, watch the network traffic using Fiddler or your browsers dev tools and re-create the request yourself:

import urllib
import urllib2
import json
import traceback
import ssl

base_url = 'https://machine.domain.com:6443/arcgis'
username = 'admin'
password = 'admin'
service = "<service name>"

#Function to open URLs
def openUrl(url,params):
    try:
        if not params:
            params = {"f":"json"}
        else:
            params.update({"f":"json"})
        encoded_params = str.encode(urllib.urlencode(params))
        request = urllib2.Request(url)
        sslContext = ssl._create_unverified_context()
        request.add_header('referer',base_url)
        response = urllib2.urlopen(request,encoded_params, context=sslContext)
        decodedResponse = response.read().decode('utf-8')
        jsonResponse = json.loads(decodedResponse)
        return jsonResponse
    except Exception as e:
        raise Exception("Unable to open {} - {}".format(url,e))

#Get a token
token_params = dict(username=username,
                    password=password,
                    client='referer',
                    referer=base_url)
token_url = '{}/tokens/generateToken'.format(base_url)
token = openUrl(token_url,token_params)['token']

#Change provider from ArcObjects11 to DMaps
changeProviderURL = '{}/admin/services/{}.MapServer/changeProvider'.format(base_url,service)
changeProviderParams = dict(provider="DMaps",
                            token=token)
updateProviderResp = openUrl(changeProviderURL,changeProviderParams)
if "status" in updateProviderResp and updateProviderResp['status'] == "success":
    print("Successfully updated {} to be shared".format(service))
else:
    print("Unable to update {} to be shared - {}".format(service,updateProviderResp['messages']))

In order to do all services, you'll need to make requests to the root folder to find all services and then loop through them, and then loop through all folders. Each loop, you'd pass in the service name instead of hard coding it.

View solution in original post

3 Replies
George_Thompson
Esri Frequent Contributor

I am not sure that we have a default way to change all the services to the shared pool. It "may" be able to be done via scripting (ArcPy and/or API). Configure service instance settings—ArcGIS Server Administration (Windows) | ArcGIS Enterprise 

--- George T.
JonathanQuinn
Esri Frequent Contributor

Any request to the Admin API can be scripted. If there isn't a built-in function within the Python API, watch the network traffic using Fiddler or your browsers dev tools and re-create the request yourself:

import urllib
import urllib2
import json
import traceback
import ssl

base_url = 'https://machine.domain.com:6443/arcgis'
username = 'admin'
password = 'admin'
service = "<service name>"

#Function to open URLs
def openUrl(url,params):
    try:
        if not params:
            params = {"f":"json"}
        else:
            params.update({"f":"json"})
        encoded_params = str.encode(urllib.urlencode(params))
        request = urllib2.Request(url)
        sslContext = ssl._create_unverified_context()
        request.add_header('referer',base_url)
        response = urllib2.urlopen(request,encoded_params, context=sslContext)
        decodedResponse = response.read().decode('utf-8')
        jsonResponse = json.loads(decodedResponse)
        return jsonResponse
    except Exception as e:
        raise Exception("Unable to open {} - {}".format(url,e))

#Get a token
token_params = dict(username=username,
                    password=password,
                    client='referer',
                    referer=base_url)
token_url = '{}/tokens/generateToken'.format(base_url)
token = openUrl(token_url,token_params)['token']

#Change provider from ArcObjects11 to DMaps
changeProviderURL = '{}/admin/services/{}.MapServer/changeProvider'.format(base_url,service)
changeProviderParams = dict(provider="DMaps",
                            token=token)
updateProviderResp = openUrl(changeProviderURL,changeProviderParams)
if "status" in updateProviderResp and updateProviderResp['status'] == "success":
    print("Successfully updated {} to be shared".format(service))
else:
    print("Unable to update {} to be shared - {}".format(service,updateProviderResp['messages']))

In order to do all services, you'll need to make requests to the root folder to find all services and then loop through them, and then loop through all folders. Each loop, you'd pass in the service name instead of hard coding it.

MoginrajMohandas
New Contributor III

Pls also refer to the following blog that shares a sample of how to iterate through services and bulk move services from Dedicatd to Shared instances. Move services to shared instances using Python