Created
April 30, 2017 06:57
-
-
Save flaccid/b181c9de762dc4e0c554a7c179125eb5 to your computer and use it in GitHub Desktop.
get_subnet_locations RCL
This file contains hidden or 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
define get_subnet_locations() return $subnet_locations do | |
@subnets = rs_cm.subnets.get() | |
$list = [] | |
foreach @subnet in @subnets do | |
$subnet = to_object(@subnet) | |
$subnet_name = $subnet['details'][0]['name'] | |
$subnet_href = select($subnet['details'][0]['links'], {'rel':'self'})[0]['href'] | |
$subnet_network_href = select($subnet['details'][0]['links'], {'rel':'network'})[0]['href'] | |
# get the name of the subnet's network | |
@network = first(rs_cm.get(href: $subnet_network_href)) # avoid? | |
$network_name = @network.name | |
# get the name of the subnet's cloud | |
$cloud_href_split = split($subnet_href, '/') | |
$subnet_cloud_href = '/' + $cloud_href_split[1] + '/' + $cloud_href_split[2] + '/' + $cloud_href_split[3] | |
@cloud = first(rs_cm.get(href: $subnet_cloud_href)) # avoid? | |
$cloud_name = @cloud.name | |
# not all clouds use the concept of DCs or AZs | |
sub on_error: skip do | |
$subnet_datacenter_href = select($subnet['details'][0]['links'], {'rel':'datacenter'})[0]['href'] | |
@datacenter = first(rs_cm.get(href: $subnet_datacenter_href)) # avoid? | |
$datacenter_name = @datacenter.name | |
end | |
if ! $datacenter_name | |
$datacenter_name = '-' | |
end | |
# append to the subnet locations array in known format | |
$list_item = $cloud_name + ' :: ' + $datacenter_name + ' :: ' + $network_name + ' :: ' + $subnet_name | |
$list << $list_item | |
end | |
$subnet_locations = sort($list) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment