mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
(POOLER-166) Vmpooler should check DNS to ensure a record does not exist before VM creation
initial draft
This commit is contained in:
parent
46af69f67b
commit
616db575f8
5 changed files with 65 additions and 1 deletions
|
|
@ -498,6 +498,19 @@ module Vmpooler
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dns_live?(vn_name, domain = nil)
|
||||||
|
require 'resolv' #ruby standard lib
|
||||||
|
fqdn = vm_name
|
||||||
|
fqdn = "#{fqdn}.#{domain}" if domain
|
||||||
|
begin
|
||||||
|
dnsip = Resolv.getaddress(fqdn)
|
||||||
|
rescue
|
||||||
|
dnsip = "N/A"
|
||||||
|
end
|
||||||
|
dnsip
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,7 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_single_vm(template)
|
def fetch_single_vm(template)
|
||||||
|
require 'vmpooler/providers/vsphere'
|
||||||
template_backends = [template]
|
template_backends = [template]
|
||||||
aliases = Vmpooler::API.settings.config[:alias]
|
aliases = Vmpooler::API.settings.config[:alias]
|
||||||
if aliases
|
if aliases
|
||||||
|
|
@ -144,6 +145,8 @@ module Vmpooler
|
||||||
|
|
||||||
vms.reverse.each do |vm|
|
vms.reverse.each do |vm|
|
||||||
ready = vm_ready?(vm, config['domain'])
|
ready = vm_ready?(vm, config['domain'])
|
||||||
|
dnsip = dns_live?(vm, config['domain'])
|
||||||
|
ips = get_all_ip_for_nics(template_backend, vm)
|
||||||
if ready
|
if ready
|
||||||
smoved = backend.smove("vmpooler__ready__#{template_backend}", "vmpooler__running__#{template_backend}", vm)
|
smoved = backend.smove("vmpooler__ready__#{template_backend}", "vmpooler__running__#{template_backend}", vm)
|
||||||
if smoved
|
if smoved
|
||||||
|
|
|
||||||
|
|
@ -1093,6 +1093,27 @@ module Vmpooler
|
||||||
return true if pool['create_linked_clone']
|
return true if pool['create_linked_clone']
|
||||||
return true if @config[:config]['create_linked_clones']
|
return true if @config[:config]['create_linked_clones']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def _get_all_ip_for_nics(pool_name, vm_name, connection)
|
||||||
|
result = []
|
||||||
|
vm_object = find_vm(pool_name, vm_name, connection)
|
||||||
|
vm_object.guest.net.each do |nic|
|
||||||
|
addresses = nic.ipAddress
|
||||||
|
|
||||||
|
addresses.each do |adr|
|
||||||
|
puts adr
|
||||||
|
result << adr
|
||||||
|
end
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_all_ip_for_nics(pool_name, vm_name)
|
||||||
|
@connection_pool.with_metrics do |pool_object|
|
||||||
|
connection = ensured_vsphere_connection(pool_object)
|
||||||
|
_get_all_ip_for_nics(pool_name, vm_name, connection)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,10 @@ MockVirtualMachine = Struct.new(
|
||||||
:name,
|
:name,
|
||||||
# From RbVmomi::VIM::ManagedEntity
|
# From RbVmomi::VIM::ManagedEntity
|
||||||
# https://github.com/vmware/rbvmomi/blob/master/lib/rbvmomi/vim/ManagedEntity.rb
|
# https://github.com/vmware/rbvmomi/blob/master/lib/rbvmomi/vim/ManagedEntity.rb
|
||||||
:path
|
:path,
|
||||||
|
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.GuestInfo.html
|
||||||
|
# From GuestInfo
|
||||||
|
:guest
|
||||||
)
|
)
|
||||||
|
|
||||||
MockVirtualMachineSnapshot = Struct.new(
|
MockVirtualMachineSnapshot = Struct.new(
|
||||||
|
|
@ -288,6 +291,18 @@ MockVirtualHardware = Struct.new(
|
||||||
:device
|
:device
|
||||||
)
|
)
|
||||||
|
|
||||||
|
MockGuestInfo = Struct.new(
|
||||||
|
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.GuestInfo.html
|
||||||
|
# From GuestInfo
|
||||||
|
:hostName, :ipAddress, :net
|
||||||
|
)
|
||||||
|
|
||||||
|
MockGuestNicInfo = Struct.new(
|
||||||
|
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.GuestInfo.NicInfo.html
|
||||||
|
# From GuestNicInfo
|
||||||
|
:connected, :ipAddress, :macAddress
|
||||||
|
)
|
||||||
|
|
||||||
MockVirtualMachineConfigInfo = Struct.new(
|
MockVirtualMachineConfigInfo = Struct.new(
|
||||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.ConfigInfo.html
|
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.ConfigInfo.html
|
||||||
# From VirtualMachineConfigInfo
|
# From VirtualMachineConfigInfo
|
||||||
|
|
@ -691,6 +706,8 @@ def mock_RbVmomi_VIM_VirtualMachine(options = {})
|
||||||
mock = MockVirtualMachine.new()
|
mock = MockVirtualMachine.new()
|
||||||
mock.config = MockVirtualMachineConfigInfo.new()
|
mock.config = MockVirtualMachineConfigInfo.new()
|
||||||
mock.config.hardware = MockVirtualHardware.new([])
|
mock.config.hardware = MockVirtualHardware.new([])
|
||||||
|
mock.guest = MockGuestInfo.new()
|
||||||
|
mock.guest.net = MockGuestNicInfo.new([])
|
||||||
mock.summary = MockVirtualMachineSummary.new()
|
mock.summary = MockVirtualMachineSummary.new()
|
||||||
mock.summary.runtime = MockVirtualMachineRuntimeInfo.new()
|
mock.summary.runtime = MockVirtualMachineRuntimeInfo.new()
|
||||||
mock.summary.guest = MockVirtualMachineGuestSummary.new()
|
mock.summary.guest = MockVirtualMachineGuestSummary.new()
|
||||||
|
|
|
||||||
|
|
@ -3312,6 +3312,16 @@ EOT
|
||||||
|
|
||||||
expect(subject.find_vm(poolname,missing_vm,connection)).to be_nil
|
expect(subject.find_vm(poolname,missing_vm,connection)).to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'new test' do
|
||||||
|
expect(connection.searchIndex).to receive(:FindByInventoryPath).and_return(vm_object)
|
||||||
|
nic_a = MockGuestNicInfo.new()
|
||||||
|
nic_b = MockGuestNicInfo.new()
|
||||||
|
expect(vm_object.guest).to receive(:net).and_return([nic_a,nic_b])
|
||||||
|
expect(nic_a).to receive(:ipAddress).and_return(["192.168.0.1", "192.168.0.2"])
|
||||||
|
expect(nic_b).to receive(:ipAddress).and_return(["192.167.0.1"])
|
||||||
|
subject.get_all_ip_for_nics(poolname,missing_vm,connection)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#get_base_vm_container_from' do
|
describe '#get_base_vm_container_from' do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue