mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
refactor set_domain_name to avoid duplicate names when running multiple guests.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
require 'securerandom'
|
||||
module VagrantPlugins
|
||||
module ProviderLibvirt
|
||||
module Action
|
||||
@@ -10,16 +11,7 @@ module VagrantPlugins
|
||||
end
|
||||
|
||||
def call(env)
|
||||
require 'securerandom'
|
||||
config = env[:machine].provider_config
|
||||
if config.default_prefix.nil?
|
||||
env[:domain_name] = env[:root_path].basename.to_s.dup
|
||||
else
|
||||
env[:domain_name] = config.default_prefix.to_s
|
||||
end
|
||||
env[:domain_name].gsub!(/[^-a-z0-9_]/i, '')
|
||||
env[:domain_name] << '_'
|
||||
env[:domain_name] << env[:machine].name.to_s
|
||||
env[:domain_name] = build_domain_name(env)
|
||||
|
||||
begin
|
||||
@logger.info("Looking for domain #{env[:domain_name]} through list #{env[:libvirt_compute].servers.all}")
|
||||
@@ -34,13 +26,32 @@ module VagrantPlugins
|
||||
|
||||
@logger.info("Looking for domain #{env[:domain_name]}")
|
||||
|
||||
if domain != nil
|
||||
unless domain.nil?
|
||||
raise ProviderLibvirt::Errors::DomainNameExists,
|
||||
:domain_name => env[:domain_name]
|
||||
end
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
|
||||
# build domain name
|
||||
# avoids `domain about to create is already taken`
|
||||
# @example
|
||||
# development-centos-6-chef-11_1404488971_3b7a569e2fd7c554b852
|
||||
# @return [String] libvirt domain name
|
||||
def build_domain_name(env)
|
||||
postfix = "#{Time.now.utc.to_i}_#{SecureRandom.hex(10)}"
|
||||
config = env[:machine].provider_config
|
||||
domain_name =
|
||||
if config.default_prefix.nil?
|
||||
env[:root_path].basename.to_s.dup
|
||||
else
|
||||
config.default_prefix.to_s
|
||||
end
|
||||
domain_name.gsub!(/[^-a-z0-9_]/i, '')
|
||||
domain_name << "_#{postfix}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module VagrantPlugins
|
||||
module ProviderLibvirt
|
||||
VERSION = '0.0.18'
|
||||
VERSION = '0.0.19'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +16,10 @@ Gem::Specification.new do |gem|
|
||||
gem.require_paths = ['lib']
|
||||
gem.version = VagrantPlugins::ProviderLibvirt::VERSION
|
||||
|
||||
gem.add_development_dependency "rspec-core", "~> 2.12.2"
|
||||
gem.add_development_dependency "rspec-expectations", "~> 2.12.1"
|
||||
gem.add_development_dependency "rspec-mocks", "~> 2.12.1"
|
||||
|
||||
gem.add_runtime_dependency 'fog', '~> 1.15'
|
||||
gem.add_runtime_dependency 'ruby-libvirt', '~> 0.4.0'
|
||||
gem.add_runtime_dependency 'nokogiri', '~> 1.5.9'
|
||||
|
||||
Reference in New Issue
Block a user