Delete a server based on the specified server ID.
Table of Contents
Prerequisite: Example assumes you have previously authenticated, and your valid session cookie is in 'mycookie'.
#!/bin/sh -e SERVER="532922001" curl -i -H X_API_VERSION:1.5 -b mycookie -X DELETE https://my.rightscale.com/api/servers/$SERVER
HTTP/1.1 204 No Content Server: nginx/1.0.15 Date: Fri, 12 Oct 2012 16:25:00 GMT Connection: keep-alive Status: 204 No Content X-Runtime: 1390 X-Request-Uuid: 6c1eb0c8c21b4835ad425d1bb6fb2b59 Set-Cookie: _session_id=92ede080c999a3e5734035f582d11b0e; path=/; Secure; HttpOnly Cache-Control: no-cache
require 'rubygems' require 'pp' # Require pretty print Ruby gem require 'right_api_client' # RightScale API client gem user = 'email@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. # server_id = '626129001' pp @client.servers(:id => server_id).destroy
If the "destroy" method was not prefaced with "pp" (pretty print), then no output is returned, the action (delete/destroy) is executed with no output.
Note: Similar to the http/curl example, you cannot delete a running or "next" server. In the above right_api_client call you will receive a message similar to:
/usr/lib64/ruby/gems/1.8/gems/right_api_client-1.5.9/lib/right_api_client/client.rb:215:in `do_delete': Error: HTTP Code: 422, Response body: ActionNotAllowed: The server has a current instance. (RightApi::Exceptions::ApiException)
© 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.