(POOLER-142) Add running host to vm API data

This change adds the running host for a VM to the API data available via /vm/hostname. Without this change the running host would be logged to vmpooler log, but not available any other way. Additionally, the data will specify if a machine has been migrated. Without this change parent host data for a vmpooler machine is not available via the vmpooler API.
This commit is contained in:
kirby@puppetlabs.com 2019-08-21 12:43:06 -07:00
parent 9d48bc1b7e
commit 9c5a0d114b
7 changed files with 19 additions and 4 deletions

View file

@ -829,6 +829,10 @@ module Vmpooler
if config['domain']
result[params[:hostname]]['domain'] = config['domain']
end
result[params[:hostname]]['host'] = rdata['host'] if rdata['host']
result[params[:hostname]]['migrated'] = rdata['migrated'] if rdata['migrated']
end
JSON.pretty_generate(result)

View file

@ -939,6 +939,7 @@ module Vmpooler
begin
connection = ensured_vsphere_connection(pool_object)
vm_hash = get_vm_details(pool_name, vm_name, connection)
$redis.hset("vmpooler__vm__#{vm_name}", 'host', vm_hash['host_name'])
migration_limit = @config[:config]['migration_limit'] if @config[:config].key?('migration_limit')
migration_count = $redis.scard('vmpooler__migration')
if migration_enabled? @config
@ -965,9 +966,10 @@ module Vmpooler
def migrate_vm_to_new_host(pool_name, vm_name, vm_hash, connection)
$redis.sadd('vmpooler__migration', vm_name)
target_host_name = select_next_host(pool_name, @provider_hosts, vm_hash['architecture'])
$redis.hset("vmpooler__vm__#{vm_name}", 'host', target_host_name)
$redis.hset("vmpooler__vm__#{vm_name}", 'migrated', true)
target_host_object = find_host_by_dnsname(connection, target_host_name)
finish = migrate_vm_and_record_timing(pool_name, vm_name, vm_hash, target_host_object, target_host_name)
#logger.log('s', "Provider_hosts is: #{provider.provider_hosts}")
logger.log('s', "[>] [#{pool_name}] '#{vm_name}' migrated from #{vm_hash['host_name']} to #{target_host_name} in #{finish} seconds")
ensure
$redis.srem('vmpooler__migration', vm_name)