Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def build_vms_by_net(data):
- data = [data]
- returnData = []
- for i,obj in enumerate(data):
- if 'value' in obj:
- inner = obj['value']
- for j, obj2 in enumerate(inner):
- config = obj2['properties']['ipConfigurations']
- for k, obj3 in enumerate(config):
- if '/virtualNetworks/' in obj3['properties']['subnet']['id']:
- vnetvals = obj3['properties']['subnet']['id'].split('/')
- vnet = vnetvals[vnetvals.index('virtualNetworks')+1]
- else:
- vnet = ''
- try:
- vmvals = obj2['properties']['virtualMachine']['id'].split('/')
- vm = vmvals[-1]
- subscriptionId = vmvals[vmvals.index('subscriptions')+1]
- resourceGroupName = vmvals[vmvals.index('resourceGroups')+1]
- if (vnet != '' and vm != ''):
- returnData.append({
- "nicId" : obj2['name'],
- "vm" : vm,
- "vnet" : vnet,
- "subscriptionId" : subscriptionId,
- "resourceGroupName" : resourceGroupName
- })
- except Exception:
- # Azure has a habit of orphaning resources, in the event that
- # a nic is not associated with a virtual network, we just don't
- # append its info and continue w/ the rest of the processing
- pass
- vnet = ''
- vm = ''
- return returnData
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement