Class: OvirtSDK4::BalancesService

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

Instance Method Summary (collapse)

Instance Method Details

- (Balance) add(balance, opts = {})

Adds a new balance.

Parameters:

Returns:



3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
# File 'lib/ovirtsdk4/services.rb', line 3659

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

- (BalanceService) balance_service(id)

Locates the balance service.

Parameters:

  • id (String)

    The identifier of the balance.

Returns:



3730
3731
3732
# File 'lib/ovirtsdk4/services.rb', line 3730

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

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

Returns:



3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
# File 'lib/ovirtsdk4/services.rb', line 3696

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



3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
# File 'lib/ovirtsdk4/services.rb', line 3741

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


3757
3758
3759
# File 'lib/ovirtsdk4/services.rb', line 3757

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