class VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain
Setup name for domain and domain volumes.
Public Class Methods
new(app, env)
click to toggle source
# File lib/vagrant-libvirt/action/set_name_of_domain.rb, line 8 def initialize(app, env) @logger = Log4r::Logger.new("vagrant_libvirt::action::set_name_of_domain") @app = app end
Public Instance Methods
build_domain_name(env)
click to toggle source
build domain name random_hostname option avoids `domain about to create is already taken` parsable and sortable by epoch time @example
development-centos-6-chef-11_1404488971_3b7a569e2fd7c554b852
@return [String] libvirt domain name
# File lib/vagrant-libvirt/action/set_name_of_domain.rb, line 44 def build_domain_name(env) 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 << '_' domain_name << env[:machine].name.to_s domain_name.gsub!(/[^-a-z0-9_]/i, '') domain_name << "_#{Time.now.utc.to_i}_#{SecureRandom.hex(10)}" if config.random_hostname domain_name end
call(env)
click to toggle source
# File lib/vagrant-libvirt/action/set_name_of_domain.rb, line 13 def call(env) 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 domain = ProviderLibvirt::Util::Collection.find_matching( env[:libvirt_compute].servers.all, env[:domain_name]) rescue Fog::Errors::Error => e @logger.info("#{e}") domain = nil end @logger.info("Looking for domain #{env[:domain_name]}") unless domain.nil? raise ProviderLibvirt::Errors::DomainNameExists, :domain_name => env[:domain_name] end @app.call(env) end