Skip to content

Instantly share code, notes, and snippets.

@stefhen
Last active September 27, 2017 15:47
Show Gist options
  • Save stefhen/df1b64dd6742d4049d88 to your computer and use it in GitHub Desktop.
Save stefhen/df1b64dd6742d4049d88 to your computer and use it in GitHub Desktop.
RSC Examples

RSC Examples

  • List all accounts you have access to:
rsc cm15 accounts /api/sessions | \
jq '.[] | .name, [.links[] | select(.rel == "self").href][0]' | \
paste -sd"\t\n" - | sort

  • List all clouds you have access to and their URLs:
rsc cm15 index /api/clouds | \
jq '.[] | .display_name, [.links[] | select(.rel == "self").href][0]' | \
paste -sd"\t\n" - | sort

  • List all deployments and their URLs:
rsc cm15 index /api/deployments | \
jq '.[] | .name, [.links[] | select(.rel=="self").href][0]' | \
paste -sd"\t\n" - | sort

  • List all servers in a deployment:
# /api/deployments/:id
rsc cm15 servers /api/deployments/397198001

  • List all operational servers in a deployment:
# /api/deployments/:id
rsc cm15 servers /api/deployments/542756004 |  jq '.[] | select(.state=="operational")'

  • Get detailed information on all servers in a deployment:
# /api/deployments/:id
rsc cm16 show /api/deployments/542756004 view=full

  • List all ServerTemplate HREF's in a deployment:
# /api/deployments/:id
rsc cm16 show /api/deployments/542756004 view=full | jq '.instances[].server_template.href'

  • List all account groups:
rsc cm15 index /api/account_groups | \
jq '.[] | .name, [.links[] | select(.rel=="self").href][0]' | \
paste -sd"\t\n" - | sort

  • Find instances by tag:
# resource_type: value must be one of servers,
# instances, volumes, volume_snapshots, deployments,
# server_templates, multi_cloud_images, images, server_arrays, accounts.
rsc cm15 by_tag /api/tags/by_tag tags[]="stefhen:active=true" resource_type=instances

  • List all operational server IP's in a deployment:
# /api/deployments/:id
rsc cm15 servers /api/deployments/542756004 |  \
jq '.[] | select(.state=="operational").links[] | select(.rel=="current_instance").href' | \
xargs -n 1 rsc cm15 show | jq '.name, .public_ip_addresses[0], .private_ip_addresses[0]' | \
paste -sd"  \n" - | sort

  • Clone a deployment:
# /api/deployments/:id
rsc cm15 clone /api/deployments/542756004 \
deployment[name]="Cloned Deployment" deployment[description]="New Description Here"

  • Show inputs of an instance:
# /api/clouds/:cloud_id/instances/:instance_id/inputs
rsc cm15 index /api/clouds/6/instances/2DUMVRT19V8P3/inputs

  • Create ServerTemplate:
# /api/server_templates
rsc cm15 create /api/server_templates server_template[name]="Name here" \
server_template[description]="Description here"

  • Find a specific AMI in us-west-2:
rsc --xm '.rel:val("self") ~ .href' cm15 index /api/clouds/6/images \
 'filter[]=resource_uid==ami-46a3b427

  • Find instance URL of current running server:
rsc --rl10 --x1 ':has(.rel:val("self")).href' cm15 index_instance_session /api/sessions/instance

  • Does this server have tag rs_cluster:role=master?
# Find this server ID
ID=$(rsc --rl10 --x1 ':has(.rel:val("self")).href' cm15 index_instance_session /api/sessions/instance)
# Find href of `rs_cluster:role=master` tag
TAG=$(rsc --rl10 cm15 by_tag /api/tags/by_tag "tags[]=rs_cluster:role=master" resource_type=instances --x1 .links.href)

if [ $ID == $TAG ]

  • Create tag
 rsc --rl10 cm15 multi_add /api/tags/multi_add "resource_hrefs[]=/api/clouds/1/instances/DTABBMVM3853C" \
 "tags[]=test:name=true"

  • Delete tag
rsc --rl10 cm15 multi_delete /api/tags/multi_delete "resource_hrefs[]=/api/clouds/1/instances/DTABBMVM3853C" \
"tags[]=test:stefhen=true"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment