[DRE-commits] [vagrant-libvirt] 04/163: refactor set_domain_name to avoid duplicate names when running multiple guests.
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Apr 24 13:56:57 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 0e9458db6c2b3e9d1f8eea0e0df096dceb79ccda
Author: Bradley Smith <brad.smith at sendgrid.com>
Date: Fri Jul 4 10:47:29 2014 -0600
refactor set_domain_name to avoid duplicate names when running multiple guests.
---
lib/vagrant-libvirt/action/set_name_of_domain.rb | 47 +++++++++++++++---------
lib/vagrant-libvirt/version.rb | 2 +-
vagrant-libvirt.gemspec | 4 ++
3 files changed, 34 insertions(+), 19 deletions(-)
diff --git a/lib/vagrant-libvirt/action/set_name_of_domain.rb b/lib/vagrant-libvirt/action/set_name_of_domain.rb
index 1aeffdf..dc6e711 100644
--- a/lib/vagrant-libvirt/action/set_name_of_domain.rb
+++ b/lib/vagrant-libvirt/action/set_name_of_domain.rb
@@ -1,3 +1,4 @@
+require 'securerandom'
module VagrantPlugins
module ProviderLibvirt
module Action
@@ -5,28 +6,19 @@ module VagrantPlugins
# Setup name for domain and domain volumes.
class SetNameOfDomain
def initialize(app, env)
- @logger = Log4r::Logger.new("vagrant_libvirt::action::set_name_of_domain")
- @app = app
+ @logger = Log4r::Logger.new("vagrant_libvirt::action::set_name_of_domain")
+ @app = app
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}")
- # Check if the domain name is not already taken
-
+ @logger.info("Looking for domain #{env[:domain_name]} through list #{env[:libvirt_compute].servers.all}")
+ # Check if the domain name is not already taken
+
domain = ProviderLibvirt::Util::Collection.find_matching(
- env[:libvirt_compute].servers.all, env[:domain_name])
+ env[:libvirt_compute].servers.all, env[:domain_name])
rescue Fog::Errors::Error => e
@logger.info("#{e}")
domain = nil
@@ -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
diff --git a/lib/vagrant-libvirt/version.rb b/lib/vagrant-libvirt/version.rb
index 6d829da..438d3d2 100644
--- a/lib/vagrant-libvirt/version.rb
+++ b/lib/vagrant-libvirt/version.rb
@@ -1,5 +1,5 @@
module VagrantPlugins
module ProviderLibvirt
- VERSION = '0.0.18'
+ VERSION = '0.0.19'
end
end
diff --git a/vagrant-libvirt.gemspec b/vagrant-libvirt.gemspec
index 721e2c1..3728fb1 100644
--- a/vagrant-libvirt.gemspec
+++ b/vagrant-libvirt.gemspec
@@ -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'
--
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