<commit_before>require 'libvirt'
require 'log4r'

module VagrantPlugins
  module ProviderKvm
    module Driver
      class Driver
        # This is raised if the VM is not found when initializing
        # a driver with a UUID.
        class VMNotFound < StandardError; end

        include Util
        include Errors

        # enum for states return by libvirt
        VM_STATE = [
          :no_state,
          :running,
          :blocked,
          :paused,
          :shutdown,
          :shutoff,
          :crashed]

        # The Name of the virtual machine we represent
        attr_reader :name

        # The UUID of the virtual machine we represent
        attr_reader :uuid

        # The QEMU version
        # XXX sufficient or have to check kvm and libvirt versions?
        attr_reader :version

        def initialize(uuid=nil)
          @logger = Log4r::Logger.new("vagrant::provider::kvm::driver")
          @uuid = uuid
          # This should be configurable
          @pool_name = "vagrant"
          @network_name = "vagrant"

          @logger.info("Check KVM kernel modules")
          kvm = false
          File.readlines("/proc/modules").each do |line|
            if line =~ /kvm_intel|kvm_amd/
              kvm = true
              break
            end
          end
          if !kvm then
            File.readlines("/proc/cpuinfo").each do |line|
              if line =~ /vmx/
                system("sudo /sbin/modprobe kvm-intel")
                kvm = true
                break
              elsif line =~ /svm/
                system("sudo /sbin/modprobe kvm-amd")
                kvm = true
                break
              end
            end
          end

          # Open a connection to the qemu driver
          begin
            @conn = Libvirt::open('qemu:///system')
          rescue Libvirt::Error => e
            if e.libvirt_code == 5
              # can't connect to hypervisor
              raise Vagrant::Errors::KvmNoConnection
            else
              raise e
            end
          end

          @version = read_version
          if @version < "1.2.0"
            raise Errors::KvmInvalidVersion,
              :actual => @version, :required => ">= 1.2.0"
          end

          # Get storage pool if it exists<commit_msg>update module check logic<commit_after>require 'libvirt'
require 'log4r'

module VagrantPlugins
  module ProviderKvm
    module Driver
      class Driver
        # This is raised if the VM is not found when initializing
        # a driver with a UUID.
        class VMNotFound < StandardError; end

        include Util
        include Errors

        # enum for states return by libvirt
        VM_STATE = [
          :no_state,
          :running,
          :blocked,
          :paused,
          :shutdown,
          :shutoff,
          :crashed]

        # The Name of the virtual machine we represent
        attr_reader :name

        # The UUID of the virtual machine we represent
        attr_reader :uuid

        # The QEMU version
        # XXX sufficient or have to check kvm and libvirt versions?
        attr_reader :version

        def initialize(uuid=nil)
          @logger = Log4r::Logger.new("vagrant::provider::kvm::driver")
          @uuid = uuid
          # This should be configurable
          @pool_name = "vagrant"
          @network_name = "vagrant"

          @logger.info("Check KVM kernel modules")
          unless File.readlines('/proc/modules').any? { |line| line =~ /kvm_(intel|amd)/ }
            case File.read('/proc/cpuinfo')
              when /vmx/
                system("sudo /sbin/modprobe kvm-intel")
              when /svm/
                system("sudo /sbin/modprobe kvm-amd")
              else
                # looks like virtualization is not supported
                raise Errors::VagrantKVMError, "KVM is unavailable"
              end
            end
          end

          # Open a connection to the qemu driver
          begin
            @conn = Libvirt::open('qemu:///system')
          rescue Libvirt::Error => e
            if e.libvirt_code == 5
              # can't connect to hypervisor
              raise Vagrant::Errors::KvmNoConnection
            else
              raise e
            end
          end

          @version = read_version
          if @version < "1.2.0"
            raise Errors::KvmInvalidVersion,
              :actual => @version, :required => ">= 1.2.0"
          end

          # Get storage pool if it exists
{'fraction_non_alphanumeric': 0.07794803464357095, 'fraction_numerical': 0.003997335109926716, 'mean_word_length': 1.421505376344086, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5809539', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1186, 'n_words': 370}