New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add random hostname option #216
Conversation
@@ -50,7 +49,8 @@ def build_domain_name(env) | |||
config.default_prefix.to_s | |||
end | |||
domain_name.gsub!(/[^-a-z0-9_]/i, '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this point domain_name is just the prefix, which is shared between all VMs in the Vagrantfile. After the gsub
, you need
domain_name << '_'
domain_name << env[:machine].name.to_s
to add the individual machine's name.
This looks good. Add this to readme?? |
domain_name.gsub!(/[^-a-z0-9_]/i, '') | ||
domain_name << "_#{postfix}" | ||
domain_name << "_#{Time.now.utc.to_i}_#{SecureRandom.hex(10)}" if config.random_hostname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this point domain_name is just the prefix, which is shared between all VMs in the Vagrantfile. Before appending the random string, you need
domain_name << '_'
domain_name << env[:machine].name.to_s
to add the individual machine's name.
Thanks for working on this, but I'm confused exactly what values you're intending to use in the name. Here's what I was expecting
|
This commit lets users enable hostname randomization from their Vagrantfile. Without this option enabled, domain creation will fail when multiple VMs are spun up from the same Vagrantfile, due to a domain name conflict.
@sciurus @purpleidea Is this what you had in mind? |
Thanks @nicot ; name generation now looks good to me! I think you'll need to update the "builds simple domain name test" case. |
@nicot didn't test, but this looks good :) Assuming this passes the tests, +1 Thanks! |
add please description to README |
Updated documentation so that users could find the new option. Updated test case to behave as expected.
@nicot What I meant by updating the simple name test was something like this describe VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain do
before :each do
@env = EnvironmentHelper.new
+ @env.name = 'name'
end
it "builds unique domain name" do
@@ -16,6 +17,6 @@ describe VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain do
it "builds simple domain name" do
@env.default_prefix= 'pre'
dmn = VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain.new(Object.new, @env)
- dmn.build_domain_name(@env).should eq('pre_')
+ dmn.build_domain_name(@env).should eq('pre_name')
end
end so we test that the VM's name is incorporated in the domain name. |
I'm fine with merging this and then fixing up the tests, since I haven't heard from @nicot in a couple weeks. |
@pronix can you please merge this and cut a release? |
@sciurus I no longer have an environment where I can test these changes, so if you or anyone else wanted to take that over I'd appreciate it. |
Thanks everyone! |
Let the user add information to the hostname from their Vagrantfile.
When on, prevent domain name collisions.
Off by default.
Fixes #215