Last active
September 12, 2018 20:24
-
-
Save srpomeroy/c1133b43c2843fe363aa360778e17e78 to your computer and use it in GitHub Desktop.
Return list of accounts and their shards
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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