def cmd_add_header_ext(fd, magic, data): try: magic = int(magic, 0) except ValueError: print("'%s' is not a valid magic number" % magic) sys.exit(1) h = QcowHeader(fd) h.extensions.append(QcowHeaderExtension.create(magic, data.encode('ascii'))) h.update(fd)
def cmd_set_header(fd, name, value): try: value = int(value, 0) except ValueError: print("'%s' is not a valid number" % value) sys.exit(1) fields = (field[2] for field in QcowHeader.fields) if name not in fields: print("'%s' is not a known header field" % name) sys.exit(1) h = QcowHeader(fd) h.__dict__[name] = value h.update(fd)
def cmd_del_header_ext(fd, magic): try: magic = int(magic, 0) except ValueError: print("'%s' is not a valid magic number" % magic) sys.exit(1) h = QcowHeader(fd) found = False for ex in h.extensions: if ex.magic == magic: found = True h.extensions.remove(ex) if not found: print("No such header extension") return h.update(fd)
def cmd_set_feature_bit(fd, group, bit): try: bit = int(bit, 0) if bit < 0 or bit >= 64: raise ValueError except ValueError: print("'%s' is not a valid bit number in range [0, 64)" % bit) sys.exit(1) h = QcowHeader(fd) if group == 'incompatible': h.incompatible_features |= 1 << bit elif group == 'compatible': h.compatible_features |= 1 << bit elif group == 'autoclear': h.autoclear_features |= 1 << bit else: print("'%s' is not a valid group, try " "'incompatible', 'compatible', or 'autoclear'" % group) sys.exit(1) h.update(fd)
def cmd_dump_header_exts(fd): h = QcowHeader(fd) h.dump_extensions(is_json)
def cmd_dump_header(fd): h = QcowHeader(fd) h.dump(is_json) print() h.dump_extensions(is_json)