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
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:
<SPAN class="keyword token">import</SPAN> urllib <SPAN class="keyword token">import</SPAN> urllib2 <SPAN class="keyword token">import</SPAN> json <SPAN class="keyword token">import</SPAN> traceback <SPAN class="keyword token">import</SPAN> ssl base_url <SPAN class="operator token">=</SPAN> <SPAN class="string token">'https://machine.domain.com:6443/arcgis'</SPAN> username <SPAN class="operator token">=</SPAN> <SPAN class="string token">'admin'</SPAN> password <SPAN class="operator token">=</SPAN> <SPAN class="string token">'admin'</SPAN> service <SPAN class="operator token">=</SPAN> <SPAN class="string token">"<service name>"</SPAN> <SPAN class="comment token">#Function to open URLs</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">openUrl</SPAN><SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">,</SPAN>params<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> params<SPAN class="punctuation token">:</SPAN> params <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">"f"</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="string token">"json"</SPAN><SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> params<SPAN class="punctuation token">.</SPAN>update<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="string token">"f"</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="string token">"json"</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN> encoded_params <SPAN class="operator token">=</SPAN> str<SPAN class="punctuation token">.</SPAN>encode<SPAN class="punctuation token">(</SPAN>urllib<SPAN class="punctuation token">.</SPAN>urlencode<SPAN class="punctuation token">(</SPAN>params<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> request <SPAN class="operator token">=</SPAN> urllib2<SPAN class="punctuation token">.</SPAN>Request<SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">)</SPAN> sslContext <SPAN class="operator token">=</SPAN> ssl<SPAN class="punctuation token">.</SPAN>_create_unverified_context<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> request<SPAN class="punctuation token">.</SPAN>add_header<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'referer'</SPAN><SPAN class="punctuation token">,</SPAN>base_url<SPAN class="punctuation token">)</SPAN> response <SPAN class="operator token">=</SPAN> urllib2<SPAN class="punctuation token">.</SPAN>urlopen<SPAN class="punctuation token">(</SPAN>request<SPAN class="punctuation token">,</SPAN>encoded_params<SPAN class="punctuation token">,</SPAN> context<SPAN class="operator token">=</SPAN>sslContext<SPAN class="punctuation token">)</SPAN> decodedResponse <SPAN class="operator token">=</SPAN> response<SPAN class="punctuation token">.</SPAN>read<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>decode<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'utf-8'</SPAN><SPAN class="punctuation token">)</SPAN> jsonResponse <SPAN class="operator token">=</SPAN> json<SPAN class="punctuation token">.</SPAN>loads<SPAN class="punctuation token">(</SPAN>decodedResponse<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> jsonResponse <SPAN class="keyword token">except</SPAN> Exception <SPAN class="keyword token">as</SPAN> e<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">raise</SPAN> Exception<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Unable to open {} - {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">,</SPAN>e<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#Get a token</SPAN> token_params <SPAN class="operator token">=</SPAN> dict<SPAN class="punctuation token">(</SPAN>username<SPAN class="operator token">=</SPAN>username<SPAN class="punctuation token">,</SPAN> password<SPAN class="operator token">=</SPAN>password<SPAN class="punctuation token">,</SPAN> client<SPAN class="operator token">=</SPAN><SPAN class="string token">'referer'</SPAN><SPAN class="punctuation token">,</SPAN> referer<SPAN class="operator token">=</SPAN>base_url<SPAN class="punctuation token">)</SPAN> token_url <SPAN class="operator token">=</SPAN> <SPAN class="string token">'{}/tokens/generateToken'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>base_url<SPAN class="punctuation token">)</SPAN> token <SPAN class="operator token">=</SPAN> openUrl<SPAN class="punctuation token">(</SPAN>token_url<SPAN class="punctuation token">,</SPAN>token_params<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">'token'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token">#Change provider from ArcObjects11 to DMaps</SPAN> changeProviderURL <SPAN class="operator token">=</SPAN> <SPAN class="string token">'{}/admin/services/{}.MapServer/changeProvider'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>base_url<SPAN class="punctuation token">,</SPAN>service<SPAN class="punctuation token">)</SPAN> changeProviderParams <SPAN class="operator token">=</SPAN> dict<SPAN class="punctuation token">(</SPAN>provider<SPAN class="operator token">=</SPAN><SPAN class="string token">"DMaps"</SPAN><SPAN class="punctuation token">,</SPAN> token<SPAN class="operator token">=</SPAN>token<SPAN class="punctuation token">)</SPAN> updateProviderResp <SPAN class="operator token">=</SPAN> openUrl<SPAN class="punctuation token">(</SPAN>changeProviderURL<SPAN class="punctuation token">,</SPAN>changeProviderParams<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="string token">"status"</SPAN> <SPAN class="keyword token">in</SPAN> updateProviderResp <SPAN class="operator token">and</SPAN> updateProviderResp<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'status'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"success"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Successfully updated {} to be shared"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>service<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Unable to update {} to be shared - {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>service<SPAN class="punctuation token">,</SPAN>updateProviderResp<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'messages'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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.
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
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
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.