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 > ServerTemplates > List ServerTemplates

List ServerTemplates

List ServerTemplates available to the account.

Note:  A revision of zero means its a Head revision.

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

Note:  Depending on the account, this can be a fairly expensive (resource intensive) call.  Note the Supplmental section which results in a lighter response.

#!/bin/sh
curl -i -H X_API_VERSION:1.5 -b mycookie -X GET https://my.rightscale.com/api/server_templates.xml

Sample Output

Note

  • HTTP headers not displayed (to save space).
  • Output is also truncated to save space.
<server_template>
    <actions>
      <action rel="commit"/>
      <action rel="clone"/>
    </actions>
    <links>
      <link rel="self" href="/api/server_templates/13"/>
      <link rel="multi_cloud_images" href="/api/server_templates/13/multi_cloud_images"/>
      <link rel="default_multi_cloud_image" href="/api/multi_cloud_images/7239"/>
      <link rel="inputs" href="/api/server_templates/13/inputs"/>
      <link rel="alert_specs" href="/api/server_templates/13/alert_specs"/>
    </links>
    <description>rightgrid_photo_worker(daemon), v1 (based on FC6V2_6)&#13;it is the first really gem version</description>
    <name>rightgrid_photo_worker</name>
    <revision>0</revision>
  </server_template>
. . .
<server_template>
    <actions>
      <action rel="commit"/>
      <action rel="clone"/>
    </actions>
    <links>
      <link rel="self" href="/api/server_templates/20003"/>
      <link rel="multi_cloud_images" href="/api/server_templates/20003/multi_cloud_images"/>
      <link rel="default_multi_cloud_image" href="/api/multi_cloud_images/49"/>
      <link rel="inputs" href="/api/server_templates/20003/inputs"/>
      <link rel="alert_specs" href="/api/server_templates/20003/alert_specs"/>
    </links>
    <description>Development sandbox for Chef recipes.
This does not use right_net in anyway.</description>
    <name>caryp - Chef-Solo</name>
    <revision>0</revision>
  </server_template>
. . .

Supplemental

Using a filter to show only ServerTemplates with "MySQL" in their name.

#!/bin/sh
curl -i -H X_API_VERSION:1.5 -b mycookie \
-d filter[]="name==MySQL" \
-X GET https://my.rightscale.com/api/server_templates.xml

Additional filter to return only ServerTemplates with "MySQL" in their name and "LTS" (lineage reference) in their description.

#!/bin/sh
curl -i -H X_API_VERSION:1.5 -b mycookie \
-d filter[]="name==MySQL" \
-d filter[]="description==LTS" \
-X GET https://my.rightscale.com/api/server_templates.xml

right_api_client

Example Call

Note:  As with many API calls, depending on the account this can be an expensive (resource intensive) operation.

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 = 'SomePassword'                 # 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.
#
pp @client.server_templates.index

Sample Output

[#<RightApi::ResourceDetail resource_type="server_template", name="Transcoding worker">,
 #<RightApi::ResourceDetail resource_type="server_template", name="rightgrid_photo_worker">,
 #<RightApi::ResourceDetail resource_type="server_template", name="MySQL Master Server">,
 #<RightApi::ResourceDetail resource_type="server_template", name="Base ServerTemplate for Linux (v13.1) v1">,
 #<RightApi::ResourceDetail resource_type="server_template", name="Base ServerTemplate for Linux (v13.1) v2">,
 #<RightApi::ResourceDetail resource_type="server_template", name="Base ServerTemplate for Linux (v13.1) v2">,
 #<RightApi::ResourceDetail resource_type="server_template", name="Base ServerTemplate for Linux (RSB)  (v13.2)">]

 

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

$webRequest = [System.Net.WebRequest]::Create("https://my.rightscale.com/api/server_templates.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

Same as bash/curl example above.

You must to post a comment.
Last modified
10:04, 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.