Class: OvirtSDK4::AffinityLabelHostsService

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

Instance Method Summary (collapse)

Instance Method Details

- (Host) add(host, opts = {})

Add a label to a host.

Parameters:

Returns:



1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
# File 'lib/ovirtsdk4/services.rb', line 1404

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

- (AffinityLabelHostService) host_service(id)

A link to the specific label-host assignment to allow label removal.

Parameters:

  • id (String)

    The identifier of the host.

Returns:



1462
1463
1464
# File 'lib/ovirtsdk4/services.rb', line 1462

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

- (Array<Host>) list(opts = {})

List all hosts with the label.

Parameters:

  • opts (Hash) (defaults to: {})

    Additional options.

Returns:



1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
# File 'lib/ovirtsdk4/services.rb', line 1437

def list(opts = {})
  query = {}
  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 HostReader.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.



1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
# File 'lib/ovirtsdk4/services.rb', line 1473

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


1489
1490
1491
# File 'lib/ovirtsdk4/services.rb', line 1489

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