Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. define get_subnet_locations() return $subnet_locations do
  2. @subnets = rs_cm.subnets.get()
  3. $list = []
  4.  
  5. foreach @subnet in @subnets do
  6. $subnet = to_object(@subnet)
  7. $subnet_name = $subnet['details'][0]['name']
  8. $subnet_href = select($subnet['details'][0]['links'], {'rel':'self'})[0]['href']
  9. $subnet_network_href = select($subnet['details'][0]['links'], {'rel':'network'})[0]['href']
  10.  
  11. # get the name of the subnet's network
  12. @network = first(rs_cm.get(href: $subnet_network_href)) # avoid?
  13. $network_name = @network.name
  14.  
  15. # get the name of the subnet's cloud
  16. $cloud_href_split = split($subnet_href, '/')
  17. $subnet_cloud_href = '/' + $cloud_href_split[1] + '/' + $cloud_href_split[2] + '/' + $cloud_href_split[3]
  18. @cloud = first(rs_cm.get(href: $subnet_cloud_href)) # avoid?
  19. $cloud_name = @cloud.name
  20.  
  21. # not all clouds use the concept of DCs or AZs
  22. sub on_error: skip do
  23. $subnet_datacenter_href = select($subnet['details'][0]['links'], {'rel':'datacenter'})[0]['href']
  24. @datacenter = first(rs_cm.get(href: $subnet_datacenter_href)) # avoid?
  25. $datacenter_name = @datacenter.name
  26. end
  27. if ! $datacenter_name
  28. $datacenter_name = '-'
  29. end
  30.  
  31. # append to the subnet locations array in known format
  32. $list_item = $cloud_name + ' :: ' + $datacenter_name + ' :: ' + $network_name + ' :: ' + $subnet_name
  33. $list << $list_item
  34. end
  35. $subnet_locations = sort($list)
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement