def get_nics_from_db(backend=None): """Get network interfaces for each vm in DB. """ backends = get_backends(backend) instances = VirtualMachine.objects.filter(deleted=False, backend__in=backends) instances_nics = {} for instance in instances: nics = {} for n in instance.nics.all(): ipv4 = n.ipv4 nic = {'mac': n.mac, 'network': n.network.backend_id, 'ipv4': ipv4 if ipv4 != '' else None } nics[n.index] = nic instances_nics[instance.id] = nics return instances_nics
def get_servers_from_db(backend=None): backends = get_backends(backend) vms = VirtualMachine.objects.filter(deleted=False, backend__in=backends) return dict(map(lambda x: (x.id, x.operstate), vms))