Class: OvirtSDK4::QuotasService

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

Instance Method Summary (collapse)

Instance Method Details

- (Quota) add(quota, opts = {})

Adds a new quota.

Parameters:

Returns:



16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
# File 'lib/ovirtsdk4/services.rb', line 16385

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

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

Returns:



16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
# File 'lib/ovirtsdk4/services.rb', line 16420

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 QuotaReader.read_many(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end

- (QuotaService) quota_service(id)

Locates the quota service.

Parameters:

  • id (String)

    The identifier of the quota.

Returns:



16449
16450
16451
# File 'lib/ovirtsdk4/services.rb', line 16449

def quota_service(id)
  return QuotaService.new(@connection, "#{@path}/#{id}")
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.



16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
# File 'lib/ovirtsdk4/services.rb', line 16460

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


16476
16477
16478
# File 'lib/ovirtsdk4/services.rb', line 16476

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