Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement