Class: OvirtSDK4::TemplateNicsService

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:



22211
22212
22213
22214
22215
22216
22217
22218
22219
22220
22221
22222
22223
22224
22225
22226
22227
22228
22229
22230
22231
22232
22233
22234
22235
# File 'lib/ovirtsdk4/services.rb', line 22211

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:



22246
22247
22248
22249
22250
22251
22252
22253
22254
22255
22256
22257
22258
22259
22260
22261
22262
22263
22264
22265
22266
# File 'lib/ovirtsdk4/services.rb', line 22246

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

- (TemplateNicService) nic_service(id)

Locates the nic service.

Parameters:

  • id (String)

    The identifier of the nic.

Returns:



22275
22276
22277
# File 'lib/ovirtsdk4/services.rb', line 22275

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



22286
22287
22288
22289
22290
22291
22292
22293
22294
22295
# File 'lib/ovirtsdk4/services.rb', line 22286

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)


22302
22303
22304
# File 'lib/ovirtsdk4/services.rb', line 22302

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