Class: OvirtSDK4::AssignedAffinityLabelsService

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

Instance Method Summary (collapse)

Instance Method Details

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

Attaches a label to an entity.

Parameters:

Returns:



1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
# File 'lib/ovirtsdk4/services.rb', line 1911

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

- (AssignedAffinityLabelService) label_service(id)

Link to the specific entity-label assignment to allow removal.

Parameters:

  • id (String)

    The identifier of the label.

Returns:



1969
1970
1971
# File 'lib/ovirtsdk4/services.rb', line 1969

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

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

Lists all labels that are attached to an entity.

Parameters:

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

    Additional options.

Returns:



1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
# File 'lib/ovirtsdk4/services.rb', line 1944

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



1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
# File 'lib/ovirtsdk4/services.rb', line 1980

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)


1996
1997
1998
# File 'lib/ovirtsdk4/services.rb', line 1996

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