Class: OvirtSDK4::TagsService

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

Instance Method Summary (collapse)

Instance Method Details

- (Tag) add(tag, opts = {})

Adds a new tag.

Parameters:

Returns:



21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
# File 'lib/ovirtsdk4/services.rb', line 21360

def add(tag, opts = {})
  if tag.is_a?(Hash)
    tag = OvirtSDK4::Tag.new(tag)
  end
  request = Request.new(:method => :POST, :path => @path)
  begin
    writer = XmlWriter.new(nil, true)
    TagWriter.write_one(tag, writer, 'tag')
    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 TagReader.read_one(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end

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

Returns the representation of the object managed by this service.

Parameters:

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

    Additional options.

Options Hash (opts):

  • :max (Integer)

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

Returns:



21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
# File 'lib/ovirtsdk4/services.rb', line 21395

def list(opts = {})
  query = {}
  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 TagReader.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.



21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
# File 'lib/ovirtsdk4/services.rb', line 21435

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

- (TagService) tag_service(id)

Locates the tag service.

Parameters:

  • id (String)

    The identifier of the tag.

Returns:

  • (TagService)

    A reference to the tag service.



21424
21425
21426
# File 'lib/ovirtsdk4/services.rb', line 21424

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


21451
21452
21453
# File 'lib/ovirtsdk4/services.rb', line 21451

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