Class: OvirtSDK4::AssignedTagsService

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:



2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
# File 'lib/ovirtsdk4/services.rb', line 2960

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:



2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
# File 'lib/ovirtsdk4/services.rb', line 2995

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.



3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
# File 'lib/ovirtsdk4/services.rb', line 3035

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

- (AssignedTagService) tag_service(id)

Locates the tag service.

Parameters:

  • id (String)

    The identifier of the tag.

Returns:



3024
3025
3026
# File 'lib/ovirtsdk4/services.rb', line 3024

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


3051
3052
3053
# File 'lib/ovirtsdk4/services.rb', line 3051

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