Class: OvirtSDK4::FiltersService

Inherits:
Service
  • Object
show all
Defined in:
lib/ovirtsdk4/services.rb,
lib/ovirtsdk4/services.rb

Instance Method Summary (collapse)

Instance Method Details

- (Filter) add(filter, opts = {})

Adds a new filter.

Parameters:

Returns:



8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
# File 'lib/ovirtsdk4/services.rb', line 8295

def add(filter, opts = {})
  if filter.is_a?(Hash)
    filter = OvirtSDK4::Filter.new(filter)
  end
  request = Request.new(:method => :POST, :path => @path)
  begin
    writer = XmlWriter.new(nil, true)
    FilterWriter.write_one(filter, writer, 'filter')
    request.body = writer.string
  ensure
    writer.close
  end
  response = @connection.send(request)
  case response.code
  when 201, 202
    begin
      reader = XmlReader.new(response.body)
      return FilterReader.read_one(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end

- (FilterService) filter_service(id)

Locates the filter service.

Parameters:

  • id (String)

    The identifier of the filter.

Returns:



8366
8367
8368
# File 'lib/ovirtsdk4/services.rb', line 8366

def filter_service(id)
  return FilterService.new(@connection, "#{@path}/#{id}")
end

- (Array<Filter>) list(opts = {})

Returns the representation of the object managed by this service.

Parameters:

  • opts (Hash) (defaults to: {})

    Additional options.

Options Hash (opts):

  • :filter (Boolean)

    Indicates if the results should be filtered according to the permissions of the user.

  • :max (Integer)

    Sets the maximum number of filters to return. If not specified all the filters are returned.

Returns:



8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
# File 'lib/ovirtsdk4/services.rb', line 8332

def list(opts = {})
  query = {}
  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
  request = Request.new(:method => :GET, :path => @path, :query => query)
  response = @connection.send(request)
  case response.code
  when 200
    begin
      reader = XmlReader.new(response.body)
      return FilterReader.read_many(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end

- (Service) service(path)

Locates the service corresponding to the given path.

Parameters:

  • path (String)

    The path of the service.

Returns:

  • (Service)

    A reference to the service.



8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
# File 'lib/ovirtsdk4/services.rb', line 8377

def service(path)
  if path.nil? || path == ''
    return self
  end
  index = path.index('/')
  if index.nil?
    return filter_service(path)
  end
  return filter_service(path[0..(index - 1)]).service(path[(index +1)..-1])
end

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


8393
8394
8395
# File 'lib/ovirtsdk4/services.rb', line 8393

def to_s
  return "#<#{FiltersService}:#{@path}>"
end