Class: OvirtSDK4::DiskAttachmentService

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

Instance Method Summary (collapse)

Instance Method Details

- (DiskAttachment) get(opts = {})

Returns the details of the attachment, including the bootable flag and link to the disk.

Parameters:

  • opts (Hash) (defaults to: {})

    Additional options.

Returns:



5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
# File 'lib/ovirtsdk4/services.rb', line 5230

def get(opts = {})
  query = {}
  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 DiskAttachmentReader.read_one(reader)
    ensure
      reader.close
    end
  else
    check_fault(response)
  end
end

- (Object) remove(opts = {})

Removes the disk attachment. This will only detach the disk from the virtual machine, but won’t remove it from the system, unless the detach_only parameter is false.

Parameters:

  • opts (Hash) (defaults to: {})

    Additional options.

Options Hash (opts):

  • :detach_only (Boolean)

    Indicates if the disk should only be detached from the virtual machine, but not removed from the system. The default value is true, which won’t remove the disk from the system.



5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
# File 'lib/ovirtsdk4/services.rb', line 5256

def remove(opts = {})
  query = {}
  value = opts[:detach_only]
  unless value.nil?
    value = Writer.render_boolean(value)
    query['detach_only'] = value
  end
  request = Request.new(:method => :DELETE, :path => @path, :query => query)
  response = @connection.send(request)
  unless response.code == 200
    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.

Raises:

  • (Error)


5321
5322
5323
5324
5325
5326
# File 'lib/ovirtsdk4/services.rb', line 5321

def service(path)
  if path.nil? || path == ''
    return self
  end
  raise Error.new("The path \"#{path}\" doesn't correspond to any service")
end

- (String) to_s

Returns an string representation of this service.

Returns:

  • (String)


5333
5334
5335
# File 'lib/ovirtsdk4/services.rb', line 5333

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

- (Object) update(disk_attachment)

Update the disk attachment and the disk properties within it.

PUT /vms/{vm:id}/disksattachments/{attachment:id}
<disk_attachment>
  <bootable>true</bootable>
  <interface>ide</interface>
  <disk>
    <name>mydisk</name>
    <provisioned_size>1024</provisioned_size>
    ...
  </disk>
</disk_attachment>


5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
# File 'lib/ovirtsdk4/services.rb', line 5287

def update(disk_attachment)
  if disk_attachment.is_a?(Hash)
    disk_attachment = OvirtSDK4::DiskAttachment.new(disk_attachment)
  end
  request = Request.new(:method => :PUT, :path => @path)
  begin
    writer = XmlWriter.new(nil, true)
    DiskAttachmentWriter.write_one(disk_attachment, writer, 'disk_attachment')
    request.body = writer.string
  ensure
    writer.close
  end
  response = @connection.send(request)
  case response.code
  when 200
    begin
      reader = XmlReader.new(response.body)
      return DiskAttachmentReader.read_one(reader)
    ensure
      reader.close
    end
    return result
  else
    check_fault(response)
  end
end