Class: OvirtSDK4::CpuProfilesService

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

Instance Method Summary (collapse)

Instance Method Details

- (CpuProfile) add(profile, opts = {})

Adds a new profile.

Parameters:

Returns:



4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
# File 'lib/ovirtsdk4/services.rb', line 4747

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

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

Returns:



4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
# File 'lib/ovirtsdk4/services.rb', line 4782

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

- (CpuProfileService) profile_service(id)

Locates the profile service.

Parameters:

  • id (String)

    The identifier of the profile.

Returns:



4811
4812
4813
# File 'lib/ovirtsdk4/services.rb', line 4811

def profile_service(id)
  return CpuProfileService.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.



4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
# File 'lib/ovirtsdk4/services.rb', line 4822

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


4838
4839
4840
# File 'lib/ovirtsdk4/services.rb', line 4838

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