Class: OvirtSDK4::VmNicsService

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

Instance Method Summary (collapse)

Instance Method Details

- (Nic) add(nic, opts = {})

Adds a new nic.

Parameters:

Returns:



25477
25478
25479
25480
25481
25482
25483
25484
25485
25486
25487
25488
25489
25490
25491
25492
25493
25494
25495
25496
25497
25498
25499
25500
25501
# File 'lib/ovirtsdk4/services.rb', line 25477

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

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

Returns:



25512
25513
25514
25515
25516
25517
25518
25519
25520
25521
25522
25523
25524
25525
25526
25527
25528
25529
25530
25531
25532
# File 'lib/ovirtsdk4/services.rb', line 25512

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

- (VmNicService) nic_service(id)

Locates the nic service.

Parameters:

  • id (String)

    The identifier of the nic.

Returns:



25541
25542
25543
# File 'lib/ovirtsdk4/services.rb', line 25541

def nic_service(id)
  return VmNicService.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.



25552
25553
25554
25555
25556
25557
25558
25559
25560
25561
# File 'lib/ovirtsdk4/services.rb', line 25552

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


25568
25569
25570
# File 'lib/ovirtsdk4/services.rb', line 25568

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