xl-qvm-usb-attach.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/python
  2. ##
  3. ## This script is for dom0
  4. ## The syntax is modelled after "xl block-attach"
  5. ##
  6. import sys
  7. import os
  8. import xen.lowlevel.xl
  9. # parse command line
  10. if (len(sys.argv)<4) or (len(sys.argv)>5):
  11. print 'usage: xl-qvm-usb-attach.py <frontendvm-xid> <backendvm-device> <frontendvm-device> [<backendvm-xid>]'
  12. sys.exit(1)
  13. frontendvm_xid=sys.argv[1]
  14. backendvm_device=sys.argv[2]
  15. frontend=sys.argv[3].split('-')
  16. if len(frontend)!=2:
  17. print 'Error: frontendvm-device must be in <controller>-<port> format'
  18. sys.exit(1)
  19. (controller, port)=frontend
  20. backendvm_xid=0
  21. if len(sys.argv)>4:
  22. backendvm_xid=sys.argv[4]
  23. # determine the name of the backend-vm
  24. backendvm_name=xen.lowlevel.xl.ctx().domid_to_name(int(backendvm_xid))
  25. # FIXME: command injection
  26. os.system("xenstore-write /local/domain/%s/backend/vusb/%s/%s/port/%s %s"
  27. % (backendvm_xid, frontendvm_xid, controller, port, backendvm_device))
  28. # FIXME: vm.run
  29. print "### qvm-run %s sudo /usr/lib/qubes/vusb-ctl.py unbind %s" % (backendvm_name, backendvm_device)