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 26143 def initialize(connection, path) @connection = connection @path = path end
Returns a reference to the service that manages the CDROMs that are associated with the template.
@return [TemplateCdromsService] A reference to `cdroms` service.
# File lib/ovirtsdk4/services.rb, line 26364 def cdroms_service TemplateCdromsService.new(@connection, "#{@path}/cdroms") end
Reference to the service that manages a specific disk attachment of the template.
@return [TemplateDiskAttachmentsService] A reference to `disk_attachments` service.
# File lib/ovirtsdk4/services.rb, line 26374 def disk_attachments_service TemplateDiskAttachmentsService.new(@connection, "#{@path}/diskattachments") end
Exports a template to the data center export domain.
For example, the operation can be facilitated using the following request:
POST /ovirt-engine/api/templates/123/export
With a request body like this:
<action>
<storage_domain id="456"/> <exclusive>true<exclusive/>
</action>
@param opts [Hash] Additional options.
@option opts [Boolean] :exclusive Indicates if the existing templates with the same name should be overwritten.
The export action reports a failed action if a template of the same name exists in the destination domain. Set this parameter to `true` to change this behavior and overwrite any existing template.
@option opts [StorageDomain] :storage_domain Specifies the destination export storage domain.
# File lib/ovirtsdk4/services.rb, line 26177 def export(opts = {}) action = Action.new(opts) writer = XmlWriter.new(nil, true) ActionWriter.write_one(action, writer) body = writer.string writer.close request = HttpRequest.new( method: :POST, url: "#{@path}/export", body: body ) response = @connection.send(request) case response.code when 200 action = check_action(response) else check_action(response) end end
Returns the information about this template or template version.
@param opts [Hash] Additional options.
@option opts [Boolean] :filter Indicates if the results should be filtered according to the permissions of the user.
@return [Template]
# File lib/ovirtsdk4/services.rb, line 26206 def get(opts = {}) query = {} value = opts[:filter] unless value.nil? value = Writer.render_boolean(value) query['filter'] = 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 TemplateReader.read_one(reader) ensure reader.close end else check_fault(response) end end
Returns a reference to the service that manages the graphical consoles that are associated with the template.
@return [TemplateGraphicsConsolesService] A reference to `graphics_consoles` service.
# File lib/ovirtsdk4/services.rb, line 26383 def graphics_consoles_service TemplateGraphicsConsolesService.new(@connection, "#{@path}/graphicsconsoles") end
Returns a reference to the service that manages the NICs that are associated with the template.
@return [TemplateNicsService] A reference to `nics` service.
# File lib/ovirtsdk4/services.rb, line 26392 def nics_service TemplateNicsService.new(@connection, "#{@path}/nics") end
Returns a reference to the service that manages the permissions that are associated with the template.
@return [AssignedPermissionsService] A reference to `permissions` service.
# File lib/ovirtsdk4/services.rb, line 26401 def permissions_service AssignedPermissionsService.new(@connection, "#{@path}/permissions") end
Removes a virtual machine template.
DELETE /ovirt-engine/api/templates/123
@param opts [Hash] Additional options.
@option opts [Boolean] :async Indicates if the remove should be performed asynchronously.
# File lib/ovirtsdk4/services.rb, line 26239 def remove(opts = {}) query = {} value = opts[:async] unless value.nil? value = Writer.render_boolean(value) query['async'] = value end request = HttpRequest.new(method: :DELETE, url: @path, query: query) response = @connection.send(request) unless response.code == 200 check_fault(response) end end
Seal the template.
Sealing erases all host-specific configuration from the filesystem: SSH keys, UDEV rules, MAC addresses, system ID, hostname etc., thus making easy to use the template to create multiple virtual machines without manual intervention.
Currently sealing is supported only for Linux OS.
@param opts [Hash] Additional options.
# File lib/ovirtsdk4/services.rb, line 26265 def seal(opts = {}) action = Action.new(opts) writer = XmlWriter.new(nil, true) ActionWriter.write_one(action, writer) body = writer.string writer.close request = HttpRequest.new( method: :POST, url: "#{@path}/seal", body: body ) response = @connection.send(request) case response.code when 200 action = check_action(response) else check_action(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 26430 def service(path) if path.nil? || path == '' return self end if path == 'cdroms' return cdroms_service end if path.start_with?('cdroms/') return cdroms_service.service(path[7..-1]) end if path == 'diskattachments' return disk_attachments_service end if path.start_with?('diskattachments/') return disk_attachments_service.service(path[16..-1]) end if path == 'graphicsconsoles' return graphics_consoles_service end if path.start_with?('graphicsconsoles/') return graphics_consoles_service.service(path[17..-1]) end if path == 'nics' return nics_service end if path.start_with?('nics/') return nics_service.service(path[5..-1]) end if path == 'permissions' return permissions_service end if path.start_with?('permissions/') return permissions_service.service(path[12..-1]) end if path == 'tags' return tags_service end if path.start_with?('tags/') return tags_service.service(path[5..-1]) end if path == 'watchdogs' return watchdogs_service end if path.start_with?('watchdogs/') return watchdogs_service.service(path[10..-1]) end raise Error.new("The path \"#{path}\" doesn't correspond to any service") end
Returns an string representation of this service.
@return [String]
# File lib/ovirtsdk4/services.rb, line 26484 def to_s "#<#{TemplateService}:#{@path}>" end
Updates the template.
The `name`, `description`, `type`, `memory`, `cpu`, `topology`, `os`, `high_availability`, `display`, `stateless`, `usb` and `timezone` elements can be updated after a template has been created.
For example, to update a template to so that it has 1 GiB of memory send a request like this:
PUT /ovirt-engine/api/templates/123
With the following request body:
<template>
<memory>1073741824</memory>
</template>
The `version_name` name attribute is the only one that can be updated within the `version` attribute used for template versions:
<template>
<version> <version_name>mytemplate_2</version_name> </version>
</template>
@param template [Template] The `template` to update. @param opts [Hash] Additional options.
@option opts [Boolean] :async Indicates if the update should be performed asynchronously.
@return [Template]
# File lib/ovirtsdk4/services.rb, line 26326 def update(template, opts = {}) if template.is_a?(Hash) template = OvirtSDK4::Template.new(template) end query = {} value = opts[:async] unless value.nil? value = Writer.render_boolean(value) query['async'] = value end request = HttpRequest.new(method: :PUT, url: @path, query: query) begin writer = XmlWriter.new(nil, true) TemplateWriter.write_one(template, writer) request.body = writer.string ensure writer.close end response = @connection.send(request) case response.code when 200 begin reader = XmlReader.new(response.body) return TemplateReader.read_one(reader) ensure reader.close end return result else check_fault(response) end end
Returns a reference to the service that manages the watchdogs that are associated with the template.
@return [TemplateWatchdogsService] A reference to `watchdogs` service.
# File lib/ovirtsdk4/services.rb, line 26419 def watchdogs_service TemplateWatchdogsService.new(@connection, "#{@path}/watchdogs") end