Sha256: 52ca2477fc222cb47ca82ab99535f5b4ab0a867ab0979ddcd5bf2058fcf955c0

Contents?: true

Size: 1.94 KB

Versions: 23

Compression:

Stored size: 1.94 KB

Contents

module Fog
  module Vsphere
    class Compute
      class Real
        def vm_config_vnc(options = {})
          raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'

          search_filter = { :uuid => options['instance_uuid'], 'vmSearch' => true, 'instanceUuid' => true }
          vm_mob_ref    = connection.searchIndex.FindAllByUuid(search_filter).first
          task          = vm_mob_ref.ReconfigVM_Task(spec: {
                                                       extraConfig: [
                                                         { key: 'RemoteDisplay.vnc.enabled',  value: options[:enabled] ? 'true' : 'false' },
                                                         { key: 'RemoteDisplay.vnc.password', value: options[:password].to_s },
                                                         { key: 'RemoteDisplay.vnc.port',     value: options[:port].to_s || '5910' }
                                                       ]
                                                     })
          task.wait_for_completion
          { 'task_state' => task.info.state }
        end

        # return a hash of VNC attributes required to view the console
        def vm_get_vnc(uuid)
          search_filter = { :uuid => uuid, 'vmSearch' => true, 'instanceUuid' => true }
          vm = connection.searchIndex.FindAllByUuid(search_filter).first
          Hash[vm.config.extraConfig.map do |config|
            if config.key =~ /^RemoteDisplay\.vnc\.(\w+)$/
              [Regexp.last_match(1).to_sym, config.value]
            end
          end.compact]
        end
      end

      class Mock
        def vm_config_vnc(options = {})
          raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
          { 'task_state' => 'success' }
        end

        def vm_get_vnc(_uuid)
          { password: 'secret', port: '5900', enabled: 'true' }
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
fog-vsphere-3.7.0 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.6.8 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.6.7 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.6.6 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.6.5 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.6.4 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.6.3 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.6.2 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.5.3 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.6.0 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.5.2 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.5.1 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.5.0 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.4.0 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.3.1 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.3.0 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.2.5 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.2.2 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.2.1 lib/fog/vsphere/requests/compute/vm_config_vnc.rb
fog-vsphere-3.2.0 lib/fog/vsphere/requests/compute/vm_config_vnc.rb