Class: OvirtSDK4::VmCdromsService

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

Instance Method Summary (collapse)

Instance Method Details

- (Cdrom) add(cdrom, opts = {})

Adds a new cdrom.

Parameters:

Returns:



24491
24492
24493
24494
24495
24496
24497
24498
24499
24500
24501
24502
24503
24504
24505
24506
24507
24508
24509
24510
24511
24512
24513
24514
24515
# File 'lib/ovirtsdk4/services.rb', line 24491

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

- (VmCdromService) cdrom_service(id)

Locates the cdrom service.

Parameters:

  • id (String)

    The identifier of the cdrom.

Returns:



24555
24556
24557
# File 'lib/ovirtsdk4/services.rb', line 24555

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

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

Returns:



24526
24527
24528
24529
24530
24531
24532
24533
24534
24535
24536
24537
24538
24539
24540
24541
24542
24543
24544
24545
24546
# File 'lib/ovirtsdk4/services.rb', line 24526

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



24566
24567
24568
24569
24570
24571
24572
24573
24574
24575
# File 'lib/ovirtsdk4/services.rb', line 24566

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


24582
24583
24584
# File 'lib/ovirtsdk4/services.rb', line 24582

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