class ChefProvisioningVsphere::VmHelper

Helps save data in provisioning a machine

Constants

RESCUE_EXCEPTIONS_ON_ESTABLISH

An array of all the known EXCEPTIONS for connecting via Chef-Provisioning-vSphere

Attributes

ip[RW]
port[RW]

Public Instance Methods

find_port?(vm, options) click to toggle source

Finds the port for to connect to the vm

@param [Object] vm Uses the VM object from Chef provisioning. @param [Hash] options Uses the VM options from Chef provisioning. @return [true] The port to connect to the VM whether Windows or *nix.

# File lib/chef/provisioning/vsphere_driver/vm_helper.rb, line 31
def find_port?(vm, options)
  @port = options[:ssh][:port]
  customization_spec = options[:customization_spec]
  if vm.config.guestId.start_with?("win")
    if customization_spec.is_a?(Hash)
      winrm_transport =
        customization_spec[:winrm_transport].nil? ? :negotiate : customization_spec[:winrm_transport].to_sym
    end
    winrm_transport ||= :negotiate
    default_win_port = winrm_transport == :ssl ? "5986" : "5985"
    @port = default_win_port if @port.nil?
  elsif port.nil?
    @port = "22"
  end
  true
end
open_port?(host, port, timeout = 5) click to toggle source

Attempt to connects to the open port

@param [String] host Uses the host string to connect. @param [String] port Uses the port number to connect. @param [Integer] timeout The number of seconds before timeout. @return [true] Returns true when the socket is available to connect.

# File lib/chef/provisioning/vsphere_driver/vm_helper.rb, line 54
def open_port?(host, port, timeout = 5)
  return false if host.to_s.empty?
  true if ::Socket.tcp(host, port, connect_timeout: timeout)
rescue *RESCUE_EXCEPTIONS_ON_ESTABLISH
  false
end
port?() click to toggle source

If the port is true

# File lib/chef/provisioning/vsphere_driver/vm_helper.rb, line 22
def port?
  @port
end