(QENG-7530) Make VM names more human readable

Prior to this commit hostnames for VMs provisioned by vmpooler were 15
random characters. This is difficult for humans to tell apart.

This commit updates the naming to use the `spicy-proton` gem to generate
adjective noun pair names for the VMs, which I think would be easier for
humans to tell apart, as well as fun and memorable to say.

The random name should not exceed 15 characters in order to prevent
issues with NETBIOS, etc as discussed in the attached ticket.
This commit is contained in:
Brandon High 2019-10-23 12:21:39 -07:00
parent 6cbc16cd80
commit 2ca6d49aeb
No known key found for this signature in database
GPG key ID: 270079C784FCAFDE
2 changed files with 7 additions and 2 deletions

View file

@ -12,6 +12,7 @@ gem 'net-ldap', '~> 0.16'
gem 'statsd-ruby', '~> 1.4.0', :require => 'statsd' gem 'statsd-ruby', '~> 1.4.0', :require => 'statsd'
gem 'connection_pool', '~> 2.2' gem 'connection_pool', '~> 2.2'
gem 'nokogiri', '~> 1.8' gem 'nokogiri', '~> 1.8'
gem 'spicy-proton', '2.1.1'
group :development do group :development do
gem 'pry' gem 'pry'

View file

@ -1,4 +1,5 @@
require 'vmpooler/providers' require 'vmpooler/providers'
require 'spicy-proton'
module Vmpooler module Vmpooler
class PoolManager class PoolManager
@ -29,6 +30,9 @@ module Vmpooler
@vm_mutex = {} @vm_mutex = {}
# Name generator for generating host names
@name_generator = Spicy::Proton.new
# load specified providers from config file # load specified providers from config file
load_used_providers load_used_providers
end end
@ -265,8 +269,8 @@ module Vmpooler
def _clone_vm(pool_name, provider) def _clone_vm(pool_name, provider)
# Generate a randomized hostname # Generate a randomized hostname
o = [('a'..'z'), ('0'..'9')].map(&:to_a).flatten random_name = [@name_generator.adjective(max: 7), @name_generator.noun(max: 7)].join('-')
new_vmname = $config[:config]['prefix'] + o[rand(25)] + (0...14).map { o[rand(o.length)] }.join new_vmname = $config[:config]['prefix'] + random_name
# Add VM to Redis inventory ('pending' pool) # Add VM to Redis inventory ('pending' pool)
$redis.sadd('vmpooler__pending__' + pool_name, new_vmname) $redis.sadd('vmpooler__pending__' + pool_name, new_vmname)