+ v_all = match.group(0)
+ v_maj = int(match.group(1))
+ v_min = int(match.group(2))
+ if match.group(4):
+ v_rev = int(match.group(4))
+ else:
+ v_rev = 0
+ return (v_all, v_maj, v_min, v_rev)
+
+ @classmethod
+ def _GetKVMOutput(cls, kvm_path, option):
+ """Return the output of a kvm invocation
+
+ @type kvm_path: string
+ @param kvm_path: path to the kvm executable
+ @type option: a key of _KVMOPTS_CMDS
+ @param option: kvm option to fetch the output from
+ @return: output a supported kvm invocation
+ @raise errors.HypervisorError: when the KVM help output cannot be retrieved
+
+ """
+ assert option in cls._KVMOPTS_CMDS, "Invalid output option"
+
+ optlist, can_fail = cls._KVMOPTS_CMDS[option]
+
+ result = utils.RunCmd([kvm_path] + optlist)
+ if result.failed and not can_fail:
+ raise errors.HypervisorError("Unable to get KVM %s output" %
+ " ".join(cls._KVMOPTS_CMDS[option]))
+ return result.output
+
+ @classmethod
+ def _GetKVMVersion(cls, kvm_path):
+ """Return the installed KVM version.
+
+ @return: (version, v_maj, v_min, v_rev)
+ @raise errors.HypervisorError: when the KVM version cannot be retrieved
+
+ """
+ return cls._ParseKVMVersion(cls._GetKVMOutput(kvm_path, cls._KVMOPT_HELP))
+
+ @classmethod
+ def _GetDefaultMachineVersion(cls, kvm_path):
+ """Return the default hardware revision (e.g. pc-1.1)
+
+ """
+ output = cls._GetKVMOutput(kvm_path, cls._KVMOPT_MLIST)
+ match = cls._DEFAULT_MACHINE_VERSION_RE.search(output)
+ if match:
+ return match.group(1)
+ else:
+ return "pc"