Note: Please go to docs.rightscale.com to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > Guides > Dashboard Users Guide > Design > Macros > Concepts > Using the RightScale API within a RightScale Macro

Using the RightScale API within a RightScale Macro

Table of Contents

Note: Macros are available only in LCP. Macros have been deprecated and are not available in the Unified Cloud Platform.

Overview

Those familiar with Javascript and the RightScale API may find it useful to know that you can use the RightScale API from within a RightScale Macro. 

Example

The following example will clone a ServerTemplate then rename the new one making it easier to find in the RightScale Dashboard. It will ask for the URL from an existing ServerTemplate and a nickname for the cloned one.

The example uses the AJAX XMLHttpRequest object to make the API requests (even though XML does not come into play in the example).  

Note: You have to use the URL of the existing ServerTemplate for URL_of_Template (6th line below) formatted for the RightScale API.  You can use the rdoc to help construct URLs you need.

// Create an instance of XMLHttpRequest to send the name change later
var apiCaller = new XMLHttpRequest();

// Get the new name from the user
var newName = prompt('Please enter the name for the new template');

//clone the template and save the URL, where URL_of_Template is the RS API formatted URL of the orig ServerTemplate
var originalTemplate = prompt('Please enter the URL of the ServerTemplate to clone');
var newTemplate = clone_server_template(originalTemplate);

// Adjust the URL to be API compatible
var requestString = newTemplate.replace("ec2_", "");

// Now lets update that nickname
apiCaller.open("PUT", requestString, "false");
apiCaller.setRequestHeader("X-API-VERSION","1.0");
apiCaller.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
apiCaller.send("server_template[nickname]="+newName);

You must to post a comment.
Last modified
09:41, 22 Jan 2014

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.