Collect the ip address of created VM for use with dns plugins

This commit is contained in:
Jake Spain 2023-02-15 09:52:04 -05:00
parent 26ad5a7a74
commit daa49dd1c9
No known key found for this signature in database
GPG key ID: BC1C4DA0A085E113

View file

@ -382,11 +382,34 @@ module Vmpooler
spec: clone_spec spec: clone_spec
).wait_for_completion ).wait_for_completion
# Make optional?
ip = get_vm_ip_address(new_vm_object)
@redis.with_metrics do |redis|
redis.hset("vmpooler__vm__#{new_vmname}", 'ip', ip)
end
vm_hash = generate_vm_hash(new_vm_object, pool_name) vm_hash = generate_vm_hash(new_vm_object, pool_name)
end end
vm_hash vm_hash
end end
# The inner method requires vmware tools running in the guest os
def get_vm_ip_address(vm_object, maxloop = 0, loop_delay = 1, max_age = 60)
loop_count = 1
ip = nil
while ip.nil?
sleep(loop_delay)
ip = vm_object.guest_ip
unless maxloop == 0
break if loop_count >= maxloop
loop_count += 1
end
end
return ip
end
def create_config_spec(vm_name, template_name, extra_config) def create_config_spec(vm_name, template_name, extra_config)
RbVmomi::VIM.VirtualMachineConfigSpec( RbVmomi::VIM.VirtualMachineConfigSpec(
annotation: JSON.pretty_generate( annotation: JSON.pretty_generate(