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 > List Security Groups

List Security Groups

List all Security Groups for the specified cloud.

icon_curl_v1.png    icon_rs_api_client_v1.png     

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="2112"
curl -i -H X_API_VERSION:1.5 -b mycookie -X GET https://my.rightscale.com/api/clouds/$CLOUD/security_groups.xml

Tip:  Get the Cloud ID from the API (see List Clouds) and parse the output or from within the RightScale Dashboard:

  • Login and navigate to:  Clouds > CloudName
  • Click on or hover over any of the cloud's supported resources.  Note the number after the ".../clouds/<CloudID>/..." for the goto URL (typically displayed in the lower left of a browser if you hover over the resource).
  • Important!  Although you can obtain the Cloud ID from the Dashboard UI, you cannot obtain cloud resource information that way. (For example, Security Groups, Instance Types, Instances, etc.  IDs for cloud resources must be retrieved via the API.)

Sample Output

Note: XML format without the return headers.

<?xml version="1.0" encoding="UTF-8"?>
<security_groups>
  <security_group>
    <links>
      <link href="/api/clouds/2112/security_groups/DEU7O32167MJ4" rel="self"/>
      <link href="/api/clouds/2112" rel="cloud"/>
      <link href="/api/clouds/2112/security_groups/DEU7O32167MJ4/security_group_rules" rel="security_group_rules"/>
    </links>
    <resource_uid>77df9203-2e72-4cae-95e4-87ae2237f856</resource_uid>
    <name>default</name>
    <actions></actions>
  </security_group>
  <security_group>
    <links>
      <link href="/api/clouds/2112/security_groups/1ISPTV2CHIRVV" rel="self"/>
      <link href="/api/clouds/2112" rel="cloud"/>
      <link href="/api/clouds/2112/security_groups/1ISPTV2CHIRVV/security_group_rules" rel="security_group_rules"/>
    </links>
    <resource_uid>e375de13-a08f-4432-9fff-d52ce40c3f2d</resource_uid>
    <name>Port_8000</name>
    <actions></actions>
  </security_group>
</security_groups>

right_api_client

Sample Call

require 'rubygems'
require 'pp'                          # Require pretty print Ruby gem
require 'right_api_client'            # RightScale API client gem

user = 'greg.doe@example.com'         # Set user email address for using the Dashboard
acct = '1234'                         # Set the account ID
pass = 'SomeSecurePassword'           # Set the password for the user.  Create client object so you can use the API.
@client = RightApi::Client.new(:email => user, :password => pass, :account_id => acct)
#
# Setup and authenticate above. Set and use additional variables below, display output, etc.
#
cloud_id = '2112'                     # Set the Cloud ID I want to list Security Groups for
instance_types = @client.clouds(:id => cloud_id).show.security_groups.index           # Get the Security Groups
pp instance_types                     # Print the Security Groups

Example Output

[#<RightApi::ResourceDetail resource_type="security_group", name="monkey_private_ports_open", resource_uid="318d3349-5b95-442b-be4a-b5ae3c20d527">,
 #<RightApi::ResourceDetail resource_type="security_group", name="wills_test", resource_uid="56f86e69-97f1-43d7-adfa-3ca1f579ccf6">,
 #<RightApi::ResourceDetail resource_type="security_group", name="default", resource_uid="77df9203-2e72-4cae-94e4-87ae2237f856">,
 #<RightApi::ResourceDetail resource_type="security_group", name="qa_test_group", resource_uid="8968e13b-1a64-5394-931e-3382513813cb">,
 #<RightApi::ResourceDetail resource_type="security_group", name="jg_del", resource_uid="a5b92936-bce1-4e51-8d9d-242f2dfac7e0">,
 #<RightApi::ResourceDetail resource_type="security_group", name="jg_hackTest", resource_uid="acd97974-9d2e-4692-be7e-db6d3d12b313">,
 #<RightApi::ResourceDetail resource_type="security_group", name="Port_8000", resource_uid="e375de13-a08f-4832-9fff-d52ce40c3f2d">,
 #<RightApi::ResourceDetail resource_type="security_group", name="My Test SG", resource_uid="f6c38e18-bc20-12a0-a753-1c5dadc43aeb">]

PowerShell

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

Example Call

#get cookie container from authentication $cookieContainer
$cloudId="2175"

$webRequest = [System.Net.WebRequest]::Create("https://my.rightscale.com/api/clouds/$cloudId/security_groups.xml")
$webRequest.Method = "GET"
$webRequest.CookieContainer = $cookieContainer
$webRequest.Headers.Add("X_API_VERSION", "1.5");

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

Sample Output

Note:  Output truncated for brevity sake.  The second Security Group shown was created with the example call shown above.

<?xml version="1.0" encoding="UTF-8"?>
<security_groups>
  <security_group>
    <links>
      <link rel="self" href="/api/clouds/2175/security_groups/5DVK9AHT956N6"/>
      <link rel="cloud" href="/api/clouds/2175"/>
      <link rel="security_group_rules" href="/api/clouds/2175/security_groups/5DVK9AHT956N6/security_group_rules"/>
    </links>
    <description>Internal traffic from default allowed</description>
    <actions></actions>
    <name>default</name>
    <resource_uid>default</resource_uid>
  </security_group>
  <security_group>
    <links>
      <link rel="self" href="/api/clouds/2175/security_groups/50E6OTVJ9KDHG"/>
      <link rel="cloud" href="/api/clouds/2175"/>
      <link rel="security_group_rules" href="/api/clouds/2175/security_groups/50E6OTVJ9KDHG/security_group_rules"/>
    </links>
    <description>Standard Security Group for use in my API Sandbox</description>
    <actions></actions>
    <name>Security Group for API Sandbox</name>
    <resource_uid>sg-177f7b350</resource_uid>
  </security_group>

.  . .  output truncated . . .


Postman

See the List and Show Assets examples (RightScale API 1.6 Guide:  Appendix A - APEye Tools > Google Chrome Postman Plugin)

You must to post a comment.
Last modified
12:53, 17 Dec 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.