src/vsphere_cpi/lib/cloud/vsphere/nsxt_provider.rb
# Add vm to given list of static Load Balancer Server Pools
# @param [Resources::VM] vm
# @param [[NSXT::LbPool, integer][]] server_pools Array of Load_balancer_pool and port no
Add vm to given list of static Load Balancer Server Pools
Add vm to given list of static Load Balancer Server Pools
def add_vm_to_server_pools(vm, server_pools)
      return if server_pools.nil? || server_pools.empty?
      Bosh::Retryable.new(
        tries: 50,
        sleep: ->(try_count, retry_exception) { 2 },
        on: [VirtualMachineIpNotFound]
      ).retryer do |i|
        vm_ip = vm.mob.guest&.ip_address
        raise VirtualMachineIpNotFound.new(vm) unless vm_ip
        server_pools.each do |server_pool, port_no|
          logger.info("Adding vm: '#{vm.cid}' with ip:#{vm_ip} to ServerPool: #{server_pool.id} on Port: #{port_no} ")
          pool_member = NSXT::PoolMemberSetting.new(ip_address: vm_ip, port: port_no)
          pool_member_setting_list = NSXT::PoolMemberSettingList.new(members: [pool_member])
          begin
            services_svc.perform_pool_member_action(server_pool.id, pool_member_setting_list, 'ADD_MEMBERS')
          rescue NSXT::ApiCallError => e
            retry if e.code == 409 || e.code == 412 
            raise e
          end
        end
      end
    end
def add_vm_to_server_pools ( vm , server_pools ) return if server_pools . nil? || server_pools . empty? Bosh :: Retryable . new ( tries : 50 , sleep : -> ( try_count , retry_exception ) { 2 } , on : [ VirtualMachineIpNotFound ] ) . retryer do | i | vm_ip = vm . mob . guest &. ip_address raise VirtualMachineIpNotFound . new ( vm ) unless vm_ip server_pools . each do | server_pool , port_no | logger . info ( "Adding vm: '#{vm.cid}' with ip:#{vm_ip} to ServerPool: #{server_pool.id} on Port: #{port_no} " ) pool_member = NSXT :: PoolMemberSetting . new ( ip_address : vm_ip , port : port_no ) pool_member_setting_list = NSXT :: PoolMemberSettingList . new ( members : [ pool_member ] ) begin services_svc . perform_pool_member_action ( server_pool . id , pool_member_setting_list , 'ADD_MEMBERS' ) rescue NSXT :: ApiCallError => e retry if e . code == 409 || e . code == 412 raise e end end end end
Add vm to given list of static Load Balancer Server Pools
Add vm to given list of static Load Balancer Server Pools
#Conflict or PreconditionFailed
vm
server_pools
None
server_pools Array of Load_balancer_pool and port no
server_pools Array of Load_balancer_pool and port no