Class: OvirtSDK4::VmHostDevicesService

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

Instance Method Summary (collapse)

Instance Method Details

- (HostDevice) add(device, opts = {})

Adds a new device.

Parameters:

Returns:



25167
25168
25169
25170
25171
25172
25173
25174
25175
25176
25177
25178
25179
25180
25181
25182
25183
25184
25185
25186
25187
25188
25189
25190
25191
# File 'lib/ovirtsdk4/services.rb', line 25167

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

- (VmHostDeviceService) device_service(id)

Locates the device service.

Parameters:

  • id (String)

    The identifier of the device.

Returns:



25231
25232
25233
# File 'lib/ovirtsdk4/services.rb', line 25231

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

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

Returns:



25202
25203
25204
25205
25206
25207
25208
25209
25210
25211
25212
25213
25214
25215
25216
25217
25218
25219
25220
25221
25222
# File 'lib/ovirtsdk4/services.rb', line 25202

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 HostDeviceReader.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.



25242
25243
25244
25245
25246
25247
25248
25249
25250
25251
# File 'lib/ovirtsdk4/services.rb', line 25242

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


25258
25259
25260
# File 'lib/ovirtsdk4/services.rb', line 25258

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