Files
vagrant-libvirt/lib/vagrant-libvirt/action/set_name_of_domain.rb
James Shubin 0ac7498f4d Add provider specific default_prefix option.
This patch adds support for a provider specific default_prefix option.
When set, this value is used instead of the project's dir name as the
prefix for the machines being created.
2014-01-11 22:31:53 -05:00

44 lines
1.3 KiB
Ruby

module VagrantPlugins
module ProviderLibvirt
module Action
# 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
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
@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])
@logger.info("Looking for domain #{env[:domain_name]}")
if domain != nil
raise ProviderLibvirt::Errors::DomainNameExists,
:domain_name => env[:domain_name]
end
@app.call(env)
end
end
end
end
end