Skip to content

Instantly share code, notes, and snippets.

@srpomeroy
Last active September 12, 2018 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srpomeroy/c1133b43c2843fe363aa360778e17e78 to your computer and use it in GitHub Desktop.
Save srpomeroy/c1133b43c2843fe363aa360778e17e78 to your computer and use it in GitHub Desktop.
Return list of accounts and their shards
# RightScale API Client(rsc): https://github.com/rightscale/rsc
# PowerShell: https://github.com/PowerShell/PowerShell
# jq: https://stedolan.github.io/jq/
# Output All Child Account Names, Numbers, and Shards
# PowerShell
# Requires: RSC and PowerShell
#
# Input:
# $ENDPOINT = Parent account host/shard, i.e. us-3.rightscale.com
# $ACCOUNT_NUMBER = Parent accouunt number
# $REFERSH_TOKEN = Must have enterprise_manager role
#
# Output:
# account_name account_number shard
# ------------ -------------- -----
# Project 1 12345 1
# Project 2 54321 2
# Project 3 25134 3
#
# Command:
(rsc --host=$ENDPOINT --refreshToken=$REFRESH_TOKEN --account=$ACCOUNT_NUMBER cm15 index child_accounts | ConvertFrom-Json) | Select-Object `
@{n='account_name';e={$_.name}},`
@{n='account_number';e={$_.links | Where-Object {$_.rel -eq "self"} | Select-Object -ExpandProperty href | Split-Path -Leaf}}, `
@{n='shard';e={$_.links | Where-Object {$_.rel -eq "cluster"} | Select-Object -ExpandProperty href | Split-Path -Leaf}}
# Linux/Mac shell
# Requires: RSC and jq
#
# Input:
# $ENDPOINT = Parent account host/shard, i.e. us-3.rightscale.com
# $ACCOUNT_NUMBER = Parent accouunt number
# $REFERSH_TOKEN = Must have enterprise_manager
#
# Output:
# [
# {
# "account_name": "Project 1",
# "account_number": "12345",
# "shard": "1"
# },
# {
# "account_name": "Project 2",
# "account_number": "54321",
# "shard": "2"
# },
# {
# "account_name": "Project 3",
# "account_number": "25134",
# "shard": "3"
# }
# ]
#
# Command:
rsc --host=$ENDPOINT --account=$ACCOUNT_NUMBER --refreshToken=$REFRESH_TOKEN cm15 index /api/child_accounts | \
jq '[.[] | {account_name: .name, account_number: [.links[] | select(.rel == "self").href | split("/")[-1]][0], shard: [.links[] | select(.rel == "cluster").href | split("/")[-1]][0]}]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment