Modify several Inputs (e.g. "bulk modify") with a single API call for a specified deployment.
Note: HTTP PUT method is used. If a specified input does not exist, it gets created. If it does exist, its value is set to the one provided. This example modifies inputs at the Deployment level. See the API online reference (for Inputs > multi_update) to construct the URL and modify at the ServerTemplate or server instance level. If you accidentally set the input value twice on the same API call, the last setting takes precedence.
Table of Contents
Prerequisite: Example assumes you have previously authenticated, and your valid session cookie is in 'mycookie'.
Modify the Timezone (text) input and the SVN User/Password (credential) input at the deployment level. A single API call changes all three for all servers in the specified deployment.
Note: The following example uses bulk modify inputs "notation 1.0". Its easy to read, but lengthier to specify. See the Supplemental section below to see the newer "notation 2.0" format.
Important! Notation 1.0 will be deprecated in RightScale API 2.0 in favor of "notation 2.0" format.
Curl on a single line:
#!/bin/sh -e DEPLOYMENT="306795001" # Set the deployment to change inputs for curl -i -H X_API_VERSION:1.5 -b mycookie -d inputs[][name]="rightscale/timezone" -d inputs[][value]="text:US/Pacific" -d inputs[][name]="repo/default/svn_username" -d inputs[][value]="cred:GD_SVN_USERNAME" -d inputs[][name]="repo/default/svn_password" -d inputs[][value]="cred:GD_SVN_PASSWORD" -X PUT https://my.rightscale.com/api/deployments/$DEPLOYMENT/inputs/multi_update
Same script but with curl split into multiple lines and basic in-line comments for readability sake:
#!/bin/sh -e DEPLOYMENT="306795001" # Set the deployment to change inputs for curl -i -H X_API_VERSION:1.5 -b mycookie \ -d inputs[][name]="rightscale/timezone" \ -d inputs[][value]="text:US/Pacific" \ # Change TZ (text) input value -d inputs[][name]="repo/default/svn_username" \ -d inputs[][value]="cred:GD_SVN_USERNAME" \ # Change SVN Username (credential) value -d inputs[][name]="repo/default/svn_password" \ -d inputs[][value]="cred:GD_SVN_PASSWORD" \ # Change the SVN Password (credential) value -X PUT https://my.rightscale.com/api/deployments/$DEPLOYMENT/inputs/multi_update
HTTP/1.1 204 No Content Server: nginx/1.0.15 Date: Wed, 07 Nov 2012 16:53:34 GMT Connection: keep-alive Status: 204 No Content X-Runtime: 62 X-Request-Uuid: 87119d96c03842869fcd36dc6b8131dd Set-Cookie: Cache-Control: no-cache
Note: Navigate or refresh your browser from YourDeployment > Inputs tab. Each input value should be changed, and painted "blue" designating the input was set at the deployment level.
The equivalent example using the more streamlined "notation 2.0" follows.
Important! Notation 1.0 will be deprecated in RightScale API 2.0 in favor of the following "notation 2.0" format.
#!/bin/sh -e DEPLOYMENT="306795001" # Set the deployment to change inputs for curl -i -H X_API_VERSION:1.5 -b mycookie \ -d inputs[rightscale/timezone]="text:US/Pacific", \ -d inputs[repo/default/svn_username]="cred:GD_SVN_USERNAME", \ -d inputs[repo/default/svn_password]="cred:GD_SVN_PASSWORD" \ -X PUT https://my.rightscale.com/api/deployments/$DEPLOYMENT/inputs/multi_update
Prerequisite: Example assumes you have previously authenticated and your session cookie for subsequent requests is in 'cookieContainer'.
The following example modifies several Inputs (APPLICATION_LISTENER_PORT, ZIP_FILE_NAME and OPT_APP_POOL_NAME) for Deployment with ID 306795001.
$deploymentID = "306795001" # Set the actual ID of the deployment to be modified $stringToPut = "inputs[][name]=APPLICATION_LISTENER_PORT&" # One of several Inputs to be modified $stringToPut += "inputs[][value]=text:80&" # Set to 80 $stringToPut += "inputs[][name]=ZIP_FILE_NAME&" $stringToPut += "inputs[][value]=text:thisisazipfile.zip&" # Set to a zip file name $stringToPut += "inputs[][name]=OPT_APP_POOL_NAME&" $stringToPut += "inputs[][value]=text:ASP.NET v4.0" # Set to ASP.NET v4.0 $inputWebRequest = [System.Net.WebRequest]::Create("https://my.rightscale.com/api/deployments/$deploymentID/inputs/multi_update?$stringToPut") $inputWebRequest.Method = "PUT" $inputWebRequest.Headers.Add("X_API_VERSION","1.5") $inputWebRequest.CookieContainer = $cookieContainer $inputWebRequest.ServicePoint.Expect100Continue = $false $inputRequestStream = $inputWebRequest.GetRequestStream() $inputRequestStream.Close() [System.Net.WebResponse]$inputResponse = $inputWebRequest.GetResponse() $inputResponseStream = $inputResponse.GetResponseStream() $inputResponseStreamReader = New-Object System.IO.StreamReader -ArgumentList $inputResponseStream $inputResponse #this is the cookie container for subsequent requests: $cookieContainer
See http/curl output.
© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.