class OvirtSDK4::VmService

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 24918
def initialize(connection, path)
  @connection = connection
  @path = path
end

Public Instance Methods

affinity_labels_service() click to toggle source

List of scheduling labels assigned to this VM.

@return [AssignedAffinityLabelsService] A reference to `affinity_labels` service.

# File lib/ovirtsdk4/services.rb, line 25616
def affinity_labels_service
  return AssignedAffinityLabelsService.new(@connection, "#{@path}/affinitylabels")
end
applications_service() click to toggle source

Locates the `applications` service.

@return [VmApplicationsService] A reference to `applications` service.

# File lib/ovirtsdk4/services.rb, line 25624
def applications_service
  return VmApplicationsService.new(@connection, "#{@path}/applications")
end
cancel_migration(opts = {}) click to toggle source

Executes the `cancel_migration` method.

@param opts [Hash] Additional options.

@option opts [Boolean] :async Indicates if the migration should cancelled asynchronously.

# File lib/ovirtsdk4/services.rb, line 24930
def cancel_migration(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}/cancelmigration",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
cdroms_service() click to toggle source

Locates the `cdroms` service.

@return [VmCdromsService] A reference to `cdroms` service.

# File lib/ovirtsdk4/services.rb, line 25632
def cdroms_service
  return VmCdromsService.new(@connection, "#{@path}/cdroms")
end
clone(opts = {}) click to toggle source

Executes the `clone` method.

@param opts [Hash] Additional options.

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

@option opts [Vm] :vm

# File lib/ovirtsdk4/services.rb, line 24959
def clone(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}/clone",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
commit_snapshot(opts = {}) click to toggle source

Executes the `commit_snapshot` method.

@param opts [Hash] Additional options.

@option opts [Boolean] :async Indicates if the snapshots should be committed asynchronously.

# File lib/ovirtsdk4/services.rb, line 24986
def commit_snapshot(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}/commitsnapshot",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
detach(opts = {}) click to toggle source

Executes the `detach` method.

@param opts [Hash] Additional options.

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

# File lib/ovirtsdk4/services.rb, line 25013
def detach(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}/detach",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
disk_attachments_service() click to toggle source

List of disks attached to this virtual machine.

@return [DiskAttachmentsService] A reference to `disk_attachments` service.

# File lib/ovirtsdk4/services.rb, line 25640
def disk_attachments_service
  return DiskAttachmentsService.new(@connection, "#{@path}/diskattachments")
end
export(opts = {}) click to toggle source

Executes the `export` method.

@param opts [Hash] Additional options.

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

@option opts [Boolean] :discard_snapshots

@option opts [Boolean] :exclusive

@option opts [StorageDomain] :storage_domain

# File lib/ovirtsdk4/services.rb, line 25046
def export(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}/export",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
freeze_filesystems(opts = {}) click to toggle source

Executes the `freeze_filesystems` method.

@param opts [Hash] Additional options.

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

# File lib/ovirtsdk4/services.rb, line 25073
def freeze_filesystems(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}/freezefilesystems",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
get(opts = {}) click to toggle source

Retrieves the description of the virtual machine.

Note that some elements of the description of the virtual machine won't be returned unless the `All-Content` header is present in the request and has the value `true`. The elements that aren't currently returned are the following:

  • `console`

  • `initialization.configuration.data` - The OVF document describing the virtual machine.

  • `rng_source`

  • `soundcard`

  • `virtio_scsi`

With the Python SDK the `All-Content` header can be set using the `all_content` parameter of the `get` method:

source,python

api.vms.get(name=“myvm”, all_content=True)


Note that the reason for not including these elements is performance: they are seldom used and they require additional queries in the server. So try to use the `All-Content` header only when it is really needed.

@param opts [Hash] Additional options.

@option opts [Boolean] :filter Indicates if the results should be filtered according to the permissions of the user.

@option opts [Boolean] :next_run Indicates if the returned result describes the virtual machine as it is currently running, or if describes

it with the modifications that have already been performed but that will have effect only when it is
restarted. By default the values is `false`.

If the parameter is included in the request, but without a value, it is assumed that the value is `true`, so
the following request:

[source]
----
GET /vms/{vm:id};next_run
----

Is equivalent to using the value `true`:

[source]
----
GET /vms/{vm:id};next_run=true
----

@return [Vm]

# File lib/ovirtsdk4/services.rb, line 25142
def get(opts = {})
  query = {}
  value = opts[:filter]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['filter'] = value
  end
  value = opts[:next_run]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['next_run'] = 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 VmReader.read_one(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end
graphics_consoles_service() click to toggle source

Locates the `graphics_consoles` service.

@return [GraphicsConsolesService] A reference to `graphics_consoles` service.

# File lib/ovirtsdk4/services.rb, line 25648
def graphics_consoles_service
  return GraphicsConsolesService.new(@connection, "#{@path}/graphicsconsoles")
end
host_devices_service() click to toggle source

Locates the `host_devices` service.

@return [VmHostDevicesService] A reference to `host_devices` service.

# File lib/ovirtsdk4/services.rb, line 25656
def host_devices_service
  return VmHostDevicesService.new(@connection, "#{@path}/hostdevices")
end
katello_errata_service() click to toggle source

Locates the `katello_errata` service.

@return [KatelloErrataService] A reference to `katello_errata` service.

# File lib/ovirtsdk4/services.rb, line 25664
def katello_errata_service
  return KatelloErrataService.new(@connection, "#{@path}/katelloerrata")
end
logon(opts = {}) click to toggle source

Executes the `logon` method.

@param opts [Hash] Additional options.

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

# File lib/ovirtsdk4/services.rb, line 25176
def logon(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}/logon",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
maintenance(opts = {}) click to toggle source

Executes the `maintenance` method.

@param opts [Hash] Additional options.

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

@option opts [Boolean] :maintenance_enabled

# File lib/ovirtsdk4/services.rb, line 25205
def maintenance(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}/maintenance",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
migrate(opts = {}) click to toggle source

Executes the `migrate` method.

@param opts [Hash] Additional options.

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

@option opts [Cluster] :cluster

@option opts [Boolean] :force

@option opts [Host] :host

# File lib/ovirtsdk4/services.rb, line 25238
def migrate(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}/migrate",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
nics_service() click to toggle source

Locates the `nics` service.

@return [VmNicsService] A reference to `nics` service.

# File lib/ovirtsdk4/services.rb, line 25672
def nics_service
  return VmNicsService.new(@connection, "#{@path}/nics")
end
numa_nodes_service() click to toggle source

Locates the `numa_nodes` service.

@return [VmNumaNodesService] A reference to `numa_nodes` service.

# File lib/ovirtsdk4/services.rb, line 25680
def numa_nodes_service
  return VmNumaNodesService.new(@connection, "#{@path}/numanodes")
end
permissions_service() click to toggle source

Locates the `permissions` service.

@return [AssignedPermissionsService] A reference to `permissions` service.

# File lib/ovirtsdk4/services.rb, line 25688
def permissions_service
  return AssignedPermissionsService.new(@connection, "#{@path}/permissions")
end
preview_snapshot(opts = {}) click to toggle source

Executes the `preview_snapshot` method.

@param opts [Hash] Additional options.

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

@option opts [Array<Disk>] :disks

@option opts [Boolean] :restore_memory

@option opts [Snapshot] :snapshot

@option opts [Vm] :vm

# File lib/ovirtsdk4/services.rb, line 25273
def preview_snapshot(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}/previewsnapshot",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
reboot(opts = {}) click to toggle source

Executes the `reboot` method.

@param opts [Hash] Additional options.

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

# File lib/ovirtsdk4/services.rb, line 25300
def reboot(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}/reboot",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
remove(opts = {}) click to toggle source

Deletes the object managed by this service.

@param opts [Hash] Additional options.

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

# File lib/ovirtsdk4/services.rb, line 25326
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
reorder_mac_addresses(opts = {}) click to toggle source

Executes the `reorder_mac_addresses` method.

@param opts [Hash] Additional options.

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

# File lib/ovirtsdk4/services.rb, line 25347
def reorder_mac_addresses(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}/reordermacaddresses",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
reported_devices_service() click to toggle source

Locates the `reported_devices` service.

@return [VmReportedDevicesService] A reference to `reported_devices` service.

# File lib/ovirtsdk4/services.rb, line 25696
def reported_devices_service
  return VmReportedDevicesService.new(@connection, "#{@path}/reporteddevices")
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 25747
def service(path)
  if path.nil? || path == ''
    return self
  end
  if path == 'affinitylabels'
    return affinity_labels_service
  end
  if path.start_with?('affinitylabels/')
    return affinity_labels_service.service(path[15..-1])
  end
  if path == 'applications'
    return applications_service
  end
  if path.start_with?('applications/')
    return applications_service.service(path[13..-1])
  end
  if path == 'cdroms'
    return cdroms_service
  end
  if path.start_with?('cdroms/')
    return cdroms_service.service(path[7..-1])
  end
  if path == 'diskattachments'
    return disk_attachments_service
  end
  if path.start_with?('diskattachments/')
    return disk_attachments_service.service(path[16..-1])
  end
  if path == 'graphicsconsoles'
    return graphics_consoles_service
  end
  if path.start_with?('graphicsconsoles/')
    return graphics_consoles_service.service(path[17..-1])
  end
  if path == 'hostdevices'
    return host_devices_service
  end
  if path.start_with?('hostdevices/')
    return host_devices_service.service(path[12..-1])
  end
  if path == 'katelloerrata'
    return katello_errata_service
  end
  if path.start_with?('katelloerrata/')
    return katello_errata_service.service(path[14..-1])
  end
  if path == 'nics'
    return nics_service
  end
  if path.start_with?('nics/')
    return nics_service.service(path[5..-1])
  end
  if path == 'numanodes'
    return numa_nodes_service
  end
  if path.start_with?('numanodes/')
    return numa_nodes_service.service(path[10..-1])
  end
  if path == 'permissions'
    return permissions_service
  end
  if path.start_with?('permissions/')
    return permissions_service.service(path[12..-1])
  end
  if path == 'reporteddevices'
    return reported_devices_service
  end
  if path.start_with?('reporteddevices/')
    return reported_devices_service.service(path[16..-1])
  end
  if path == 'sessions'
    return sessions_service
  end
  if path.start_with?('sessions/')
    return sessions_service.service(path[9..-1])
  end
  if path == 'snapshots'
    return snapshots_service
  end
  if path.start_with?('snapshots/')
    return snapshots_service.service(path[10..-1])
  end
  if path == 'statistics'
    return statistics_service
  end
  if path.start_with?('statistics/')
    return statistics_service.service(path[11..-1])
  end
  if path == 'tags'
    return tags_service
  end
  if path.start_with?('tags/')
    return tags_service.service(path[5..-1])
  end
  if path == 'watchdogs'
    return watchdogs_service
  end
  if path.start_with?('watchdogs/')
    return watchdogs_service.service(path[10..-1])
  end
  raise Error.new("The path \"#{path}\" doesn't correspond to any service")
end
sessions_service() click to toggle source

Locates the `sessions` service.

@return [VmSessionsService] A reference to `sessions` service.

# File lib/ovirtsdk4/services.rb, line 25704
def sessions_service
  return VmSessionsService.new(@connection, "#{@path}/sessions")
end
shutdown(opts = {}) click to toggle source

Executes the `shutdown` method.

@param opts [Hash] Additional options.

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

# File lib/ovirtsdk4/services.rb, line 25374
def shutdown(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}/shutdown",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
snapshots_service() click to toggle source

Locates the `snapshots` service.

@return [SnapshotsService] A reference to `snapshots` service.

# File lib/ovirtsdk4/services.rb, line 25712
def snapshots_service
  return SnapshotsService.new(@connection, "#{@path}/snapshots")
end
start(opts = {}) click to toggle source

Executes the `start` method.

@param opts [Hash] Additional options.

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

@option opts [Boolean] :filter Indicates if the results should be filtered according to the permissions of the user.

@option opts [Boolean] :pause

@option opts [Boolean] :use_cloud_init

@option opts [Boolean] :use_sysprep

@option opts [Vm] :vm

# File lib/ovirtsdk4/services.rb, line 25411
def start(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}/start",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
statistics_service() click to toggle source

Locates the `statistics` service.

@return [StatisticsService] A reference to `statistics` service.

# File lib/ovirtsdk4/services.rb, line 25720
def statistics_service
  return StatisticsService.new(@connection, "#{@path}/statistics")
end
stop(opts = {}) click to toggle source

Executes the `stop` method.

@param opts [Hash] Additional options.

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

# File lib/ovirtsdk4/services.rb, line 25438
def stop(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}/stop",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
suspend(opts = {}) click to toggle source

Executes the `suspend` method.

@param opts [Hash] Additional options.

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

# File lib/ovirtsdk4/services.rb, line 25465
def suspend(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}/suspend",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
tags_service() click to toggle source

Locates the `tags` service.

@return [AssignedTagsService] A reference to `tags` service.

# File lib/ovirtsdk4/services.rb, line 25728
def tags_service
  return AssignedTagsService.new(@connection, "#{@path}/tags")
end
thaw_filesystems(opts = {}) click to toggle source

Executes the `thaw_filesystems` method.

@param opts [Hash] Additional options.

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

# File lib/ovirtsdk4/services.rb, line 25492
def thaw_filesystems(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}/thawfilesystems",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
ticket(opts = {}) click to toggle source

Executes the `ticket` method.

@param opts [Hash] Additional options.

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

@option opts [Ticket] :ticket

# File lib/ovirtsdk4/services.rb, line 25521
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 25855
def to_s
  return "#<#{VmService}:#{@path}>"
end
undo_snapshot(opts = {}) click to toggle source

Executes the `undo_snapshot` method.

@param opts [Hash] Additional options.

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

# File lib/ovirtsdk4/services.rb, line 25549
def undo_snapshot(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}/undosnapshot",
    :body => body,
  )
  response = @connection.send(request)
  case response.code
  when 200
    action = check_action(response)
  else
    check_action(response)
  end
end
update(vm, opts = {}) click to toggle source

Updates the `vm`.

@param vm [Vm] The `vm` to update. @param opts [Hash] Additional options.

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

@return [Vm]

# File lib/ovirtsdk4/services.rb, line 25579
def update(vm, opts = {})
  if vm.is_a?(Hash)
    vm = OvirtSDK4::Vm.new(vm)
  end
  query = {}
  value = opts[:async]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['async'] = value
  end
  request = HttpRequest.new(:method => :PUT, :url => @path, :query => query)
  begin
    writer = XmlWriter.new(nil, true)
    VmWriter.write_one(vm, writer)
    request.body = writer.string
  ensure
    writer.close
  end
  response = @connection.send(request)
  case response.code
  when 200
    begin
      reader = XmlReader.new(response.body)
      return VmReader.read_one(reader)
    ensure
      reader.close
    end
    return result
  else
    check_fault(response)
  end
end
watchdogs_service() click to toggle source

Locates the `watchdogs` service.

@return [VmWatchdogsService] A reference to `watchdogs` service.

# File lib/ovirtsdk4/services.rb, line 25736
def watchdogs_service
  return VmWatchdogsService.new(@connection, "#{@path}/watchdogs")
end