Class: OvirtSDK4::LabelsService

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

Instance Method Summary (collapse)

Instance Method Details

- (Label) add(label, opts = {})

Adds a new label.

Parameters:

Returns:



10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
# File 'lib/ovirtsdk4/services.rb', line 10787

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

- (LabelService) label_service(id)

Locates the label service.

Parameters:

  • id (String)

    The identifier of the label.

Returns:



10851
10852
10853
# File 'lib/ovirtsdk4/services.rb', line 10851

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

- (Array<Label>) 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 labels to return. If not specified all the labels are returned.

Returns:



10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
# File 'lib/ovirtsdk4/services.rb', line 10822

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 LabelReader.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.



10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
# File 'lib/ovirtsdk4/services.rb', line 10862

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


10878
10879
10880
# File 'lib/ovirtsdk4/services.rb', line 10878

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