analyze-migration.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. #!/usr/bin/env python3
  2. #
  3. # Migration Stream Analyzer
  4. #
  5. # Copyright (c) 2015 Alexander Graf <agraf@suse.de>
  6. #
  7. # This library is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Lesser General Public
  9. # License as published by the Free Software Foundation; either
  10. # version 2.1 of the License, or (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with this library; if not, see <http://www.gnu.org/licenses/>.
  19. import json
  20. import os
  21. import argparse
  22. import collections
  23. import struct
  24. import sys
  25. def mkdir_p(path):
  26. try:
  27. os.makedirs(path)
  28. except OSError:
  29. pass
  30. class MigrationFile(object):
  31. def __init__(self, filename):
  32. self.filename = filename
  33. self.file = open(self.filename, "rb")
  34. def read64(self):
  35. return int.from_bytes(self.file.read(8), byteorder='big', signed=False)
  36. def read32(self):
  37. return int.from_bytes(self.file.read(4), byteorder='big', signed=False)
  38. def read16(self):
  39. return int.from_bytes(self.file.read(2), byteorder='big', signed=False)
  40. def read8(self):
  41. return int.from_bytes(self.file.read(1), byteorder='big', signed=True)
  42. def readstr(self, len = None):
  43. return self.readvar(len).decode('utf-8')
  44. def readvar(self, size = None):
  45. if size is None:
  46. size = self.read8()
  47. if size == 0:
  48. return ""
  49. value = self.file.read(size)
  50. if len(value) != size:
  51. raise Exception("Unexpected end of %s at 0x%x" % (self.filename, self.file.tell()))
  52. return value
  53. def tell(self):
  54. return self.file.tell()
  55. # The VMSD description is at the end of the file, after EOF. Look for
  56. # the last NULL byte, then for the beginning brace of JSON.
  57. def read_migration_debug_json(self):
  58. QEMU_VM_VMDESCRIPTION = 0x06
  59. # Remember the offset in the file when we started
  60. entrypos = self.file.tell()
  61. # Read the last 10MB
  62. self.file.seek(0, os.SEEK_END)
  63. endpos = self.file.tell()
  64. self.file.seek(max(-endpos, -10 * 1024 * 1024), os.SEEK_END)
  65. datapos = self.file.tell()
  66. data = self.file.read()
  67. # The full file read closed the file as well, reopen it
  68. self.file = open(self.filename, "rb")
  69. # Find the last NULL byte, then the first brace after that. This should
  70. # be the beginning of our JSON data.
  71. nulpos = data.rfind(b'\0')
  72. jsonpos = data.find(b'{', nulpos)
  73. # Check backwards from there and see whether we guessed right
  74. self.file.seek(datapos + jsonpos - 5, 0)
  75. if self.read8() != QEMU_VM_VMDESCRIPTION:
  76. raise Exception("No Debug Migration device found")
  77. jsonlen = self.read32()
  78. # Seek back to where we were at the beginning
  79. self.file.seek(entrypos, 0)
  80. # explicit decode() needed for Python 3.5 compatibility
  81. return data[jsonpos:jsonpos + jsonlen].decode("utf-8")
  82. def close(self):
  83. self.file.close()
  84. class RamSection(object):
  85. RAM_SAVE_FLAG_COMPRESS = 0x02
  86. RAM_SAVE_FLAG_MEM_SIZE = 0x04
  87. RAM_SAVE_FLAG_PAGE = 0x08
  88. RAM_SAVE_FLAG_EOS = 0x10
  89. RAM_SAVE_FLAG_CONTINUE = 0x20
  90. RAM_SAVE_FLAG_XBZRLE = 0x40
  91. RAM_SAVE_FLAG_HOOK = 0x80
  92. RAM_SAVE_FLAG_COMPRESS_PAGE = 0x100
  93. RAM_SAVE_FLAG_MULTIFD_FLUSH = 0x200
  94. def __init__(self, file, version_id, ramargs, section_key):
  95. if version_id != 4:
  96. raise Exception("Unknown RAM version %d" % version_id)
  97. self.file = file
  98. self.section_key = section_key
  99. self.TARGET_PAGE_SIZE = ramargs['page_size']
  100. self.dump_memory = ramargs['dump_memory']
  101. self.write_memory = ramargs['write_memory']
  102. self.ignore_shared = ramargs['ignore_shared']
  103. self.sizeinfo = collections.OrderedDict()
  104. self.data = collections.OrderedDict()
  105. self.data['section sizes'] = self.sizeinfo
  106. self.name = ''
  107. if self.write_memory:
  108. self.files = { }
  109. if self.dump_memory:
  110. self.memory = collections.OrderedDict()
  111. self.data['memory'] = self.memory
  112. def __repr__(self):
  113. return self.data.__repr__()
  114. def __str__(self):
  115. return self.data.__str__()
  116. def getDict(self):
  117. return self.data
  118. def read(self):
  119. # Read all RAM sections
  120. while True:
  121. addr = self.file.read64()
  122. flags = addr & (self.TARGET_PAGE_SIZE - 1)
  123. addr &= ~(self.TARGET_PAGE_SIZE - 1)
  124. if flags & self.RAM_SAVE_FLAG_MEM_SIZE:
  125. while True:
  126. namelen = self.file.read8()
  127. # We assume that no RAM chunk is big enough to ever
  128. # hit the first byte of the address, so when we see
  129. # a zero here we know it has to be an address, not the
  130. # length of the next block.
  131. if namelen == 0:
  132. self.file.file.seek(-1, 1)
  133. break
  134. self.name = self.file.readstr(len = namelen)
  135. len = self.file.read64()
  136. self.sizeinfo[self.name] = '0x%016x' % len
  137. if self.write_memory:
  138. print(self.name)
  139. mkdir_p('./' + os.path.dirname(self.name))
  140. f = open('./' + self.name, "wb")
  141. f.truncate(0)
  142. f.truncate(len)
  143. self.files[self.name] = f
  144. if self.ignore_shared:
  145. mr_addr = self.file.read64()
  146. flags &= ~self.RAM_SAVE_FLAG_MEM_SIZE
  147. if flags & self.RAM_SAVE_FLAG_COMPRESS:
  148. if flags & self.RAM_SAVE_FLAG_CONTINUE:
  149. flags &= ~self.RAM_SAVE_FLAG_CONTINUE
  150. else:
  151. self.name = self.file.readstr()
  152. fill_char = self.file.read8()
  153. # The page in question is filled with fill_char now
  154. if self.write_memory and fill_char != 0:
  155. self.files[self.name].seek(addr, os.SEEK_SET)
  156. self.files[self.name].write(chr(fill_char) * self.TARGET_PAGE_SIZE)
  157. if self.dump_memory:
  158. self.memory['%s (0x%016x)' % (self.name, addr)] = 'Filled with 0x%02x' % fill_char
  159. flags &= ~self.RAM_SAVE_FLAG_COMPRESS
  160. elif flags & self.RAM_SAVE_FLAG_PAGE:
  161. if flags & self.RAM_SAVE_FLAG_CONTINUE:
  162. flags &= ~self.RAM_SAVE_FLAG_CONTINUE
  163. else:
  164. self.name = self.file.readstr()
  165. if self.write_memory or self.dump_memory:
  166. data = self.file.readvar(size = self.TARGET_PAGE_SIZE)
  167. else: # Just skip RAM data
  168. self.file.file.seek(self.TARGET_PAGE_SIZE, 1)
  169. if self.write_memory:
  170. self.files[self.name].seek(addr, os.SEEK_SET)
  171. self.files[self.name].write(data)
  172. if self.dump_memory:
  173. hexdata = " ".join("{0:02x}".format(ord(c)) for c in data)
  174. self.memory['%s (0x%016x)' % (self.name, addr)] = hexdata
  175. flags &= ~self.RAM_SAVE_FLAG_PAGE
  176. elif flags & self.RAM_SAVE_FLAG_XBZRLE:
  177. raise Exception("XBZRLE RAM compression is not supported yet")
  178. elif flags & self.RAM_SAVE_FLAG_HOOK:
  179. raise Exception("RAM hooks don't make sense with files")
  180. if flags & self.RAM_SAVE_FLAG_MULTIFD_FLUSH:
  181. continue
  182. # End of RAM section
  183. if flags & self.RAM_SAVE_FLAG_EOS:
  184. break
  185. if flags != 0:
  186. raise Exception("Unknown RAM flags: %x" % flags)
  187. def __del__(self):
  188. if self.write_memory:
  189. for key in self.files:
  190. self.files[key].close()
  191. class HTABSection(object):
  192. HASH_PTE_SIZE_64 = 16
  193. def __init__(self, file, version_id, device, section_key):
  194. if version_id != 1:
  195. raise Exception("Unknown HTAB version %d" % version_id)
  196. self.file = file
  197. self.section_key = section_key
  198. def read(self):
  199. header = self.file.read32()
  200. if (header == -1):
  201. # "no HPT" encoding
  202. return
  203. if (header > 0):
  204. # First section, just the hash shift
  205. return
  206. # Read until end marker
  207. while True:
  208. index = self.file.read32()
  209. n_valid = self.file.read16()
  210. n_invalid = self.file.read16()
  211. if index == 0 and n_valid == 0 and n_invalid == 0:
  212. break
  213. self.file.readvar(n_valid * self.HASH_PTE_SIZE_64)
  214. def getDict(self):
  215. return ""
  216. class ConfigurationSection(object):
  217. def __init__(self, file, desc):
  218. self.file = file
  219. self.desc = desc
  220. self.caps = []
  221. def parse_capabilities(self, vmsd_caps):
  222. if not vmsd_caps:
  223. return
  224. ncaps = vmsd_caps.data['caps_count'].data
  225. self.caps = vmsd_caps.data['capabilities']
  226. if type(self.caps) != list:
  227. self.caps = [self.caps]
  228. if len(self.caps) != ncaps:
  229. raise Exception("Number of capabilities doesn't match "
  230. "caps_count field")
  231. def has_capability(self, cap):
  232. return any([str(c) == cap for c in self.caps])
  233. def read(self):
  234. if self.desc:
  235. version_id = self.desc['version']
  236. section = VMSDSection(self.file, version_id, self.desc,
  237. 'configuration')
  238. section.read()
  239. self.parse_capabilities(
  240. section.data.get("configuration/capabilities"))
  241. else:
  242. # backward compatibility for older streams that don't have
  243. # the configuration section in the json
  244. name_len = self.file.read32()
  245. name = self.file.readstr(len = name_len)
  246. class VMSDFieldGeneric(object):
  247. def __init__(self, desc, file):
  248. self.file = file
  249. self.desc = desc
  250. self.data = ""
  251. def __repr__(self):
  252. return str(self.__str__())
  253. def __str__(self):
  254. return " ".join("{0:02x}".format(c) for c in self.data)
  255. def getDict(self):
  256. return self.__str__()
  257. def read(self):
  258. size = int(self.desc['size'])
  259. self.data = self.file.readvar(size)
  260. return self.data
  261. class VMSDFieldCap(object):
  262. def __init__(self, desc, file):
  263. self.file = file
  264. self.desc = desc
  265. self.data = ""
  266. def __repr__(self):
  267. return self.data
  268. def __str__(self):
  269. return self.data
  270. def read(self):
  271. len = self.file.read8()
  272. self.data = self.file.readstr(len)
  273. class VMSDFieldInt(VMSDFieldGeneric):
  274. def __init__(self, desc, file):
  275. super(VMSDFieldInt, self).__init__(desc, file)
  276. self.size = int(desc['size'])
  277. self.format = '0x%%0%dx' % (self.size * 2)
  278. self.sdtype = '>i%d' % self.size
  279. self.udtype = '>u%d' % self.size
  280. def __repr__(self):
  281. if self.data < 0:
  282. return ('%s (%d)' % ((self.format % self.udata), self.data))
  283. else:
  284. return self.format % self.data
  285. def __str__(self):
  286. return self.__repr__()
  287. def getDict(self):
  288. return self.__str__()
  289. def read(self):
  290. super(VMSDFieldInt, self).read()
  291. self.sdata = int.from_bytes(self.data, byteorder='big', signed=True)
  292. self.udata = int.from_bytes(self.data, byteorder='big', signed=False)
  293. self.data = self.sdata
  294. return self.data
  295. class VMSDFieldUInt(VMSDFieldInt):
  296. def __init__(self, desc, file):
  297. super(VMSDFieldUInt, self).__init__(desc, file)
  298. def read(self):
  299. super(VMSDFieldUInt, self).read()
  300. self.data = self.udata
  301. return self.data
  302. class VMSDFieldIntLE(VMSDFieldInt):
  303. def __init__(self, desc, file):
  304. super(VMSDFieldIntLE, self).__init__(desc, file)
  305. self.dtype = '<i%d' % self.size
  306. class VMSDFieldBool(VMSDFieldGeneric):
  307. def __init__(self, desc, file):
  308. super(VMSDFieldBool, self).__init__(desc, file)
  309. def __repr__(self):
  310. return self.data.__repr__()
  311. def __str__(self):
  312. return self.data.__str__()
  313. def getDict(self):
  314. return self.data
  315. def read(self):
  316. super(VMSDFieldBool, self).read()
  317. if self.data[0] == 0:
  318. self.data = False
  319. else:
  320. self.data = True
  321. return self.data
  322. class VMSDFieldStruct(VMSDFieldGeneric):
  323. QEMU_VM_SUBSECTION = 0x05
  324. def __init__(self, desc, file):
  325. super(VMSDFieldStruct, self).__init__(desc, file)
  326. self.data = collections.OrderedDict()
  327. # When we see compressed array elements, unfold them here
  328. new_fields = []
  329. for field in self.desc['struct']['fields']:
  330. if not 'array_len' in field:
  331. new_fields.append(field)
  332. continue
  333. array_len = field.pop('array_len')
  334. field['index'] = 0
  335. new_fields.append(field)
  336. for i in range(1, array_len):
  337. c = field.copy()
  338. c['index'] = i
  339. new_fields.append(c)
  340. self.desc['struct']['fields'] = new_fields
  341. def __repr__(self):
  342. return self.data.__repr__()
  343. def __str__(self):
  344. return self.data.__str__()
  345. def read(self):
  346. for field in self.desc['struct']['fields']:
  347. try:
  348. reader = vmsd_field_readers[field['type']]
  349. except:
  350. reader = VMSDFieldGeneric
  351. field['data'] = reader(field, self.file)
  352. field['data'].read()
  353. if 'index' in field:
  354. if field['name'] not in self.data:
  355. self.data[field['name']] = []
  356. a = self.data[field['name']]
  357. if len(a) != int(field['index']):
  358. raise Exception("internal index of data field unmatched (%d/%d)" % (len(a), int(field['index'])))
  359. a.append(field['data'])
  360. else:
  361. self.data[field['name']] = field['data']
  362. if 'subsections' in self.desc['struct']:
  363. for subsection in self.desc['struct']['subsections']:
  364. if self.file.read8() != self.QEMU_VM_SUBSECTION:
  365. raise Exception("Subsection %s not found at offset %x" % ( subsection['vmsd_name'], self.file.tell()))
  366. name = self.file.readstr()
  367. version_id = self.file.read32()
  368. self.data[name] = VMSDSection(self.file, version_id, subsection, (name, 0))
  369. self.data[name].read()
  370. def getDictItem(self, value):
  371. # Strings would fall into the array category, treat
  372. # them specially
  373. if value.__class__ is ''.__class__:
  374. return value
  375. try:
  376. return self.getDictOrderedDict(value)
  377. except:
  378. try:
  379. return self.getDictArray(value)
  380. except:
  381. try:
  382. return value.getDict()
  383. except:
  384. return value
  385. def getDictArray(self, array):
  386. r = []
  387. for value in array:
  388. r.append(self.getDictItem(value))
  389. return r
  390. def getDictOrderedDict(self, dict):
  391. r = collections.OrderedDict()
  392. for (key, value) in dict.items():
  393. r[key] = self.getDictItem(value)
  394. return r
  395. def getDict(self):
  396. return self.getDictOrderedDict(self.data)
  397. vmsd_field_readers = {
  398. "bool" : VMSDFieldBool,
  399. "int8" : VMSDFieldInt,
  400. "int16" : VMSDFieldInt,
  401. "int32" : VMSDFieldInt,
  402. "int32 equal" : VMSDFieldInt,
  403. "int32 le" : VMSDFieldIntLE,
  404. "int64" : VMSDFieldInt,
  405. "uint8" : VMSDFieldUInt,
  406. "uint16" : VMSDFieldUInt,
  407. "uint32" : VMSDFieldUInt,
  408. "uint32 equal" : VMSDFieldUInt,
  409. "uint64" : VMSDFieldUInt,
  410. "int64 equal" : VMSDFieldInt,
  411. "uint8 equal" : VMSDFieldInt,
  412. "uint16 equal" : VMSDFieldInt,
  413. "float64" : VMSDFieldGeneric,
  414. "timer" : VMSDFieldGeneric,
  415. "buffer" : VMSDFieldGeneric,
  416. "unused_buffer" : VMSDFieldGeneric,
  417. "bitmap" : VMSDFieldGeneric,
  418. "struct" : VMSDFieldStruct,
  419. "capability": VMSDFieldCap,
  420. "unknown" : VMSDFieldGeneric,
  421. }
  422. class VMSDSection(VMSDFieldStruct):
  423. def __init__(self, file, version_id, device, section_key):
  424. self.file = file
  425. self.data = ""
  426. self.vmsd_name = ""
  427. self.section_key = section_key
  428. desc = device
  429. if 'vmsd_name' in device:
  430. self.vmsd_name = device['vmsd_name']
  431. # A section really is nothing but a FieldStruct :)
  432. super(VMSDSection, self).__init__({ 'struct' : desc }, file)
  433. ###############################################################################
  434. class MigrationDump(object):
  435. QEMU_VM_FILE_MAGIC = 0x5145564d
  436. QEMU_VM_FILE_VERSION = 0x00000003
  437. QEMU_VM_EOF = 0x00
  438. QEMU_VM_SECTION_START = 0x01
  439. QEMU_VM_SECTION_PART = 0x02
  440. QEMU_VM_SECTION_END = 0x03
  441. QEMU_VM_SECTION_FULL = 0x04
  442. QEMU_VM_SUBSECTION = 0x05
  443. QEMU_VM_VMDESCRIPTION = 0x06
  444. QEMU_VM_CONFIGURATION = 0x07
  445. QEMU_VM_SECTION_FOOTER= 0x7e
  446. def __init__(self, filename):
  447. self.section_classes = { ( 'ram', 0 ) : [ RamSection, None ],
  448. ( 'spapr/htab', 0) : ( HTABSection, None ) }
  449. self.filename = filename
  450. self.vmsd_desc = None
  451. def read(self, desc_only = False, dump_memory = False, write_memory = False):
  452. # Read in the whole file
  453. file = MigrationFile(self.filename)
  454. # File magic
  455. data = file.read32()
  456. if data != self.QEMU_VM_FILE_MAGIC:
  457. raise Exception("Invalid file magic %x" % data)
  458. # Version (has to be v3)
  459. data = file.read32()
  460. if data != self.QEMU_VM_FILE_VERSION:
  461. raise Exception("Invalid version number %d" % data)
  462. self.load_vmsd_json(file)
  463. # Read sections
  464. self.sections = collections.OrderedDict()
  465. if desc_only:
  466. return
  467. ramargs = {}
  468. ramargs['page_size'] = self.vmsd_desc['page_size']
  469. ramargs['dump_memory'] = dump_memory
  470. ramargs['write_memory'] = write_memory
  471. ramargs['ignore_shared'] = False
  472. self.section_classes[('ram',0)][1] = ramargs
  473. while True:
  474. section_type = file.read8()
  475. if section_type == self.QEMU_VM_EOF:
  476. break
  477. elif section_type == self.QEMU_VM_CONFIGURATION:
  478. config_desc = self.vmsd_desc.get('configuration')
  479. section = ConfigurationSection(file, config_desc)
  480. section.read()
  481. ramargs['ignore_shared'] = section.has_capability('x-ignore-shared')
  482. elif section_type == self.QEMU_VM_SECTION_START or section_type == self.QEMU_VM_SECTION_FULL:
  483. section_id = file.read32()
  484. name = file.readstr()
  485. instance_id = file.read32()
  486. version_id = file.read32()
  487. section_key = (name, instance_id)
  488. classdesc = self.section_classes[section_key]
  489. section = classdesc[0](file, version_id, classdesc[1], section_key)
  490. self.sections[section_id] = section
  491. section.read()
  492. elif section_type == self.QEMU_VM_SECTION_PART or section_type == self.QEMU_VM_SECTION_END:
  493. section_id = file.read32()
  494. self.sections[section_id].read()
  495. elif section_type == self.QEMU_VM_SECTION_FOOTER:
  496. read_section_id = file.read32()
  497. if read_section_id != section_id:
  498. raise Exception("Mismatched section footer: %x vs %x" % (read_section_id, section_id))
  499. else:
  500. raise Exception("Unknown section type: %d" % section_type)
  501. file.close()
  502. def load_vmsd_json(self, file):
  503. vmsd_json = file.read_migration_debug_json()
  504. self.vmsd_desc = json.loads(vmsd_json, object_pairs_hook=collections.OrderedDict)
  505. for device in self.vmsd_desc['devices']:
  506. key = (device['name'], device['instance_id'])
  507. value = ( VMSDSection, device )
  508. self.section_classes[key] = value
  509. def getDict(self):
  510. r = collections.OrderedDict()
  511. for (key, value) in self.sections.items():
  512. key = "%s (%d)" % ( value.section_key[0], key )
  513. r[key] = value.getDict()
  514. return r
  515. ###############################################################################
  516. class JSONEncoder(json.JSONEncoder):
  517. def default(self, o):
  518. if isinstance(o, VMSDFieldGeneric):
  519. return str(o)
  520. return json.JSONEncoder.default(self, o)
  521. parser = argparse.ArgumentParser()
  522. parser.add_argument("-f", "--file", help='migration dump to read from', required=True)
  523. parser.add_argument("-m", "--memory", help='dump RAM contents as well', action='store_true')
  524. parser.add_argument("-d", "--dump", help='what to dump ("state" or "desc")', default='state')
  525. parser.add_argument("-x", "--extract", help='extract contents into individual files', action='store_true')
  526. args = parser.parse_args()
  527. jsonenc = JSONEncoder(indent=4, separators=(',', ': '))
  528. if args.extract:
  529. dump = MigrationDump(args.file)
  530. dump.read(desc_only = True)
  531. print("desc.json")
  532. f = open("desc.json", "w")
  533. f.truncate()
  534. f.write(jsonenc.encode(dump.vmsd_desc))
  535. f.close()
  536. dump.read(write_memory = True)
  537. dict = dump.getDict()
  538. print("state.json")
  539. f = open("state.json", "w")
  540. f.truncate()
  541. f.write(jsonenc.encode(dict))
  542. f.close()
  543. elif args.dump == "state":
  544. dump = MigrationDump(args.file)
  545. dump.read(dump_memory = args.memory)
  546. dict = dump.getDict()
  547. print(jsonenc.encode(dict))
  548. elif args.dump == "desc":
  549. dump = MigrationDump(args.file)
  550. dump.read(desc_only = True)
  551. print(jsonenc.encode(dump.vmsd_desc))
  552. else:
  553. raise Exception("Please specify either -x, -d state or -d desc")