spacepaste

  1.  
  2. #!/usr/bin/python
  3. from ctypes import *
  4. from ctypes.util import find_library
  5. import os, platform
  6. xs_transaction_t = c_ulong
  7. struct_xs_handle = c_void_p
  8. xenstore = CDLL(find_library("xenstore"))
  9. xs_read = xenstore.__getattr__("xs_read")
  10. xs_read.argtypes = [ struct_xs_handle, xs_transaction_t, c_char_p, POINTER(c_uint) ]
  11. xs_read.restype = c_char_p
  12. xs_domain_open = xenstore.__getattr__("xs_domain_open")
  13. xs_domain_open.restype = struct_xs_handle
  14. xs_transaction_start = xenstore.__getattr__("xs_transaction_start")
  15. xs_transaction_start.argtypes = [ struct_xs_handle ]
  16. xs_transaction_start.restype = xs_transaction_t
  17. xs_transaction_end = xenstore.__getattr__("xs_transaction_end")
  18. xs_transaction_end.argtypes = [ struct_xs_handle, xs_transaction_t, c_bool ]
  19. xs_transaction_end.restype = c_bool
  20. path = "memory/target"
  21. length = c_uint()
  22. ret = 0
  23. transaction = 0
  24. xsh = None
  25. xst = 0
  26. if transaction:
  27. xsh = xs_domain_open()
  28. xst = xs_transaction_start(xsh)
  29. val = xs_read(xsh, xst, path, byref(length))
  30. if val == None:
  31. ret = 1
  32. if transaction:
  33. xs_transaction_end(xsh, xth, ret)
  34.