mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
Generate a wider set of legal names
Previously, we restricted the adjective and noun portion of the name each to 7 characters to ensure that the final name would not be more than 15 after adding a hyphen. Given that the _total_ length is what matters, we can generate a noun up to 11 characters (to ensure we leave room for a hyphen and a 3 letter adjective) and adjust our acceptable adjective size accordingly. This lets many more names be generated than would otherwise, while still respecting the 15 character limit. Due to the limited set of 11 letter nouns and corresponding 3 letter adjectives, as well as some complex combinatorics, setting the noun length to 11 causes a net increase in conflicts. We therefore actually set it to 10, which causes a net decrease in conflicts. We favor generating longer nouns rather than longer adjectives (by selecting the noun first) because longer adjectives tend to be more unwieldy words, and thus more awkward to say and generally less fun.
This commit is contained in:
parent
94eacdd7af
commit
c4f3a49782
1 changed files with 11 additions and 2 deletions
|
|
@ -269,8 +269,17 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_and_check_hostname(pool_name)
|
def generate_and_check_hostname(pool_name)
|
||||||
# Generate a randomized hostname
|
# Generate a randomized hostname. The total name must no longer than 15
|
||||||
random_name = [@name_generator.adjective(max: 7), @name_generator.noun(max: 7)].join('-')
|
# character including the hyphen. The shortest adjective in the corpus is
|
||||||
|
# three characters long. Therefore, we can technically select a noun up to 11
|
||||||
|
# characters long and still be guaranteed to have an available adjective.
|
||||||
|
# Because of the limited set of 11 letter nouns and corresponding 3
|
||||||
|
# letter adjectives, we actually limit the noun to 10 letters to avoid
|
||||||
|
# inviting more conflicts. We favor selecting a longer noun rather than a
|
||||||
|
# longer adjective because longer adjectives tend to be less fun.
|
||||||
|
noun = @name_generator.noun(max: 10)
|
||||||
|
adjective = @name_generator.adjective(max: 14-noun.length)
|
||||||
|
random_name = [adjective, noun].join('-')
|
||||||
hostname = $config[:config]['prefix'] + random_name
|
hostname = $config[:config]['prefix'] + random_name
|
||||||
available = $redis.hlen('vmpooler__vm__' + hostname) == 0
|
available = $redis.hlen('vmpooler__vm__' + hostname) == 0
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue