Class: OvirtSDK4::VmDisksService

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

Instance Method Summary (collapse)

Instance Method Details

- (Disk) add(disk, opts = {})

Adds a new disk.

Parameters:

Returns:



24851
24852
24853
24854
24855
24856
24857
24858
24859
24860
24861
24862
24863
24864
24865
24866
24867
24868
24869
24870
24871
24872
24873
24874
24875
# File 'lib/ovirtsdk4/services.rb', line 24851

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

- (VmDiskService) disk_service(id)

Locates the disk service.

Parameters:

  • id (String)

    The identifier of the disk.

Returns:



24915
24916
24917
# File 'lib/ovirtsdk4/services.rb', line 24915

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

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

Returns:



24886
24887
24888
24889
24890
24891
24892
24893
24894
24895
24896
24897
24898
24899
24900
24901
24902
24903
24904
24905
24906
# File 'lib/ovirtsdk4/services.rb', line 24886

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



24926
24927
24928
24929
24930
24931
24932
24933
24934
24935
# File 'lib/ovirtsdk4/services.rb', line 24926

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

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


24942
24943
24944
# File 'lib/ovirtsdk4/services.rb', line 24942

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