Sha256: 436caee17ffad91877565ac5855fdd97403791ad695d769d6fe2103b88d2cea0

Contents?: true

Size: 1.06 KB

Versions: 17

Compression:

Stored size: 1.06 KB

Contents

require 'log4r'

module VagrantPlugins
  module ProviderLibvirt
    module Action
      class ReadMacAddresses
        def initialize(app, _env)
          @app    = app
          @logger = Log4r::Logger.new('vagrant_libvirt::action::read_mac_addresses')
        end

        def call(env)
          env[:machine_mac_addresses] = read_mac_addresses(env[:machine].provider.driver.connection, env[:machine])
        end

        def read_mac_addresses(libvirt, machine)
          return nil if machine.id.nil?

          domain = libvirt.client.lookup_domain_by_uuid(machine.id)

          if domain.nil?
            @logger.info('Machine could not be found, assuming it got destroyed')
            machine.id = nil
            return nil
          end

          xml = Nokogiri::XML(domain.xml_desc)
          mac = xml.xpath('/domain/devices/interface/mac/@address')

          return {} if mac.empty?

          Hash[mac.each_with_index.map do |x, i|
            @logger.debug("interface[#{i}] = #{x.value}")
            [i, x.value]
          end]
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
vagrant-libvirt-0.5.3 lib/vagrant-libvirt/action/read_mac_addresses.rb
vagrant-libvirt-0.5.2 lib/vagrant-libvirt/action/read_mac_addresses.rb
vagrant-libvirt-0.5.1 lib/vagrant-libvirt/action/read_mac_addresses.rb
vagrant-libvirt-0.5.0 lib/vagrant-libvirt/action/read_mac_addresses.rb
vagrant-libvirt-0.4.1 lib/vagrant-libvirt/action/read_mac_addresses.rb
vagrant-libvirt-0.4.0 lib/vagrant-libvirt/action/read_mac_addresses.rb
vagrant-libvirt-0.3.0 lib/vagrant-libvirt/action/read_mac_addresses.rb
vagrant-libvirt-0.2.1 lib/vagrant-libvirt/action/read_mac_addresses.rb
vagrant-libvirt-0.1.2 lib/vagrant-libvirt/action/read_mac_addresses.rb
vagrant-libvirt-0.1.0 lib/vagrant-libvirt/action/read_mac_addresses.rb
vagrant-libvirt-0.0.45 lib/vagrant-libvirt/action/read_mac_addresses.rb
vagrant-libvirt-0.0.43 lib/vagrant-libvirt/action/read_mac_addresses.rb
vagrant-libvirt-0.0.42 lib/vagrant-libvirt/action/read_mac_addresses.rb
vagrant-libvirt-0.0.40 lib/vagrant-libvirt/action/read_mac_addresses.rb
vagrant-libvirt-0.0.39 lib/vagrant-libvirt/action/read_mac_addresses.rb
vagrant-libvirt-0.0.38 lib/vagrant-libvirt/action/read_mac_addresses.rb
vagrant-libvirt-0.0.37 lib/vagrant-libvirt/action/read_mac_addresses.rb