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.
When creating a new floating <<types/disk,Disk>>, the API requires the `storage_domain`, `provisioned_size` and `format` attributes.
To create a new floating disk with specified `provisioned_size`, `format` and `name` on a storage domain with an id `e9fedf39-5edc-4e0a-8628-253f1b9c5693`, send a request as follows:
POST /ovirt-engine/api/disks
With a request body as follows:
<disk>
<storage_domains> <storage_domain id="e9fedf39-5edc-4e0a-8628-253f1b9c5693"/> </storage_domains> <name>disk1</name> <provisioned_size>1048576</provisioned_size> <format>cow</format>
</disk>
@param disk [Disk] The disk.
@param opts [Hash] Additional options.
@return [Disk]
# File lib/ovirtsdk4/services.rb, line 6841 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 6951 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 6913 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 6962 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 6978 def to_s "#<#{DisksService}:#{@path}>" end