Generate human-readable hostnames

Names like cfcfqcuitlkutjo and phfyyu4t4ahjaae are impossible to
communicate outside of chat, and difficult to talk about. This commit
adds a dictionary of basic english words[1] and generates hostnames by
randomly joining three of them with -. Example hostnames:

clothes-at-sound
take-map-uncle
shoot-nearly-me
sail-eye-certain
trust-little-woman

[1] http://simple.wikipedia.org/wiki/Wikipedia:List_of_1000_basic_words
This commit is contained in:
Nick Lewis 2014-01-30 11:28:34 -08:00
parent 282727aaa2
commit 7f0d3f0df0
2 changed files with 1002 additions and 3 deletions

View file

@ -40,7 +40,11 @@ $vsphere = {}
# Our thread-tracker object
$threads = {}
$dictionary ||= File.readlines('dictionary').map(&:chomp)
def generate_hostname
(1..3).map { $dictionary[rand($dictionary.length)] }.join('-')
end
# Check the state of a VM
def check_pending_vm vm, pool, timeout
@ -148,9 +152,7 @@ def clone_vm template, pool, folder, datastore
raise "Unable to find template '#{vm['template']}'!"
end
# Generate a randomized hostname
o = [('a'..'z'),('0'..'9')].map{|r| r.to_a}.flatten
vm['hostname'] = o[rand(25)]+(0...14).map{o[rand(o.length)]}.join
vm['hostname'] = generate_hostname
# Add VM to Redis inventory ('pending' pool)
$redis.sadd('vmware_host_pool__pending__'+vm['template'], vm['hostname'])