class OvirtSDK4::VmPoolsService

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

Public Instance Methods

add(pool, opts = {}) click to toggle source

Creates a new virtual machine pool.

A new pool requires the `name`, `cluster` and `template` attributes. Identify the cluster and template with the `id` or `name` nested attributes:

source

POST /ovirt-engine/api/vmpools


With the following body:

source,xml

<vmpool>

<name>mypool</name>
<cluster id="123"/>
<template id="456"/>

</vmpool>


@param pool [VmPool] Pool to add.

@param opts [Hash] Additional options.

@return [VmPool]

# File lib/ovirtsdk4/services.rb, line 32482
def add(pool, opts = {})
  if pool.is_a?(Hash)
    pool = OvirtSDK4::VmPool.new(pool)
  end
  query = {}
  request = HttpRequest.new(method: :POST, url: @path, query: query)
  begin
    writer = XmlWriter.new(nil, true)
    VmPoolWriter.write_one(pool, writer)
    request.body = writer.string
  ensure
    writer.close
  end
  response = @connection.send(request)
  case response.code
  when 200, 201, 202
    begin
      reader = XmlReader.new(response.body)
      return VmPoolReader.read_one(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end
list(opts = {}) click to toggle source

Get a list of available virtual machines pools.

source

GET /ovirt-engine/api/vmpools


You will receive the following response:

source,xml

<vm_pools>

<vm_pool id="123">
  ...
</vm_pool>
...

</vm_pools>


@param opts [Hash] Additional options.

@option opts [Boolean] :case_sensitive Indicates if the search performed using the `search` parameter should be performed taking case into

account. The default value is `true`, which means that case is taken into account. If you want to search
ignoring case set it to `false`.

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

@option opts [Integer] :max Sets the maximum number of pools to return. If this value is not specified, all of the pools are returned.

@option opts [String] :search A query string used to restrict the returned pools.

@return [Array<VmPool>]

# File lib/ovirtsdk4/services.rb, line 32543
def list(opts = {})
  query = {}
  value = opts[:case_sensitive]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['case_sensitive'] = value
  end
  value = opts[:filter]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['filter'] = value
  end
  value = opts[:max]
  unless value.nil?
    value = Writer.render_integer(value)
    query['max'] = value
  end
  value = opts[:search]
  unless value.nil?
    query['search'] = 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 VmPoolReader.read_many(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end
pool_service(id) click to toggle source

Reference to the service that manages a specific virtual machine pool.

@param id [String] The identifier of the `pool`.

@return [VmPoolService] A reference to the `pool` service.

# File lib/ovirtsdk4/services.rb, line 32586
def pool_service(id)
  VmPoolService.new(@connection, "#{@path}/#{id}")
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 32597
def service(path)
  if path.nil? || path == ''
    return self
  end
  index = path.index('/')
  if index.nil?
    return pool_service(path)
  end
  return pool_service(path[0..(index - 1)]).service(path[(index +1)..-1])
end
to_s() click to toggle source

Returns an string representation of this service.

@return [String]

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