Note: Please go to docs.rightscale.com to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > Guides > RightScale API 1.5 > Examples > Security Groups > Create Security Group

Create Security Group

Create a Security Group in the specified cloud.

Note

  • Not all clouds support Security Groups
  • Requires "security_manager" privileges on the account.

 

  

Table of Contents

Curl

Prerequisite:  Example assumes you have previously authenticated, and your valid session cookie is in 'mycookie'.

Example Call

#!/bin/sh -e
CLOUD="1234"    # Must provide the Cloud ID because security groups are cloud specific.
curl -i -H X_API_VERSION:1.5 -b mycookie -X POST \
-d security_group[name]="Security Group for API Sandbox" \
-d security_group[description]="Standard Security Group for use in my API Sandbox" \
https://my.rightscale.com/api/clouds/$CLOUD/security_groups

Sample Output

HTTP/1.1 201 Created
Server: nginx/1.0.15
Date: Fri, 26 Oct 2012 00:05:37 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 201 Created
Location: /api/clouds/2112/security_groups/4ISBSPCJCG3CS
X-Runtime: 1180
X-Request-Uuid: 4d60bcdd36e64220a06a9c0680f5f043
Set-Cookie: rs_gbl=eNotkMmOgkBURf-l1pLwGKSKpBeK3IAIguK0MVYBtswoiLbh3xuS3t3FPWdxPuiCVJS90QgFD6R-UPMI70hVNFa6EaoZUkGUQeAJEZURugX9WcJCxCQachBGmAMIBY4IUr8EEUTCU4wZ9Lo6_GdBgYHt7chMnwJJSrZ0ygh0A_N0pf_kU20-d6v0qSUnW1es6_oezE6LYh7La5-YlEvodhc71OH3vmM2brnXjEM7vnBWpWlZmEq1YW53t9k7WB-3LxsmZSbtGRziiEbYPv5OE--cVYywiTfWeVpWm-DcTrOXL7uKJeVenlLf2hTfK7_VilV1dY3F0mu_hiKvociFsaLJ6z4KdN0fMj1bpw%3D%3D; domain=.rightscale.com; path=/; HttpOnly
Set-Cookie: _session_id=6312c855c21ba86436aeb4deb83a45a2; path=/; Secure; HttpOnly
Cache-Control: no-cache

Note:  Requires "security_manager" privileges on the account, or an HTTP 403 Forbidden is returned.

PowerShell

Prerequisite:  Example assumes you have previously authenticated and your session cookie for subsequent requests is in 'cookieContainer'.

Example Call

$cloudId='2175'    # Set the Cloud ID

$postURL = "https://my.rightscale.com/api/clouds/$cloudId/security_groups"
$stringToPost = "security_group[name]=Security Group for API Sandbox&"+
"security_group[description]=Standard Security Group for use in my API Sandbox"
$bytesToPost = [System.Text.Encoding]::UTF8.GetBytes($stringToPost)


$webRequest = [System.Net.WebRequest]::Create($postURL)
$webRequest.Method = "POST"
$webRequest.Headers.Add("X_API_VERSION","1.5")
$webRequest.CookieContainer = $cookieContainer # recieved from authentication.ps1


$requestStream = $webRequest.GetRequestStream()
$requestStream.Write($bytesToPost, 0, $bytesToPost.Length)
$requestStream.Close()

[System.Net.WebResponse]$response = $webRequest.GetResponse()
$responseStream = $response.GetResponseStream()
$responseStreamReader = New-Object System.IO.StreamReader -ArgumentList $responseStream
[string]$responseString = $responseStreamReader.ReadToEnd()

$responseString

Sample Output

HTTP 201 (created)

You must to post a comment.
Last modified
09:20, 11 Oct 2013

Tags

Classifications

This page has no classifications.

Announcements

None


© 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.