class OvirtSDK4::DiskAttachmentsService

Public Class Methods

new(connection, path) click to toggle source

Creates a new implementation of the service.

@param connection [Connection] The connection to be used by this service.

@param path [String] The relative path of this service, for example `vms/123/disks`.

@api private

# File lib/ovirtsdk4/services.rb, line 5528
def initialize(connection, path)
  @connection = connection
  @path = path
end

Public Instance Methods

add(attachment, opts = {}) click to toggle source

Adds a new disk attachment to the virtual machine. The `attachment` parameter can contain just a reference, if the disk already exists:

source,xml

<disk_attachment>

<bootable>true</bootable>
<interface>ide</interface>
<disk id="123"/>

</disk_attachment>


Or it can contain the complete representation of the disk, if the disk doesn't exist yet:

source,xml

<disk_attachment>

<bootable>true</bootable>
<interface>ide</interface>
<disk>
  <name>mydisk</name>
  <provisioned_size>1024</provisioned_size>
  ...
</disk>

</disk_attachment>


In this case the disk will be created and then attached to the virtual machine.

@param attachment [DiskAttachment] The `attachment` to add.

@param opts [Hash] Additional options.

@return [DiskAttachment]

# File lib/ovirtsdk4/services.rb, line 5569
def add(attachment, opts = {})
  if attachment.is_a?(Hash)
    attachment = OvirtSDK4::DiskAttachment.new(attachment)
  end
  query = {}
  request = HttpRequest.new(:method => :POST, :url => @path, :query => query)
  begin
    writer = XmlWriter.new(nil, true)
    DiskAttachmentWriter.write_one(attachment, writer)
    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 DiskAttachmentReader.read_one(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end
attachment_service(id) click to toggle source

Reference to the service that manages a specific attachment.

@param id [String] The identifier of the `attachment`.

@return [DiskAttachmentService] A reference to the `attachment` service.

# File lib/ovirtsdk4/services.rb, line 5627
def attachment_service(id)
  return DiskAttachmentService.new(@connection, "#{@path}/#{id}")
end
list(opts = {}) click to toggle source

List the disk that are attached to the virtual machine.

@param opts [Hash] Additional options.

@return [Array<DiskAttachment>]

# File lib/ovirtsdk4/services.rb, line 5603
def list(opts = {})
  query = {}
  request = HttpRequest.new(:method => :GET, :url => @path, :query => query)
  response = @connection.send(request)
  case response.code
  when 200
    begin
      reader = XmlReader.new(response.body)
      return DiskAttachmentReader.read_many(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end
service(path) click to toggle source

Locates the service corresponding to the given path.

@param path [String] The path of the service.

@return [Service] A reference to the service.

# File lib/ovirtsdk4/services.rb, line 5638
def service(path)
  if path.nil? || path == ''
    return self
  end
  index = path.index('/')
  if index.nil?
    return attachment_service(path)
  end
  return attachment_service(path[0..(index - 1)]).service(path[(index +1)..-1])
end
to_s() click to toggle source

Returns an string representation of this service.

@return [String]

# File lib/ovirtsdk4/services.rb, line 5654
def to_s
  return "#<#{DiskAttachmentsService}:#{@path}>"
end