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 > Servers > List all Servers in a Deployment

List all Servers in a Deployment

List all Servers in a given Deployment.

icon_curl_v1.png    icon_rs_api_client_v1.png   icon_powershell_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
DEPLOYMENT="306795001"
curl -i -H X_API_VERSION:1.5 -b mycookie -X GET https://my.rightscale.com/api/deployments/$DEPLOYMENT/servers.xml

Sample Output

Note

  • Truncated XML output without headers included (to save space). 
  • Only one server in this example deployment (or all additional servers would have been displayed).
<?xml version="1.0" encoding="UTF-8"?>
<servers>
  <server>
    <updated_at>2012/10/09 21:42:04 +0000</updated_at>
    <links>
      <link href="/api/servers/527725001" rel="self"/>
      <link href="/api/deployments/306795001" rel="deployment"/>
      <link href="/api/clouds/2112/instances/2BFJC99QC8FJA" rel="current_instance"/>
      <link href="/api/clouds/2112/instances/B469CS55K5VRQ" rel="next_instance"/>
      <link href="/api/servers/527725001/alert_specs" rel="alert_specs"/>
    </links>
    <description></description>
    <created_at>2012/10/09 21:41:34 +0000</created_at>
    <name>Base ServerTemplate for Linux (v12.11.0-LTS)</name>
    <actions>
      <action rel="terminate"/>
    </actions>
    <state>operational</state>
  </server>
</servers>

right_api_client

Example 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 = '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.
#
deployment_id = '306795001'           # Set the Deployment ID I want to show Servers for
pp @client.deployments(:id => deployment_id).show.servers.index

Sample Output

The following reveals 7 servers in the specified deployment.

[#<RightApi::ResourceDetail resource_type="server", name="Base ServerTemplate for Linux (v12.11.0-LTS)">,
#<RightApi::ResourceDetail resource_type="server", name="Bethany_app_server1">,
#<RightApi::ResourceDetail resource_type="server", name="Bethany_app_server2">,
#<RightApi::ResourceDetail resource_type="server", name="Bethany_db_server1">,
#<RightApi::ResourceDetail resource_type="server", name="Bethany_db_server2">,
#<RightApi::ResourceDetail resource_type="server", name="Bethany_load_balancer1">,
#<RightApi::ResourceDetail resource_type="server", name="Bethany_load_balancer2">]

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
$DEPLOYMENT="366638001"     # Set the Deployment ID to list Servers for

$webRequest = [System.Net.WebRequest]::Create("https://my.rightscale.com/api/deployments/$DEPLOYMENT/servers.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: Two servers are listed in the sample output.  One is inactive, the other is operational.  The operational servers highlights (in bold) both the Current and Next Instance IDs.  These IDs are often needed for other API calls (such as List Current or Next Inputs).

<?xml version="1.0" encoding="UTF-8"?>
<servers>
  <server>
    <state>inactive</state>
    <updated_at>2013/10/09 22:38:22 +0000</updated_at>
    <created_at>2013/10/09 21:06:18 +0000</created_at>
    <links>
      <link rel="self" href="/api/servers/931047001"/>
      <link rel="deployment" href="/api/deployments/366638001"/>
      <link rel="next_instance" href="/api/clouds/2175/instances/FULA6ROBR8RR4"/>
      <link rel="alert_specs" href="/api/servers/931047001/alert_specs"/>
      <link rel="alerts" href="/api/servers/931047001/alerts"/>
    </links>
    <description></description>
    <actions>
      <action rel="launch"/>
      <action rel="clone"/>
    </actions>
    <name>Base ServerTemplate for Linux (RSB) (v13.5)</name>
  </server>
  <server>
    <state>operational</state>
    <updated_at>2013/10/09 21:25:54 +0000</updated_at>
    <created_at>2013/10/09 21:23:59 +0000</created_at>
    <links>
      <link rel="self" href="/api/servers/931067001"/>
      <link rel="deployment" href="/api/deployments/366638001"/>
      <link rel="current_instance" href="/api/clouds/2175/instances/34NM8MNFGPE45"/>
      <link rel="next_instance" href="/api/clouds/2175/instances/3PLSU71PF2BJS"/>
      <link rel="alert_specs" href="/api/servers/931067001/alert_specs"/>
      <link rel="alerts" href="/api/servers/931067001/alerts"/>
    </links>
    <description></description>
    <actions>
      <action rel="terminate"/>
      <action rel="clone"/>
    </actions>
    <name>Base ServerTemplate for Linux (RSB) (v13.5.0-LTS)</name>
  </server>
</servers>

See also

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