Class: OvirtSDK4::InstanceTypesService

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

Instance Method Summary (collapse)

Instance Method Details

- (InstanceType) add(instance_type, opts = {})

Adds a new instance_type.

Parameters:

Returns:



11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
# File 'lib/ovirtsdk4/services.rb', line 11214

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

- (InstanceTypeService) instance_type_service(id)

Locates the instance_type service.

Parameters:

  • id (String)

    The identifier of the instance_type.

Returns:



11278
11279
11280
# File 'lib/ovirtsdk4/services.rb', line 11278

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

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

Returns:



11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
# File 'lib/ovirtsdk4/services.rb', line 11249

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



11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
# File 'lib/ovirtsdk4/services.rb', line 11289

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


11305
11306
11307
# File 'lib/ovirtsdk4/services.rb', line 11305

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