mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Allow usage of public/private networks as management networks
This requires that the qemu_use_agent is enabled and at least one network is defined in the Vagrantfile that is either private or public. The restriction that qemu_use_agent need be enabled may be removed subsequently for networks using a static IP address. That should be considered a subsequent problem. Fixes: #1204 Fixes: #1124 Fixes: #1057
This commit is contained in:
committed by
Darragh Bailey
parent
5daecc6ee3
commit
9c18a32952
@@ -22,30 +22,29 @@ module VagrantPlugins
|
||||
# Initialize metrics if they haven't been
|
||||
env[:metrics] ||= {}
|
||||
|
||||
# Get domain object
|
||||
domain = env[:machine].provider.driver.get_domain(env[:machine])
|
||||
driver = env[:machine].provider.driver
|
||||
domain = driver.get_domain(env[:machine])
|
||||
|
||||
if domain.nil?
|
||||
raise Errors::NoDomainError,
|
||||
error_message: "Domain #{env[:machine].id} not found"
|
||||
end
|
||||
|
||||
# Wait for domain to obtain an ip address. Ip address is searched
|
||||
# from arp table, either locally or remotely via ssh, if Libvirt
|
||||
# connection was done via ssh.
|
||||
env[:ip_address] = nil
|
||||
@logger.debug("Searching for IP for MAC address: #{domain.mac}")
|
||||
env[:ui].info(I18n.t('vagrant_libvirt.waiting_for_ip'))
|
||||
|
||||
# Wait for domain to obtain an ip address. Ip address is searched
|
||||
# from dhcp leases table via libvirt, or via qemu agent if enabled.
|
||||
env[:metrics]['instance_ip_time'] = Util::Timer.time do
|
||||
retryable(on: Fog::Errors::TimeoutError, tries: 300) do
|
||||
# just return if interrupted and let the warden call recover
|
||||
return if env[:interrupted]
|
||||
|
||||
# Wait for domain to obtain an ip address
|
||||
env[:ip_address] = env[:machine].provider.driver.get_domain_ipaddress(env[:machine], domain)
|
||||
env[:ip_address] = driver.get_domain_ipaddress(env[:machine], domain)
|
||||
end
|
||||
end
|
||||
|
||||
@logger.info("Got IP address #{env[:ip_address]}")
|
||||
@logger.info("Time for getting IP: #{env[:metrics]['instance_ip_time']}")
|
||||
|
||||
|
||||
@@ -92,8 +92,14 @@ module VagrantPlugins
|
||||
management_network_options[:slot] = management_network_pci_slot
|
||||
end
|
||||
|
||||
if (env[:machine].config.vm.box &&
|
||||
!env[:machine].provider_config.mgmt_attach)
|
||||
# if there is a box and management network is disabled
|
||||
# need qemu agent enabled and at least one network that can be accessed
|
||||
if (
|
||||
env[:machine].config.vm.box &&
|
||||
!env[:machine].provider_config.mgmt_attach &&
|
||||
!env[:machine].provider_config.qemu_use_agent &&
|
||||
!env[:machine].config.vm.networks.any? { |type, _| ["private_network", "public_network"].include?(type.to_s) }
|
||||
)
|
||||
raise Errors::ManagementNetworkRequired
|
||||
end
|
||||
|
||||
|
||||
2
tests/qemu_agent/Vagrantfile
vendored
2
tests/qemu_agent/Vagrantfile
vendored
@@ -6,7 +6,9 @@
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "generic/debian10"
|
||||
config.vm.synced_folder ".", "/vagrant", disabled: true
|
||||
config.vm.network "private_network", type: "dhcp"
|
||||
config.vm.provider :libvirt do |libvirt|
|
||||
libvirt.qemu_use_agent = true
|
||||
libvirt.mgmt_attach = false
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user