class OvirtSDK4::VmGraphicsConsoleService

Public Class Methods

new(connection, path) click to toggle source

Creates a new implementation of the service.

@param connection [Connection] The connection to be used by this service.

@param path [String] The relative path of this service, for example `vms/123/disks`.

@api private

# File lib/ovirtsdk4/services.rb, line 30778
def initialize(connection, path)
  @connection = connection
  @path = path
end

Public Instance Methods

get(opts = {}) click to toggle source

Gets graphics console configuration of the virtual machine.

@param opts [Hash] Additional options.

@option opts [Boolean] :current Use the following query to obtain the current run-time configuration of the graphics console.

[source]
----
GET /ovit-engine/api/vms/123/graphicsconsoles/456?current=true
----

The default value is `false`.

@return [GraphicsConsole]

# File lib/ovirtsdk4/services.rb, line 30799
def get(opts = {})
  query = {}
  value = opts[:current]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['current'] = value
  end
  request = HttpRequest.new(method: :GET, url: @path, query: query)
  response = @connection.send(request)
  case response.code
  when 200
    begin
      reader = XmlReader.new(response.body)
      return GraphicsConsoleReader.read_one(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end
proxy_ticket(opts = {}) click to toggle source

Executes the `proxy_ticket` method.

@param opts [Hash] Additional options.

@option opts [Boolean] :async Indicates if the generation of the ticket should be performed asynchronously.

@option opts [ProxyTicket] :proxy_ticket

# File lib/ovirtsdk4/services.rb, line 30830
def proxy_ticket(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = HttpRequest.new(
    method: :POST,
    url: "#{@path}/proxyticket",
    body: body
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
    return action.proxy_ticket
  else
    check_action(response)
  end
end
remote_viewer_connection_file(opts = {}) click to toggle source

Generates the file which is compatible with `remote-viewer` client.

Use the following request to generate remote viewer connection file of the graphics console. Note that this action generates the file only if virtual machine is running.

source

POST /ovirt-engine/api/vms/123/graphicsconsoles/456/remoteviewerconnectionfile


The `remoteviewerconnectionfile` action does not take any action specific parameters, so the request body should contain an empty `action`:

source,xml

<action/>


The response contains the file, which can be used with `remote-viewer` client.

source,xml

<action>

<remote_viewer_connection_file>
  [virt-viewer]
  type=spice
  host=192.168.1.101
  port=-1
  password=123456789
  delete-this-file=1
  fullscreen=0
  toggle-fullscreen=shift+f11
  release-cursor=shift+f12
  secure-attention=ctrl+alt+end
  tls-port=5900
  enable-smartcard=0
  enable-usb-autoshare=0
  usb-filter=null
  tls-ciphers=DEFAULT
  host-subject=O=local,CN=example.com
  ca=...
</remote_viewer_connection_file>

</action>


E.g., to fetch the content of remote viewer connection file and save it into temporary file, user can use oVirt Python SDK as follows:

source,python

# Find the virtual machine: vm = vms_service.list(search=‘name=myvm’)

# Locate the service that manages the virtual machine, as that is where # the locators are defined: vm_service = vms_service.vm_service(vm.id)

# Find the graphic console of the virtual machine: graphics_consoles_service = vm_service.graphics_consoles_service() graphics_console = graphics_consoles_service.list()

# Generate the remote viewer connection file: console_service = graphics_consoles_service.console_service(graphics_console.id) #remote_viewer_connection_file = console_service.remote_viewer_connection_file()

# Write the content to file “/tmp/remote_viewer_connection_file.vv” path = “/tmp/remote_viewer_connection_file.vv” with open(path, “w”) as f:

f.write(remote_viewer_connection_file)

When you create the remote viewer connection file, then you can connect to virtual machine graphic console, as follows:

source,bash

#!/bin/sh -ex

remote-viewer –ovirt-ca-file=/etc/pki/ovirt-engine/ca.pem /tmp/remote_viewer_connection_file.vv


@param opts [Hash] Additional options.

@option opts [String] :remote_viewer_connection_file Contains the file which is compatible with `remote-viewer` client.

User can use the content of this attribute to create a file, which can be passed to `remote-viewer` client to
connect to virtual machine graphic console.
# File lib/ovirtsdk4/services.rb, line 30940
def remote_viewer_connection_file(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = HttpRequest.new(
    method: :POST,
    url: "#{@path}/remoteviewerconnectionfile",
    body: body
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
    return action.remote_viewer_connection_file
  else
    check_action(response)
  end
end
remove(opts = {}) click to toggle source

Remove the graphics console from the virtual machine.

@param opts [Hash] Additional options.

@option opts [Boolean] :async Indicates if the remove should be performed asynchronously.

# File lib/ovirtsdk4/services.rb, line 30967
def remove(opts = {})
  query = {}
  value = opts[:async]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['async'] = value
  end
  request = HttpRequest.new(method: :DELETE, url: @path, query: query)
  response = @connection.send(request)
  unless response.code == 200
    check_fault(response)
  end
end
service(path) click to toggle source

Locates the service corresponding to the given path.

@param path [String] The path of the service.

@return [Service] A reference to the service.

# File lib/ovirtsdk4/services.rb, line 31035
def service(path)
  if path.nil? || path == ''
    return self
  end
  raise Error.new("The path \"#{path}\" doesn't correspond to any service")
end
ticket(opts = {}) click to toggle source

Generates a time-sensitive authentication token for accessing this virtual machine's console.

source

POST /ovirt-engine/api/vms/123/graphicsconsoles/456/ticket


The client-provided action optionally includes a desired ticket value and/or an expiry time in seconds.

In any case, the response specifies the actual ticket value and expiry used.

source,xml

<action>

<ticket>
  <value>abcd12345</value>
  <expiry>120</expiry>
</ticket>

</action>


@param opts [Hash] Additional options.

@option opts [Ticket] :ticket The generated ticket that can be used to access this console.

# File lib/ovirtsdk4/services.rb, line 31007
def ticket(opts = {})
  action = Action.new(opts)
  writer = XmlWriter.new(nil, true)
  ActionWriter.write_one(action, writer)
  body = writer.string
  writer.close
  request = HttpRequest.new(
    method: :POST,
    url: "#{@path}/ticket",
    body: body
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
    return action.ticket
  else
    check_action(response)
  end
end
to_s() click to toggle source

Returns an string representation of this service.

@return [String]

# File lib/ovirtsdk4/services.rb, line 31047
def to_s
  "#<#{VmGraphicsConsoleService}:#{@path}>"
end