Class: OvirtSDK4::AssignedCpuProfilesService

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:



2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
# File 'lib/ovirtsdk4/services.rb', line 2111

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:



2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
# File 'lib/ovirtsdk4/services.rb', line 2146

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

- (AssignedCpuProfileService) profile_service(id)

Locates the profile service.

Parameters:

  • id (String)

    The identifier of the profile.

Returns:



2175
2176
2177
# File 'lib/ovirtsdk4/services.rb', line 2175

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



2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
# File 'lib/ovirtsdk4/services.rb', line 2186

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)


2202
2203
2204
# File 'lib/ovirtsdk4/services.rb', line 2202

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