Octopus.Script exported 2014-05-16 by bobjwalker belongs to ‘Rackspace’ category.
Change the condition of a node in a Rackspace Cloud Load Balancer.
Parameters
When steps based on the template are included in a project’s deployment process, the parameters below can be set.
Username
Username
Rackspace control panel username
API key
ApiKey
Rackspace control panel user API key
Load Balancer ID
LoadBalancerID
ID of the load balancer, found on the details page in the Rackspace control panel
Node IP address
NodeIpAddress
IP address of load balanced node. Found on the load balancer details page of the Rackspace control panel
New Node Condition
NewCondition
Condition to set the node to. Can either be ‘ENABLED’, ‘DISABLED’ or ‘DRAINING’
Script body
Steps based on this template will execute the following PowerShell script.
$username = $OctopusParameters['Username']
$apiKey = $OctopusParameters['ApiKey']
$loadbalanderId = $OctopusParameters['LoadBalancerID']
$newNodeCondition = $OctopusParameters['NewCondition']
$ipAddress = $OctopusParameters['NodeIpAddress']
if ($newNodeCondition -ne "ENABLED" -and $newNodeCondition -ne "DISABLED" -and $newNodeCondition -ne "DRAINING")
{
throw "Condition must be one of 'ENABLED', 'DISABLED' or 'DRAINING'"
}
# Get token and manipulation URL
$tokensUri = "https://lon.identity.api.rackspacecloud.com/v2.0/tokens"
$tokensBody = @"
{
"auth":
{
"RAX-KSKEY:apiKeyCredentials":
{
"username": "$username",
"apiKey": "$apiKey"
}
}
}
"@
Write-Host "Sending request $tokensBody to $tokensUri"
$tokensResponse = Invoke-WebRequest -Uri $tokensUri -Method Post -Body $tokensBody -ContentType "application/json" -UseBasicParsing
if ($tokensResponse.StatusCode -ne 200)
{
throw "Authorisation failed"
}
$tokensObj = ConvertFrom-Json -InputObject $tokensResponse.Content
$loadBalancerDetails = $tokensObj.access.serviceCatalog | Where {$_.name -eq "cloudLoadBalancers"}
$endpoints = $loadBalancerDetails.endpoints | Select -First 1
$loadbalancerUrl = $endpoints.publicURL
$token = $tokensObj.access.token.id
# Update node
$header = @{}
$header.Add("X-Auth-Token", $token)
$nodesUrl = "$loadbalancerUrl/loadbalancers/$loadbalancerId/nodes"
Write-Host "Getting node details from $nodesUrl"
$nodesResponse = Invoke-WebRequest -Uri $nodesUrl -Method Get -Headers $header -ContentType "application/json" -UseBasicParsing
if ($nodesResponse.StatusCode -ne 200)
{
throw "Getting load balancer details failed"
}
$nodesObj = ConvertFrom-Json -InputObject $nodesResponse.Content
$node = $nodesObj.nodes | Where {$_.address -eq $ipAddress}
$nodeId = $node.id
$updateBody = @"
{
"node": {
"condition" : "$newNodeCondition"
}
}
"@
$updateUrl = "$loadbalancerUrl/loadbalancers/$loadbalancerId/nodes/$nodeId"
Write-Host "Updating node $nodeId to $newNodeCondition"
Write-Host "$updateBody"
Write-Host "$updateUrl"
$updateResponse = Invoke-WebRequest -Uri $updateUrl -Body $updateBody -Method Put -Headers $header -ContentType "application/json" -UseBasicParsing
if ($updateResponse.StatusCode -ne 202)
{
throw "Updating load balancer failed"
}
Provided under the Apache License version 2.0.
To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.
{
"Id": "94aa35a3-0a0c-4c45-8781-98006bda3bcd",
"Name": "Rackspace - Update Load Balancer",
"Description": "Change the condition of a node in a Rackspace Cloud Load Balancer.",
"Version": 4,
"ExportedAt": "2014-05-16T10:29:42.481+00:00",
"ActionType": "Octopus.Script",
"Author": "bobjwalker",
"Parameters": [
{
"Name": "Username",
"Label": "Username",
"HelpText": "Rackspace control panel username",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "ApiKey",
"Label": "API key",
"HelpText": "Rackspace control panel user API key",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "LoadBalancerID",
"Label": "Load Balancer ID",
"HelpText": "ID of the load balancer, found on the details page in the Rackspace control panel",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "NodeIpAddress",
"Label": "Node IP address",
"HelpText": "IP address of load balanced node. Found on the load balancer details page of the Rackspace control panel",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "NewCondition",
"Label": "New Node Condition",
"HelpText": "Condition to set the node to. Can either be 'ENABLED', 'DISABLED' or 'DRAINING'",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
}
],
"Properties": {
"Octopus.Action.Script.ScriptBody": "$username = $OctopusParameters['Username']\n$apiKey = $OctopusParameters['ApiKey']\n$loadbalanderId = $OctopusParameters['LoadBalancerID']\n$newNodeCondition = $OctopusParameters['NewCondition']\n$ipAddress = $OctopusParameters['NodeIpAddress']\n\nif ($newNodeCondition -ne \"ENABLED\" -and $newNodeCondition -ne \"DISABLED\" -and $newNodeCondition -ne \"DRAINING\")\n{\n throw \"Condition must be one of 'ENABLED', 'DISABLED' or 'DRAINING'\"\n}\n\n# Get token and manipulation URL\n\n$tokensUri = \"https://lon.identity.api.rackspacecloud.com/v2.0/tokens\"\n$tokensBody = @\"\n{\n \"auth\":\n {\n \"RAX-KSKEY:apiKeyCredentials\":\n { \n \"username\": \"$username\", \n \"apiKey\": \"$apiKey\"\n }\n } \n}\n\"@\n\nWrite-Host \"Sending request $tokensBody to $tokensUri\"\n\n$tokensResponse = Invoke-WebRequest -Uri $tokensUri -Method Post -Body $tokensBody -ContentType \"application/json\" -UseBasicParsing\n\nif ($tokensResponse.StatusCode -ne 200)\n{\n throw \"Authorisation failed\"\n}\n\n$tokensObj = ConvertFrom-Json -InputObject $tokensResponse.Content\n\n$loadBalancerDetails = $tokensObj.access.serviceCatalog | Where {$_.name -eq \"cloudLoadBalancers\"}\n$endpoints = $loadBalancerDetails.endpoints | Select -First 1\n$loadbalancerUrl = $endpoints.publicURL\n$token = $tokensObj.access.token.id\n\n# Update node\n\n$header = @{}\n$header.Add(\"X-Auth-Token\", $token)\n$nodesUrl = \"$loadbalancerUrl/loadbalancers/$loadbalancerId/nodes\"\n\nWrite-Host \"Getting node details from $nodesUrl\"\n\n$nodesResponse = Invoke-WebRequest -Uri $nodesUrl -Method Get -Headers $header -ContentType \"application/json\" -UseBasicParsing\n\nif ($nodesResponse.StatusCode -ne 200)\n{\n throw \"Getting load balancer details failed\"\n}\n\n$nodesObj = ConvertFrom-Json -InputObject $nodesResponse.Content\n$node = $nodesObj.nodes | Where {$_.address -eq $ipAddress}\n$nodeId = $node.id\n\n$updateBody = @\"\n{\n \"node\": {\n \"condition\" : \"$newNodeCondition\"\n }\n}\n\"@\n$updateUrl = \"$loadbalancerUrl/loadbalancers/$loadbalancerId/nodes/$nodeId\"\n\nWrite-Host \"Updating node $nodeId to $newNodeCondition\"\nWrite-Host \"$updateBody\"\nWrite-Host \"$updateUrl\"\n\n$updateResponse = Invoke-WebRequest -Uri $updateUrl -Body $updateBody -Method Put -Headers $header -ContentType \"application/json\" -UseBasicParsing\n\nif ($updateResponse.StatusCode -ne 202)\n{\n throw \"Updating load balancer failed\"\n}",
"Octopus.Action.Script.Syntax": "PowerShell"
},
"Category": "Rackspace",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/rackspace-update-load-balancer.json",
"Website": "/step-templates/94aa35a3-0a0c-4c45-8781-98006bda3bcd",
"Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADBQTFRFeXl5s7Oz0VhnAAAA1NTU5J+nNzc3////uAAXvRUq2nqH++/w7+/vyDlK9t/i8MfM40F2ugAAB3JJREFUeNrsnduS4iAQQAGBCITw/3+7OjOuJiHQF8joFNQ+TKlr5aTv3QTF9EeWGCADZIAMkAEyQAbIABkgA2SADJABMkAGyAAZIG8IIqX+/qc/G0RcXpa1Qsj5I0FWHA8cIeYPA5lzHD8w8pNADjm+ltCfAlLmuMtFfgSIvAAW3VzOAgkgDgbKWSD6Al1WhjcGgXPcUfTbgsz2K/7ZewgU4uuPsn69K4iWOpet3JiaCeV3k8abNdxosijyo0B+aKTgq9e7pPEZF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H74jPsbID8ofwHkC0X9CZC7A/srINMAGSADZIAMkAEyQAbIABkgA2SADJABMkAGyAD5uPVPgAEAa7HuHFW/2YcAAAAASUVORK5CYII=",
"$Meta": {
"Type": "ActionTemplate"
}
}
Page updated on Friday, May 16, 2014