[DRE-commits] [vagrant-libvirt] 154/163: implemented nic_mac_addresses capability
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Apr 24 13:57:18 UTC 2016
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to annotated tag 0.0.26
in repository vagrant-libvirt.
commit c4c8c8afc77d9005cdbd5fb6f84323c23096a8e0
Author: James Johnson <james.johnson at accuvant.com>
Date: Mon Apr 13 04:13:12 2015 -0500
implemented nic_mac_addresses capability
---
lib/vagrant-libvirt/action.rb | 9 +++++
lib/vagrant-libvirt/action/read_mac_addresses.rb | 42 ++++++++++++++++++++++++
lib/vagrant-libvirt/cap/nic_mac_addresses.rb | 11 +++++++
lib/vagrant-libvirt/plugin.rb | 5 +++
lib/vagrant-libvirt/provider.rb | 12 +++++++
5 files changed, 79 insertions(+)
diff --git a/lib/vagrant-libvirt/action.rb b/lib/vagrant-libvirt/action.rb
index e969498..98479a7 100644
--- a/lib/vagrant-libvirt/action.rb
+++ b/lib/vagrant-libvirt/action.rb
@@ -286,6 +286,14 @@ module VagrantPlugins
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.
def self.action_ssh_run
Vagrant::Action::Builder.new.tap do |b|
@@ -336,6 +344,7 @@ module VagrantPlugins
autoload :PruneNFSExports, action_root.join('prune_nfs_exports')
autoload :ReadSSHInfo, action_root.join('read_ssh_info')
+ autoload :ReadMacAddresses, action_root.join('read_mac_addresses')
autoload :ReadState, action_root.join('read_state')
autoload :ResumeDomain, action_root.join('resume_domain')
autoload :SetNameOfDomain, action_root.join('set_name_of_domain')
diff --git a/lib/vagrant-libvirt/action/read_mac_addresses.rb b/lib/vagrant-libvirt/action/read_mac_addresses.rb
new file mode 100644
index 0000000..42db4c0
--- /dev/null
+++ b/lib/vagrant-libvirt/action/read_mac_addresses.rb
@@ -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
diff --git a/lib/vagrant-libvirt/cap/nic_mac_addresses.rb b/lib/vagrant-libvirt/cap/nic_mac_addresses.rb
new file mode 100644
index 0000000..1f083cd
--- /dev/null
+++ b/lib/vagrant-libvirt/cap/nic_mac_addresses.rb
@@ -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
diff --git a/lib/vagrant-libvirt/plugin.rb b/lib/vagrant-libvirt/plugin.rb
index f125e30..080feb0 100644
--- a/lib/vagrant-libvirt/plugin.rb
+++ b/lib/vagrant-libvirt/plugin.rb
@@ -37,6 +37,11 @@ module VagrantPlugins
Cap::MountP9
end
+ provider_capability(:libvirt, :nic_mac_addresses) do
+ require_relative "cap/nic_mac_addresses"
+ Cap::NicMacAddresses
+ end
+
# lower priority than nfs or rsync
# https://github.com/pradels/vagrant-libvirt/pull/170
synced_folder("9p", 4) do
diff --git a/lib/vagrant-libvirt/provider.rb b/lib/vagrant-libvirt/provider.rb
index dc78434..bd98dc2 100644
--- a/lib/vagrant-libvirt/provider.rb
+++ b/lib/vagrant-libvirt/provider.rb
@@ -49,6 +49,18 @@ module VagrantPlugins
env[:machine_ssh_info]
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.
# The state must be an instance of {MachineState}.
def state
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/vagrant-libvirt.git
More information about the Pkg-ruby-extras-commits
mailing list