Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. def build_vms_by_net(data):
  2. data = [data]
  3. returnData = []
  4. for i,obj in enumerate(data):
  5. if 'value' in obj:
  6. inner = obj['value']
  7. for j, obj2 in enumerate(inner):
  8. config = obj2['properties']['ipConfigurations']
  9. for k, obj3 in enumerate(config):
  10. if '/virtualNetworks/' in obj3['properties']['subnet']['id']:
  11. vnetvals = obj3['properties']['subnet']['id'].split('/')
  12. vnet = vnetvals[vnetvals.index('virtualNetworks')+1]
  13. else:
  14. vnet = ''
  15. try:
  16. vmvals = obj2['properties']['virtualMachine']['id'].split('/')
  17. vm = vmvals[-1]
  18. subscriptionId = vmvals[vmvals.index('subscriptions')+1]
  19. resourceGroupName = vmvals[vmvals.index('resourceGroups')+1]
  20. if (vnet != '' and vm != ''):
  21. returnData.append({
  22. "nicId" : obj2['name'],
  23. "vm" : vm,
  24. "vnet" : vnet,
  25. "subscriptionId" : subscriptionId,
  26. "resourceGroupName" : resourceGroupName
  27. })
  28. except Exception:
  29. # Azure has a habit of orphaning resources, in the event that
  30. # a nic is not associated with a virtual network, we just don't
  31. # append its info and continue w/ the rest of the processing
  32. pass
  33. vnet = ''
  34. vm = ''
  35. return returnData
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement