qvm_net.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Show network tree
  5. @author: unman
  6. """
  7. from qubes.qubes import QubesVmCollection
  8. qvm_collection = QubesVmCollection()
  9. qvm_collection.lock_db_for_reading()
  10. qvm_collection.load()
  11. qvm_collection.unlock_db()
  12. qvm_collection.pop(0)
  13. def tree(netvm, padding):
  14. names={}
  15. padding = padding + ' '
  16. connected = netvm.connected_vms
  17. for i in connected:
  18. names[i] = connected[i].name
  19. for name in sorted(names.values()):
  20. vm = qvm_collection.get_qid_by_name(name)
  21. if qvm_collection[vm].is_running():
  22. vm_name = qvm_collection[vm].name + '* '
  23. else:
  24. vm_name = qvm_collection[vm].name
  25. if qvm_collection[vm].is_template():
  26. print(padding,'|->',vm_name,'(Tpl)')
  27. else:
  28. print(padding,'|->',vm_name)
  29. if qvm_collection[vm].is_netvm() :
  30. tree(qvm_collection[vm], padding)
  31. padding=''
  32. for vm in qvm_collection:
  33. if qvm_collection[vm].is_netvm() and not qvm_collection[vm].netvm :
  34. print(qvm_collection[vm].name)
  35. tree(qvm_collection[vm], padding)