mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
implemented nic_mac_addresses capability
This commit is contained in:
parent
5b1f8a85a6
commit
c4c8c8afc7
@ -286,6 +286,14 @@ module VagrantPlugins
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.action_read_mac_addresses
|
||||||
|
Vagrant::Action::Builder.new.tap do |b|
|
||||||
|
b.use ConfigValidate
|
||||||
|
b.use ConnectLibvirt
|
||||||
|
b.use ReadMacAddresses
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# This is the action that will run a single SSH command.
|
# This is the action that will run a single SSH command.
|
||||||
def self.action_ssh_run
|
def self.action_ssh_run
|
||||||
Vagrant::Action::Builder.new.tap do |b|
|
Vagrant::Action::Builder.new.tap do |b|
|
||||||
@ -336,6 +344,7 @@ module VagrantPlugins
|
|||||||
autoload :PruneNFSExports, action_root.join('prune_nfs_exports')
|
autoload :PruneNFSExports, action_root.join('prune_nfs_exports')
|
||||||
|
|
||||||
autoload :ReadSSHInfo, action_root.join('read_ssh_info')
|
autoload :ReadSSHInfo, action_root.join('read_ssh_info')
|
||||||
|
autoload :ReadMacAddresses, action_root.join('read_mac_addresses')
|
||||||
autoload :ReadState, action_root.join('read_state')
|
autoload :ReadState, action_root.join('read_state')
|
||||||
autoload :ResumeDomain, action_root.join('resume_domain')
|
autoload :ResumeDomain, action_root.join('resume_domain')
|
||||||
autoload :SetNameOfDomain, action_root.join('set_name_of_domain')
|
autoload :SetNameOfDomain, action_root.join('set_name_of_domain')
|
||||||
|
42
lib/vagrant-libvirt/action/read_mac_addresses.rb
Normal file
42
lib/vagrant-libvirt/action/read_mac_addresses.rb
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
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[:libvirt_compute], 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")
|
||||||
|
|
||||||
|
if mac.length == 0
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
|
Hash[mac.each_with_index.map do |x,i|
|
||||||
|
@logger.debug("interface[#{i}] = #{x.value}")
|
||||||
|
[i,x.value]
|
||||||
|
end]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
11
lib/vagrant-libvirt/cap/nic_mac_addresses.rb
Normal file
11
lib/vagrant-libvirt/cap/nic_mac_addresses.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
module VagrantPlugins
|
||||||
|
module ProviderLibvirt
|
||||||
|
module Cap
|
||||||
|
class NicMacAddresses
|
||||||
|
def self.nic_mac_addresses(machine)
|
||||||
|
machine.provider.mac_addresses
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -37,6 +37,11 @@ module VagrantPlugins
|
|||||||
Cap::MountP9
|
Cap::MountP9
|
||||||
end
|
end
|
||||||
|
|
||||||
|
provider_capability(:libvirt, :nic_mac_addresses) do
|
||||||
|
require_relative "cap/nic_mac_addresses"
|
||||||
|
Cap::NicMacAddresses
|
||||||
|
end
|
||||||
|
|
||||||
# lower priority than nfs or rsync
|
# lower priority than nfs or rsync
|
||||||
# https://github.com/pradels/vagrant-libvirt/pull/170
|
# https://github.com/pradels/vagrant-libvirt/pull/170
|
||||||
synced_folder("9p", 4) do
|
synced_folder("9p", 4) do
|
||||||
|
@ -49,6 +49,18 @@ module VagrantPlugins
|
|||||||
env[:machine_ssh_info]
|
env[:machine_ssh_info]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mac_addresses
|
||||||
|
# Run a custom action called "read_mac_addresses" which will return
|
||||||
|
# a list of mac addresses used by the machine. The returned data will
|
||||||
|
# be in the following format:
|
||||||
|
#
|
||||||
|
# {
|
||||||
|
# <ADAPTER_ID>: <MAC>
|
||||||
|
# }
|
||||||
|
env = @machine.action('read_mac_addresses')
|
||||||
|
env[:machine_mac_addresses]
|
||||||
|
end
|
||||||
|
|
||||||
# This should return the state of the machine within this provider.
|
# This should return the state of the machine within this provider.
|
||||||
# The state must be an instance of {MachineState}.
|
# The state must be an instance of {MachineState}.
|
||||||
def state
|
def state
|
||||||
|
Loading…
Reference in New Issue
Block a user