Class: ChefProvisioningVsphere::VmHelper
- Inherits:
-
Object
- Object
- ChefProvisioningVsphere::VmHelper
- Defined in:
- lib/chef/provisioning/vsphere_driver/vm_helper.rb
Overview
Helps save data in provisioning a machine
Constant Summary collapse
- RESCUE_EXCEPTIONS_ON_ESTABLISH =
An array of all the known EXCEPTIONS for connecting via Chef-Provisioning-vSphere
[ Errno::EACCES, Errno::EADDRINUSE, Errno::ECONNREFUSED, Errno::ETIMEDOUT, Errno::ECONNRESET, Errno::ENETUNREACH, Errno::EHOSTUNREACH, Errno::EPIPE, Errno::EPERM, Errno::EFAULT, Errno::EIO, Errno::EHOSTDOWN, Net::SSH::Disconnect, Net::SSH::AuthenticationFailed, Net::SSH::ConnectionTimeout, Timeout::Error, IPAddr::AddressFamilyError ].freeze
Instance Attribute Summary collapse
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
-
#find_port?(vm, options) ⇒ true
Finds the port for to connect to the vm.
-
#open_port?(host, port, timeout = 5) ⇒ true
Attempt to connects to the open port.
-
#port? ⇒ Boolean
If the port is true.
Instance Attribute Details
#ip ⇒ Object
Returns the value of attribute ip.
9 10 11 |
# File 'lib/chef/provisioning/vsphere_driver/vm_helper.rb', line 9 def ip @ip end |
#port ⇒ Object
Returns the value of attribute port.
9 10 11 |
# File 'lib/chef/provisioning/vsphere_driver/vm_helper.rb', line 9 def port @port end |
Instance Method Details
#find_port?(vm, options) ⇒ true
Finds the port for to connect to the vm
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/chef/provisioning/vsphere_driver/vm_helper.rb', line 31 def find_port?(vm, ) @port = [:ssh][:port] customization_spec = [: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) ⇒ true
Attempt to connects to the open port
54 55 56 57 58 59 |
# 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? ⇒ Boolean
If the port is true
22 23 24 |
# File 'lib/chef/provisioning/vsphere_driver/vm_helper.rb', line 22 def port? @port end |