Class: OvirtSDK4::InstanceTypeNicsService

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:



10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
# File 'lib/ovirtsdk4/services.rb', line 10858

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:



10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
# File 'lib/ovirtsdk4/services.rb', line 10893

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

- (InstanceTypeNicService) nic_service(id)

Locates the nic service.

Parameters:

  • id (String)

    The identifier of the nic.

Returns:



10922
10923
10924
# File 'lib/ovirtsdk4/services.rb', line 10922

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



10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
# File 'lib/ovirtsdk4/services.rb', line 10933

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)


10949
10950
10951
# File 'lib/ovirtsdk4/services.rb', line 10949

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