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 6802 def initialize(connection, path) @connection = connection @path = path end
Adds a new floating disk.
There are three types of disks that can be added - disk image, direct LUN and
https://wiki.openstack.org/wiki/Cinder[Cinder] disk.
*Adding a new image disk:*
When creating a new floating image <<types/disk,Disk>>, the API requires the `storage_domain`, `provisioned_size` and `format` attributes.
To create a new floating image disk with specified `provisioned_size`, `format` and `name` on a storage domain with an id `123`, send a request as follows:
POST /ovirt-engine/api/disks
With a request body as follows:
<disk>
<storage_domains> <storage_domain id="123"/> </storage_domains> <name>mydisk</name> <provisioned_size>1048576</provisioned_size> <format>cow</format>
</disk>
*Adding a new direct LUN disk:*
When adding a new floating direct LUN via the API, there are two flavors that can be used:
. With a `host` element - in this case, the host is used for sanity checks (e.g., that the LUN is visible) and to retrieve basic information about the LUN (e.g., size and serial). . Without a `host` element - in this case, the operation is a database-only operation, and the storage is never accessed.
To create a new floating direct LUN disk with a `host` element with an id `123`, specified `alias`, `type` and `logical_unit` with an id `456` (that has the attributes `address`, `port` and `target`), send a request as follows:
POST /ovirt-engine/api/disks
With a request body as follows:
<disk>
<alias>mylun</alias> <lun_storage> <host id="123"/> <type>iscsi</type> <logical_units> <logical_unit id="456"> <address>10.35.10.20</address> <port>3260</port> <target>iqn.2017-01.com.myhost:444</target> </logical_unit> </logical_units> </lun_storage>
</disk>
To create a new floating direct LUN disk without using a host, remove the `host` element.
*Adding a new Cinder disk:*
To create a new floating Cinder disk, send a request as follows:
POST /ovirt-engine/api/disks
With a request body as follows:
<disk>
<openstack_volume_type> <name>myceph</name> </openstack_volume_type> <storage_domains> <storage_domain> <name>cinderDomain</name> </storage_domain> </storage_domains> <provisioned_size>1073741824</provisioned_size> <interface>virtio</interface> <format>raw</format>
</disk>
@param disk [Disk] The disk.
@param opts [Hash] Additional options.
@return [Disk]
# File lib/ovirtsdk4/services.rb, line 6916 def add(disk, opts = {}) if disk.is_a?(Hash) disk = OvirtSDK4::Disk.new(disk) end query = {} request = HttpRequest.new(method: :POST, url: @path, query: query) begin writer = XmlWriter.new(nil, true) DiskWriter.write_one(disk, writer) request.body = writer.string ensure writer.close end response = @connection.send(request) case response.code when 200, 201, 202 begin reader = XmlReader.new(response.body) return DiskReader.read_one(reader) ensure reader.close end else check_fault(response) end end
Reference to a service managing a specific disk.
@param id [String] The identifier of the `disk`.
@return [DiskService] A reference to the `disk` service.
# File lib/ovirtsdk4/services.rb, line 7026 def disk_service(id) DiskService.new(@connection, "#{@path}/#{id}") end
Get list of disks.
GET /ovirt-engine/api/disks
You will get a XML response which will look like this one:
<disks>
<disk id="123"> <actions>...</actions> <name>MyDisk</name> <description>MyDisk description</description> <link href="/ovirt-engine/api/disks/123/permissions" rel="permissions"/> <link href="/ovirt-engine/api/disks/123/statistics" rel="statistics"/> <actual_size>5345845248</actual_size> <alias>MyDisk alias</alias> ... <status>ok</status> <storage_type>image</storage_type> <wipe_after_delete>false</wipe_after_delete> <disk_profile id="123"/> <quota id="123"/> <storage_domains>...</storage_domains> </disk> ...
</disks>
@param opts [Hash] Additional options.
@option opts [Boolean] :case_sensitive Indicates if the search performed using the `search` parameter should be performed taking case into
account. The default value is `true`, which means that case is taken into account. If you want to search ignoring case set it to `false`.
@option opts [Integer] :max Sets the maximum number of disks to return. If not specified all the disks are returned.
@option opts [String] :search A query string used to restrict the returned disks.
@return [Array<Disk>]
# File lib/ovirtsdk4/services.rb, line 6988 def list(opts = {}) query = {} value = opts[:case_sensitive] unless value.nil? value = Writer.render_boolean(value) query['case_sensitive'] = value end value = opts[:max] unless value.nil? value = Writer.render_integer(value) query['max'] = value end value = opts[:search] unless value.nil? query['search'] = value end 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 DiskReader.read_many(reader) ensure reader.close end else check_fault(response) end end
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 7037 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
Returns an string representation of this service.
@return [String]
# File lib/ovirtsdk4/services.rb, line 7053 def to_s "#<#{DisksService}:#{@path}>" end