Class: OvirtSDK4::WeightsService

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

Instance Method Summary (collapse)

Instance Method Details

- (Weight) add(weight, opts = {})

Adds a new weight.

Parameters:

Returns:



27323
27324
27325
27326
27327
27328
27329
27330
27331
27332
27333
27334
27335
27336
27337
27338
27339
27340
27341
27342
27343
27344
27345
27346
27347
# File 'lib/ovirtsdk4/services.rb', line 27323

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

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

Returns the representation of the object managed by this service.

Parameters:

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

    Additional options.

Options Hash (opts):

  • :filter (Boolean)

    Indicates if the results should be filtered according to the permissions of the user.

  • :max (Integer)

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

Returns:



27360
27361
27362
27363
27364
27365
27366
27367
27368
27369
27370
27371
27372
27373
27374
27375
27376
27377
27378
27379
27380
27381
27382
27383
27384
27385
# File 'lib/ovirtsdk4/services.rb', line 27360

def list(opts = {})
  query = {}
  value = opts[:filter]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['filter'] = value
  end
  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 WeightReader.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.



27405
27406
27407
27408
27409
27410
27411
27412
27413
27414
# File 'lib/ovirtsdk4/services.rb', line 27405

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


27421
27422
27423
# File 'lib/ovirtsdk4/services.rb', line 27421

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

- (WeightService) weight_service(id)

Locates the weight service.

Parameters:

  • id (String)

    The identifier of the weight.

Returns:



27394
27395
27396
# File 'lib/ovirtsdk4/services.rb', line 27394

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