Class: VSphereCloud::IPConflictDetector
- Inherits:
-
Object
- Object
- VSphereCloud::IPConflictDetector
- Defined in:
- lib/cloud/vsphere/ip_conflict_detector.rb
Instance Method Summary collapse
- #conflicts ⇒ Object
-
#initialize(logger, client, networks) ⇒ IPConflictDetector
constructor
A new instance of IPConflictDetector.
Constructor Details
#initialize(logger, client, networks) ⇒ IPConflictDetector
Returns a new instance of IPConflictDetector.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cloud/vsphere/ip_conflict_detector.rb', line 4 def initialize(logger, client, networks) @logger = logger @client = client @networks = networks @desired_ip_mapping = [] @networks.map do |_, network_spec| ip = network_spec['ip'] network_name = network_spec.fetch('cloud_properties', [])['name'] if ip && network_name @desired_ip_mapping << {ip: ip, name: network_name} end end end |
Instance Method Details
#conflicts ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cloud/vsphere/ip_conflict_detector.rb', line 20 def conflicts conflicts = [] @desired_ip_mapping.each do |mapping| @logger.info("Checking if ip '#{mapping[:ip]}' is in use") vm = @client.find_vm_by_ip(mapping[:ip]) if vm.nil? next end vm.guest.net.each do |nic| if nic.ip_address.include?(mapping[:ip]) && nic.network == mapping[:name] @logger.info("found conflicting vm: #{vm.name}, on network: #{mapping[:name]} with ip: #{mapping[:ip]}") conflicts << {vm_name: vm.name, network_name: mapping[:name], ip: mapping[:ip]} end end end conflicts end |