Note: Please go to docs.rightscale.com to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > Reference Info > Macro Reference Documentation

Macro Reference Documentation

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

 

Below is a list of all supported calls that can be used to define valid Javascript calls for RightScale Macro's.  A Macro's underlying code can be modified under its Commands tab.  Macro must be unlocked.  The reference documentation below is useful for customizing an existing Macro.

To learn more about Macros and how to create and run them, see Macros.

 


Notes

'pr_create' vs 'create'

There are two different ways to create a cloud resource or RightScale component.  Use the 'pr_create' prefix if you want the user to specify a name for the resource/component when the macro is executed.  A window prompt will appear and ask the user to specify a name before it creates the component.  You can either leave the parameter blank or specify a default value.

The 'pr_create' option is available on the following create actions:

  • Deployment
  • Server Array
  • EC2 Security Group
  • EC2 SSH Key
  • EC2 Elastic IP
  • SQS Queue
  • S3 Bucket

See example code below.

 deployment_url = pr_create_deployment(
		{
		'nickname':'defaultvalue'
		'description':'This is a test deployment.'
		}
		);

Otherwise, you can use the regular 'create' option which will create the resource/object with the value specified in the code.  See example code below.

deployment_url = create_deployment(
		{
		'nickname': 'ProjectX',
		'description':'This is a test deployment.'
		}
		);

 

Using Brackets for Arrays

Use brackets to enclose any arrays.  For example, if you're assigning multiple tags or associating multiple security groups to a server, you must enclose all of the items in brackets.

'ec2_security_groups_href':[ec2_security_group_21212,ec2_security_group_34343],

-or-

'tags':[tag1,tag2],  

 

Generating Unique Components/Resources

Remember, each component that the macro creates, must be unique.  Therefore, if you're creating multiple components/resources of the same type, we recommend adding a different suffix identifier.  See example below:

Note:  In order to create a security group, you must at least provide one ingress rule. 

ec2_security_group_1234 = pr_create_ec2_security_group(
		{
		'aws_group_name':'defaultvalue'
                'aws_description':'Security Group for MyCompany',
		'cloud_id':'1'
		}
		);

ec2_security_group_5678 = pr_create_ec2_security_group(
		{
		'aws_group_name':'defaultvalue'
                'aws_description':'Security Group for MyCompany',
		'cloud_id':'1'
		}
		);

Specifying hrefs

There are two different ways to specify the href of a component/resource.  You can either explicitly list the href or reference a variable name.  See example below:

var ec2_security_group_1234 = 'https://my.rightscale.com/api/acct/<accountID>/ec2_security_groups/5678';
server_array = create_server_array(
                {
                'ec2_security_group_href':ec2_security_group_1234,
                }
                );

-or-

server_array = create_server_array(
                {
                'ec2_security_group_href':'https://my.rightscale.com/api/acct/<accountID>/ec2_security_groups/5678',
                }
                );

Variable Substitution

Use common Javascript calls to customize any macro. For example, you can define variables for input substitution.  If you run the macro code below, it will prompt you to define a value for the 'variablename' that will be used as the nickname of the created deployment.

var variablename = prompt("Name for the new Deployment","defaultvalue");
deployment_url = create_deployment( { 'nickname': variablename, 'description':'This is a test deployment.' } );

Adding a Timestamp

To help create components that are unique, you can add a timestamp as a suffix to the nickname of a created component.  The example code below will create an SSH Key with a timestamp in the namespace.  (e.g. my-name-here-1284681501203)  (5:02pm)

//Get timestamp 
var d = new Date();
var now = d.getTime();

ec2_ssh_key= create_ec2_ssh_key(
		{
		'cloud_id':'1',
		'aws_key_name':'my-name-here-' + now
		}
		);

AWS Cloud IDs

cloud_id
Value Description
1 aws us-east
2 aws eu-west
3 aws us-west
4 aws ap-singapore
5 aws ap-tokyo
6 aws us-Oregon
7 aws us-SA-São Paulo

 

 

 

 


RightScale Functions

create_deployment

Create a deployment.  'pr_create' option is supported.  See 'pr_create' vs 'create'.

Parameters Description
nickname Nickname of the deployment
description Description of the deployment

 

Example

deployment_url = create_deployment(
		{
		'nickname':''
		'description':'This is a test deployment.'
		}
		);

 

set_deployment_parameter

Defines input parameters at the Deployment level.  The first argument is the href to the deployment.  The second argument is a hash with the key's parameters.  See Understanding Inputs.

Parameters Description
parameters List of inputs that will be defined at the deployment level.

 

Example

set_deployment_parameter(deployment_href,
		{
		'parameters':
		{
		'MEMCACHED_STATS':'ignore:$ignore',
		'PRIVATE_SSH_KEY':'key:Gaming SSH Key:1',
		'DB_HOST_NAME':'text:master.mydeployment.com',
		'MASTER_DB_DNSID':'text:11111',
		'SLAVE_DB_DNSID':'text:11112',
		'WEBSITE_DNS':'env:EC2_PUBLIC_HOSTNAME'
		}
		}
		);

clone_server_template

Clone a ServerTemplate.

Parameters Description
server_template_href href of the ServerTemplate you wish to clone.  You can only clone a ServerTemplate that exists in your local collection.  (i.e. a ServerTemplate that you've already imported/subscribed to from the Library.) 
server_template_library_id required and used only when specifying a ServerTemplate which exists in
the MultiCloud Marketplace. Do not use when only specifying a local ServerTemplate. If you are publishing your macro, all referenced ServerTemplates must also be published and the macro must have this new parameter specified for each of them.

 

Example for server_template_href

var worker_template_href = 'https://my.rightscale.com/api/acct/1/ec2_server_templates/12345';
my_worker_template = clone_server_template(worker_template_href)

Example for server_template_library_id

var my_local_worker_template_href = '
https://my.rightscale.com/api/acct/1/ec2_server_templates/12345'; #
template is not published
var my_published_worker_template_href = '
https://my.rightscale.com/api/acct/1/ec2_server_templates/67890';
var rs_marketplace_worker_template_href = '
https://my.rightscale.com/api/acct/2901/ec2_server_templates/13579';

var my_published_library_id = '34987'; # for my local template 67890
var rs_marketplace_template_id = '2346'; # the marketplace id for account
2901's template 13579

my_worker_template_1 = clone_server_template(my_local_worker_template_href);
my_worker_template_2 = clone_server_template(
my_published_worker_template_href, my_published_library_id);
my_worker_template_3 =
clone_server_template(rs_marketplace_worker_template_href,
rs_marketplace_template_id);

my_worker_template_1 = clone_server_template(my_local_worker_template_href,
'345678'); # or obviously set up a var for the library id


Note: If Account 1 was to publish this macro, then its ServerTemplate 12345 must first be published, and then the library_id of that new object in the marketplace must be used.

set_server_template_parameter

Defines input parameters at the ServerTemplate level.  The first argument is the href to the deployment.  The second argument is a hash with the key's parameters.

Parameters Description
parameters List of inputs for the server to be filled out.

 

Example

set_server_template_parameter(server_template_href,
		{
		'parameters':
		{
                'MON_PROCESSES':'ignore:$ignore',                'CUSTOM_INPUT':'text:custom value',
		'GIT_PRIVATE_KEY':'cred:gitkey',
		'DBAPPLICATION_USER':'text:my_username',
		'CONFIG_FILE':'text:http://svn.mysite.com/app/1.0/',
		'SLAVE_DB_DNSNAME':'cred:DBREPLICATION_USER',
		'MASTER_DB_DNSNAME':'cred:DNSMADEEASY_USER',
		'DBAPPLICATION_PASSWORD':'text:my_password' 
		}
		}
		);

create_ec2_server

Create a Server.

Parameters Description
nickname Nickname of the Server
description Description of the Server
cloud_id The ID for cloud: (1 = us-east; 2 = eu-west; 3 = us-west; 4 = ap)
ec2_availability_zone Name of the availability zone for which the server will be configured.  (e.g. us-east-1a)
instance_type The size of the EC2 Instance (m1.small, m1.medium, etc.)
deployment_href The URL for the deployment that the server will be added to  (e.g. https://my.rightscale.com/api/acct/71/deployments/12345)
ec2_image_href

The href for the EC2 image (AMI) e.g.

https://my.rightsacle.com/api/acct/71/ec2_images/ami-aaafff?cloud_id=1

vpc_subnet_href The href to your VPC Subnet
aki_image_href The href for the Kernel image
ari_image_href The href for the Ramdisk image
ec2_ssh_key_href The href to the SSH Key  (e.g.  https://my.rightscale.com/api/acct/1/ec2_ssh_keys/1234)
ec2_security_groups_href The href(s) for the security group(s) that will be used by the server  (e.g.  https://my.rightscale.com/api/acct/1/ec2_security_groups/1234)
ec2_elastic_ip_href The href for the Elastic IP that will be associated with the server.
server_template_library_id required and used only when specifying a ServerTemplate which exists in
the MultiCloud Marketplace. Do not use when only specifying a local ServerTemplate. If you are publishing your macro, all referenced ServerTemplates must also be published and the macro must have this new parameter specified for each of them.
tags Comma separated list of server tags.  (e.g. [tag1,tag2])

 

Example

server_123456 = create_ec2_server(
		{
		'tags':['tag1','tag2'
			],
		'server_template_href':'https://my.rightscale.com/api/acct/1/ec2_server_templates/12345',
		'ec2_image_href':null,
		'ec2_elastic_ip_href':ec2_elastic_ip_1234,
		'deployment_href':'https://my.rightscale.com/api/acct/1/deployments/1234',
		'ec2_ssh_key_href':ec2_ssh_key_123456,
		'aki_image_href':null,
		'instance_type':null,
		'vpc_subnet_href':null,
		'ec2_security_groups_href':[ec2_security_group_12345
			],
		'ec2_availability_zone':'us-east-1b',
		'ari_image_href':null,
		'nickname':'MyServer',
		'cloud_id':'1'
		}
		);

set_ec2_server_parameter

Defines input parameters at the Server level.  The first argument is the href to the deployment.  The second argument is a hash with the key's parameters.  See Understanding Inputs.

Parameters Description
parameters A list of inputs for the server to be filled out.  You will need to look a server's list of inputs to know what parameters can be set.

 

Example

set_ec2_server_parameter(server_href,
		{
		'parameters':
		{
                'MON_PROCESSES':'ignore:$ignore',                'CUSTOM_INPUT':'text:custom value',
		'GIT_PRIVATE_KEY':'cred:gitkey',
		'DBAPPLICATION_USER':'text:my_username',
		'CONFIG_FILE':'text:http://svn.mysite.com/app/1.0/',
		'SLAVE_DB_DNSNAME':'cred:DBREPLICATION_USER',
		'MASTER_DB_DNSNAME':'cred:DNSMADEEASY_USER',
		'DBAPPLICATION_PASSWORD':'text:my_password' 
		}
		}
		);

create_alert

Create and attach an alert specification.  You can attach an alert specification to either a Server or ServerTemplate.

Parameters Description
name Name of the Alert Specification
description Description of the Alert Specification
file The file or metric that is being monitored (e.g. cpu-0/cpu-idle)
variable Variable used for the alert specification. (e.g. value, state, count)
condition Condition to use for a comparison to the threshold (e.g. >, >=, <, <=, ==, !=)
threshold The threshold is the corresponding value based on the type of variable.  The condition and threshold of the monitored variable must be satisfied in order for an alert to be triggered.  For example, "cpu-0/cpu-idle" must be greater than 70% (e.g. 70) 
duration The length of time (in minutes) that the alert specification's condition and threshold must exist before the alert specification is triggered and an alert is created.
subject_href The href of the Server or ServerTemplate to which the alert will be attached. (e.g. https://my.rightscale.com/api/acct/1/server_templates/12345)
subject_type You can either attach an Alert Specification to a Server or ServerTemplate. (e.g. Server)
escalation_name The name of the Alert Escalation to be called when the Alert Specification's is triggered.

 

Example

alert_1 = create_alert(
                {
                'duration':'1',
                'subject_href':server_1233456,
                'threshold':'pending',
                'variable':'state',
                'file':'RS/server',
                'description':'monitoring server state',
                'condition':'>',
                'name':'alert name',
                'subject_type':'Server',
                'escalation_name':'default'
                }
                );

 

create_server_array

Create an alert-based or queue-based server array.  'pr_create' option is supported.  See 'pr_create' vs 'create'.

Parameters Description
indicator_href The href of the SQS queue. (e.g. queue_12345)
tags Comma separated list of server tags.  (e.g. [tag1,tag2])
array_type Type of server array.  (alert, queue) (e.g. alert)
nickname Nickname for the server array
elasticity Category of elasticity parameters
max_count The maximum number of servers that can be running in a server array at any given time.
resize_down_by The resize down parameter defines how many servers you want to terminate when you scale down.
min_count The minimum number of servers that you should be running in the server array at any given time.
resize_up_by The resize up parameter defines how many servers you want to launch when you scale up.
resize_calm_time The calm time defines how long to wait before another scaling action can occur.  (e.g. 5)
decision_threshold The percent of servers that must vote for the same scaling action before any instances are launched or terminated.  The decision threshold only applies to scaling actions where servers can "vote" for a particular scaling action such as scaling up/down. (e.g. 51)
ec2_ssh_key_href The href to the EC2 SSH Key that will be used by each server instance launched into the server array.  (e.g. ec2_ssh_key_123456)
deployment_href The href to the deployment that the server array is associated with. 
(e.g. https://my.rightscale.com/api/acct/1/deployments/1234)
server_template_href The href to the ServerTemplate that will be used to launch each new server instance in the server array.  (e.g. https://my.rightscale.com/api/acct/1/ec2_server_templates/12345)
server_template_library_id required and used only when specifying a ServerTemplate which exists in
the MultiCloud Marketplace. Do not use when only specifying a local ServerTemplate. If you are publishing your macro, all referenced ServerTemplates must also be published and the macro must have this new parameter specified for each of them.
active The status of the server array.  Only 'active' server arrays will be enabled for scaling.  (true, false)
ec2_security_groups_href The href to the EC2 Security Group that will be used by each server instance launched into the server array.  (e.g. [ec2_security_group_12345])
cloud_id The ID for cloud: (1 = us-east; 2 = eu-west; 3 = us-west; 4 = ap)  (e.g. 1)
audit_queue The href to the Audit Queue
(Only applies to 'queue' types)
elasticity_function Defines how a queue-based server array should scale.  (sqs_queue_size, sqs_item_age)
(Only applies to 'queue' types)
elasticity_params Category of related elasticity parameters based on the type of 'elasticity_function' such such as 'items_per_instance' for 'sqs_queue_size' 
(Only applies to 'queue' types)
items_per_instance Defines the ratio of worker instances per items in the queue.  (e.g. 20)
(Only applies to 'queue' types)
description Description of the server array
ec2_availability_zone The availability zone into which new server instances will be launched. (e.g. us-east-1a)

 

Example: Alert-based

server_array_1234 = create_server_array(
		{
		'tags':[
			],
		'indicator_href':null,
		'server_template_href':'https://my.rightscale.com/api/acct/1/ec2_server_templates/12345',
		'deployment_href':'https://my.rightscale.com/api/acct/1/deployments/23456',
		'elasticity_function':null,
		'array_type':'alert',
		'active':'false',
		'nickname':'My Alert-based Server Array',
		'cloud_id':'1',
		'elasticity':
		{
		'max_count':'20',
		'resize_down_by':'1',
		'min_count':'1',
		'resize_up_by':'1',
		'resize_calm_time':'5',
		'decision_threshold':'51'
		},
		'elasticity_params':
		{
                },

'ec2_security_groups_href':[ec2_security_group_10101], 'ec2_ssh_key_href':ec2_ssh_key_20202, 'audit_queue_href':null, 'description':null } );

 

Example: Queue-based

server_array_5511 = create_server_array(
		{
		'tags':[
			],
		'elasticity':
		{
		'max_count':'20',
		'resize_down_by':null,
		'min_count':'1',
		'resize_up_by':null,
		'resize_calm_time':'5',
		'decision_threshold':'51'
		},
		'elasticity_function':'sqs_queue_size',
		'ec2_ssh_key_href':ec2_ssh_key_10101,
		'deployment_href':'https://my.rightscale.com/api/acct/1/deployments/12345',
		'audit_queue_href':queue_22222,
		'indicator_href':queue_33333,
		'ec2_security_groups_href':[ec2_security_group_44444],
		'server_template_href':'https://my.rightscale.com/api/acct/1/ec2_server_templates/23456',
		'active':'false',
		'nickname':'My Queue-based Server Array',
		'cloud_id':'1',
		'elasticity_params':
		{
		'items_per_instance':'5'
		},
		'array_type':'queue',
		'description':null
		}
		);

 

append_status_panel(msg)

Variable Description
msg What you want to append to the status panel.

 

 


EC2 Functions

create_ec2_security_group

Create an EC2 Security Group.  'pr_create' option is supported.  See 'pr_create' vs 'create'.  

Note: In order to create a new EC2 Security Group you must provide at least one ingress rule.

Parameters Description
aws_group_name Name of the security group
aws_description Description of the security group
cloud_id The ID for cloud: (1 = us-east; 2 = eu-west; 3 = us-west; 4 = ap)

 

Example

ec2_security_group_12345 = create_ec2_security_group(
		{
		'aws_group_name':'defaultvalue'
                'aws_description':'Security Group for MyCompany',
		'cloud_id':'1'
		}
		);

 

add_ingress_rule

Defines the access permissions of an EC2 Security Group.  The first argument is the href to the security group.  The second argument is a hash with the key's parameters. 

Parameters Description
owner The AWS account number that created the security group
group The name of the security group
protocol 'tcp', 'udp' or 'icmp'
cidr_ips IP range (e.g. 192.168.0.1/8)
from_port Port range lower bound
to_port Port range upper bound

 

Example

add_ingress_rule(ec2_security_group_12345,
		{
		'owner':'123412341234',
		'group':'default'
		}
		);

add_ingress_rule(ec2_security_group_12345,
		{
		'protocol':'tcp',
		'cidr_ips':'0.0.0.0/0',
		'from_port':'22',
		'to_port':'22'
		}
		);
add_ingress_rule(ec2_security_group_12345,
		{
		'protocol':'tcp',
		'cidr_ips':'0.0.0.0/0',
		'from_port':'80',
		'to_port':'80'
		}
		);

create_ec2_ssh_key

User will be prompted to specify an 'aws_key_name' when creating the SSH Key.  'pr_create' option is supported.  See 'pr_create' vs 'create'.

Parameters Description
aws_key_name Name of the SSH Key
cloud_id The ID for cloud: (1 = us-east; 2 = eu-west; 3 = us-west; 4 = ap)

 

Example

ec2_ssh_key_1234 = create_ec2_ssh_key(
		{
		'aws_key_name':'defaultvalue'
                'cloud_id':'1'
                }
		);

 

create_ec2_elastic_ip

User will NOT be prompted to specify a nickname when creating the Elastic IP.  'pr_create' option is supported.  See 'pr_create' vs 'create'.

Parameters Description
nickname Name of the Elastic IP
cloud_id The ID for cloud: (1 = us-east; 2 = eu-west; 3 = us-west; 4 = ap)

 

Example

ec2_elastic_ip_12345 = create_ec2_elastic_ip(
		{
                'nickname':'MyElasticIP',
                'cloud_id':'3'
		}
		);

 

create_ec2_ebs_volume

Create an EBS Volume.

Parameters Description
nickname Name of the EBS Volume
description Description of the EBS Volume
cloud_id The ID for cloud: (1 = us-east; 2 = eu-west; 3 = us-west; 4 = ap)
ec2_availability_zone Name of the availability zone where the volume will be created.  (e.g. us-east-1a)
aws_size Size of the EBS volume in gigabytes

 

Example

ec2_ebs_volume_12345 = create_ec2_ebs_volume(
		{
                'nickname':'MyVolume',
                'description':'Some marcom data',
		'cloud_id':'1',
                'ec2_availability_zone':'us-east-1a',
		'aws_size':'1'
		}
		);

 

attach_ec2_ebs_volume

Attach an EBS Volume to a server.

Parameters Description
mount Defines when the volume will be mounted to the instance. Set it to 'boot'. 
Note:  You cannot mount a volume to a server at 'runtime'.
ec2_ebs_volume_href The href of the EBS volume that you're going to attach to the instance.
component_href The href of the component (e.g. server) where the volume will be attached.
device The name of the device where the volume will be attached on the instance.  (e.g. /dev/sdj)

 

Example

attach_ec2_ebs_volume(
		{
		'mount':'boot',
		'ec2_ebs_volume_href':ec2_ebs_volume_1234,
		'component_href':server_111222,
		'device':'/dev/sdj'
		}
		);

 

start_server

Launch a server.

Example

start_server(server_href);

 

stop_server

Terminate a server.

Example

stop_server(server_href);

 

create_queue

Create an SQS Queue.  'pr_create' option is supported.  See 'pr_create' vs 'create'.

Parameters Description
name Name of the Queue
description Description of the Queue
visibility_timeout The time in seconds that a job will remain hidden before it becomes available to other worker instances.
api_generation The queue's API generation.  Always use Gen2 queues.  (e.g. 2)

 

Example

queue_12345 = create_queue(
		{
		'name':'RightGrid_Demo_App_Input_123451234512345',
		'description':null,
		'visibility_timeout':'30',
		'api_generation':'2'
		}
		);

create_bucket

Create an S3 bucket.  'pr_create' option is supported.  See 'pr_create' vs 'create'.

Parameters Description
name Name of the S3 bucket.
cloud_id The ID for cloud: (1 = us-east; 2 = eu-west; 3 = us-west; 4 = ap)

 

Example

bucket_12345 = create_bucket(
		{
		'name':'mybuck',
                'cloud_id':1
		}
		);

 

 

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