mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
commit
b3d888a7bb
@ -148,6 +148,7 @@ end
|
||||
* `volume_cache` - Controls the cache mechanism. Possible values are "default", "none", "writethrough", "writeback", "directsync" and "unsafe". [See driver->cache in libvirt documentation](http://libvirt.org/formatdomain.html#elementsDisks).
|
||||
* `kernel` - To launch the guest with a kernel residing on host filesystems. Equivalent to qemu `-kernel`.
|
||||
* `initrd` - To specify the initramfs/initrd to use for the guest. Equivalent to qemu `-initrd`.
|
||||
* `random_hostname` - To create a domain name with extra information on the end to prevent hostname conflicts.
|
||||
* `cmd_line` - Arguments passed on to the guest kernel initramfs or initrd to use. Equivalent to qemu `-append`.
|
||||
|
||||
|
||||
|
@ -35,13 +35,13 @@ module VagrantPlugins
|
||||
end
|
||||
|
||||
# build domain name
|
||||
# avoids `domain about to create is already taken`
|
||||
# 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
|
||||
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?
|
||||
@ -49,8 +49,11 @@ module VagrantPlugins
|
||||
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 << "_#{postfix}"
|
||||
domain_name << "_#{Time.now.utc.to_i}_#{SecureRandom.hex(10)}" if config.random_hostname
|
||||
domain_name
|
||||
end
|
||||
|
||||
end
|
||||
@ -58,4 +61,3 @@ module VagrantPlugins
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -40,6 +40,9 @@ module VagrantPlugins
|
||||
# be stored.
|
||||
attr_accessor :storage_pool_name
|
||||
|
||||
# Turn on to prevent hostname conflicts
|
||||
attr_accessor :random_hostname
|
||||
|
||||
# Libvirt default network
|
||||
attr_accessor :management_network_name
|
||||
attr_accessor :management_network_address
|
||||
@ -70,6 +73,7 @@ module VagrantPlugins
|
||||
@password = UNSET_VALUE
|
||||
@id_ssh_key_file = UNSET_VALUE
|
||||
@storage_pool_name = UNSET_VALUE
|
||||
@random_hostname = UNSET_VALUE
|
||||
@management_network_name = UNSET_VALUE
|
||||
@management_network_address = UNSET_VALUE
|
||||
|
||||
@ -182,6 +186,7 @@ module VagrantPlugins
|
||||
@password = nil if @password == UNSET_VALUE
|
||||
@id_ssh_key_file = 'id_rsa' if @id_ssh_key_file == UNSET_VALUE
|
||||
@storage_pool_name = 'default' if @storage_pool_name == UNSET_VALUE
|
||||
@random_hostname = false if @random_hostname == UNSET_VALUE
|
||||
@management_network_name = 'vagrant-libvirt' if @management_network_name == UNSET_VALUE
|
||||
@management_network_address = '192.168.121.0/24' if @management_network_address == UNSET_VALUE
|
||||
|
||||
|
@ -3,7 +3,9 @@ require "pathname"
|
||||
|
||||
class EnvironmentHelper
|
||||
|
||||
attr_writer :default_prefix, :domain_name
|
||||
attr_writer :domain_name
|
||||
|
||||
attr_accessor :random_hostname, :name, :default_prefix
|
||||
|
||||
def [](value)
|
||||
self.send(value.to_sym)
|
||||
@ -17,10 +19,6 @@ class EnvironmentHelper
|
||||
self
|
||||
end
|
||||
|
||||
def default_prefix
|
||||
# noop
|
||||
end
|
||||
|
||||
def root_path
|
||||
Pathname.new("./spec/support/foo")
|
||||
end
|
||||
|
@ -5,10 +5,17 @@ describe VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain do
|
||||
@env = EnvironmentHelper.new
|
||||
end
|
||||
|
||||
it "builds uniqie domain name" do
|
||||
it "builds unique domain name" do
|
||||
@env.random_hostname = true
|
||||
dmn = VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain.new(Object.new, @env)
|
||||
first = dmn.build_domain_name(@env)
|
||||
second = dmn.build_domain_name(@env)
|
||||
first.should_not eq(second)
|
||||
end
|
||||
|
||||
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_')
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user