Class: OvirtSDK4::ExternalHostProvidersService

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

Instance Method Summary (collapse)

Instance Method Details

- (ExternalHostProvider) add(provider, opts = {})

Adds a new provider.

Parameters:

Returns:



7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
# File 'lib/ovirtsdk4/services.rb', line 7339

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

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

Returns:



7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
# File 'lib/ovirtsdk4/services.rb', line 7374

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

- (ExternalHostProviderService) provider_service(id)

Locates the provider service.

Parameters:

  • id (String)

    The identifier of the provider.

Returns:



7403
7404
7405
# File 'lib/ovirtsdk4/services.rb', line 7403

def provider_service(id)
  return ExternalHostProviderService.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.



7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
# File 'lib/ovirtsdk4/services.rb', line 7414

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


7430
7431
7432
# File 'lib/ovirtsdk4/services.rb', line 7430

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