class OvirtSDK4::TemplatesService

Constants

ADD
ADD_FROM_CONFIGURATION
ADD_FROM_VM
ADD_FROM_VM_SNAPSHOT
LIST

Public Instance Methods

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

Creates a new template.

This requires the `name` and `vm` elements. To identify the virtual machine use the `vm.id` or `vm.name` attributes. For example, to create a template from a virtual machine with the identifier `123` send a request like this:

source

POST /ovirt-engine/api/templates


With a request body like this:

source,xml

<template>

<name>mytemplate</name>
<vm id="123"/>

</template>


Since version 4.3, in order to create virtual machine template from a snapshot send a request body like this:

source,xml

<template>

<name>mytemplate</name>
<vm id="123">
  <snapshots>
    <snapshot id="456"/>
  </snapshots>
</vm>

</template>


The disks of the template can be customized, making some of their characteristics different from the disks of the original virtual machine. To do so use the `vm.disk_attachments` attribute, specifying the identifier of the disk of the original virtual machine and the characteristics that you want to change. For example, if the original virtual machine has a disk with the identifier `456`, and, for that disk, you want to change the name to `mydisk` the format to xref:types-disk_format[_Copy On Write_] and make it xref:types-disk, send a request body like this:

source,xml

<template>

<name>mytemplate</name>
<vm id="123">
  <disk_attachments>
    <disk_attachment>
      <disk id="456">
        <name>mydisk</name>
        <format>cow</format>
        <sparse>true</sparse>
      </disk>
    </disk_attachment>
  </disk_attachments>
</vm>

</template>


The template can be created as a sub-version of an existing template. This requires the `name` and `vm` attributes for the new template, and the `base_template` and `version_name` attributes for the new template version. The `base_template` and `version_name` attributes must be specified within a `version` section enclosed in the `template` section. Identify the virtual machine with the `id` or `name` attributes.

source,xml

<template>

<name>mytemplate</name>
<vm id="123"/>
<version>
  <base_template id="456"/>
  <version_name>mytemplate_001</version_name>
</version>

</template>


The destination storage domain of the template can be customized, in one of two ways:

  1. Globally, at the request level. The request must list the desired disk attachments to be created on the

storage domain. If the disk attachments are not listed, the global storage domain parameter will be ignored. +

source,xml

<template>

<name>mytemplate</name>
<storage_domain id="123"/>
<vm id="456">
  <disk_attachments>
    <disk_attachment>
      <disk id="789">
        <format>cow</format>
        <sparse>true</sparse>
      </disk>
    </disk_attachment>
  </disk_attachments>
</vm>

</template>


  1. Per each disk attachment. Specify the desired storage domain for each disk attachment.

Specifying the global storage definition will override the storage domain per disk attachment specification. +

source,xml

<template>

<name>mytemplate</name>
<vm id="123">
  <disk_attachments>
    <disk_attachment>
      <disk id="456">
        <format>cow</format>
        <sparse>true</sparse>
        <storage_domains>
           <storage_domain id="789"/>
        </storage_domains>
      </disk>
    </disk_attachment>
  </disk_attachments>
</vm>

</template>


@param template [Template] The information about the template or template version.

@param opts [Hash] Additional options.

@option opts [Boolean] :clone_permissions Specifies if the permissions of the virtual machine should be copied to the template.

If this optional parameter is provided, and its value is `true`, then the permissions of the virtual machine
(only the direct ones, not the inherited ones) will be copied to the created template. For example, to create
a template from the `myvm` virtual machine copying its permissions, send a request like this:

[source]
----
POST /ovirt-engine/api/templates?clone_permissions=true
----

With a request body like this:

[source,xml]
----
<template>
  <name>mytemplate<name>
  <vm>
    <name>myvm<name>
  </vm>
</template>
----

@option opts [Boolean] :seal Seals the template.

If this optional parameter is provided and its value is `true`,
then the template is sealed after creation.

Sealing erases all host-specific configuration from the filesystem:
SSH keys, UDEV rules, MAC addresses, system ID, hostname, and so on,
thus making it easier to use the template to create multiple virtual
machines without manual intervention.

Currently, sealing is supported only for Linux operating systems.

@option opts [Hash] :headers ({}) Additional HTTP headers.

@option opts [Hash] :query ({}) Additional URL query parameters.

@option opts [Integer] :timeout (nil) The timeout for this request, in seconds. If no value is explicitly

given then the timeout set globally for the connection will be used.

@option opts [Boolean] :wait (true) If `true` wait for the response.

@return [Template]

# File lib/ovirtsdk4/services.rb, line 28918
def add(template, opts = {})
  internal_add(template, Template, ADD, opts)
end
add_from_configuration(template, opts = {}) click to toggle source

Add a virtual machine template to the system from a configuration. Requires the configuration type, the configuration data, and the target cluster.

@param template [Template] The information about the template or template version.

@param opts [Hash] Additional options.

@option opts [Boolean] :clone_permissions Specifies if the permissions of the virtual machine should be copied to the template.

If this optional parameter is provided, and its value is `true`, then the permissions of the virtual machine
(only the direct ones, not the inherited ones) will be copied to the created template. For example, to create
a template from the `myvm` virtual machine copying its permissions, send a request like this:

[source]
----
POST /ovirt-engine/api/templates?clone_permissions=true
----

With a request body like this:

[source,xml]
----
<template>
  <name>mytemplate<name>
  <vm>
    <name>myvm<name>
  </vm>
</template>
----

@option opts [Boolean] :seal Seals the template.

If this optional parameter is provided and its value is `true`,
then the template is sealed after creation.

Sealing erases all host-specific configuration from the filesystem:
SSH keys, UDEV rules, MAC addresses, system ID, hostname, and so on,
thus making it easier to use the template to create multiple virtual
machines without manual intervention.

Currently, sealing is supported only for Linux operating systems.

@option opts [Hash] :headers ({}) Additional HTTP headers.

@option opts [Hash] :query ({}) Additional URL query parameters.

@option opts [Integer] :timeout (nil) The timeout for this request, in seconds. If no value is explicitly

given then the timeout set globally for the connection will be used.

@option opts [Boolean] :wait (true) If `true` wait for the response.

@return [Template]

# File lib/ovirtsdk4/services.rb, line 28982
def add_from_configuration(template, opts = {})
  internal_add(template, Template, ADD_FROM_CONFIGURATION, opts)
end
add_from_vm(template, opts = {}) click to toggle source

Add a virtual machine template to the system from an existing virtual machine.

@param template [Template] The information about the template or template version.

@param opts [Hash] Additional options.

@option opts [Boolean] :clone_permissions Specifies if the permissions of the virtual machine should be copied to the template.

If this optional parameter is provided, and its value is `true`, then the permissions of the virtual machine
(only the direct ones, not the inherited ones) will be copied to the created template. For example, to create
a template from the `myvm` virtual machine copying its permissions, send a request like this:

[source]
----
POST /ovirt-engine/api/templates?clone_permissions=true
----

With a request body like this:

[source,xml]
----
<template>
  <name>mytemplate<name>
  <vm>
    <name>myvm<name>
  </vm>
</template>
----

@option opts [Boolean] :seal Seals the template.

If this optional parameter is provided and its value is `true`,
then the template is sealed after creation.

Sealing erases all host-specific configuration from the filesystem:
SSH keys, UDEV rules, MAC addresses, system ID, hostname, and so on,
thus making it easier to use the template to create multiple virtual
machines without manual intervention.

Currently, sealing is supported only for Linux operating systems.

@option opts [Hash] :headers ({}) Additional HTTP headers.

@option opts [Hash] :query ({}) Additional URL query parameters.

@option opts [Integer] :timeout (nil) The timeout for this request, in seconds. If no value is explicitly

given then the timeout set globally for the connection will be used.

@option opts [Boolean] :wait (true) If `true` wait for the response.

@return [Template]

# File lib/ovirtsdk4/services.rb, line 29046
def add_from_vm(template, opts = {})
  internal_add(template, Template, ADD_FROM_VM, opts)
end
add_from_vm_snapshot(template, opts = {}) click to toggle source

Add a virtual machine template to the system from a snapshot.

@param template [Template] The information about the template or template version.

@param opts [Hash] Additional options.

@option opts [Boolean] :clone_permissions Specifies if the permissions of the virtual machine should be copied to the template.

If this optional parameter is provided, and its value is `true`, then the permissions of the virtual machine
(only the direct ones, not the inherited ones) will be copied to the created template. For example, to create
a template from the `myvm` virtual machine copying its permissions, send a request like this:

[source]
----
POST /ovirt-engine/api/templates?clone_permissions=true
----

With a request body like this:

[source,xml]
----
<template>
  <name>mytemplate<name>
  <vm>
    <name>myvm<name>
  </vm>
</template>
----

@option opts [Boolean] :seal Seals the template.

If this optional parameter is provided and its value is `true`,
then the template is sealed after creation.

Sealing erases all host-specific configuration from the filesystem:
SSH keys, UDEV rules, MAC addresses, system ID, hostname, and so on,
thus making it easier to use the template to create multiple virtual
machines without manual intervention.

Currently, sealing is supported only for Linux operating systems.

@option opts [Hash] :headers ({}) Additional HTTP headers.

@option opts [Hash] :query ({}) Additional URL query parameters.

@option opts [Integer] :timeout (nil) The timeout for this request, in seconds. If no value is explicitly

given then the timeout set globally for the connection will be used.

@option opts [Boolean] :wait (true) If `true` wait for the response.

@return [Template]

# File lib/ovirtsdk4/services.rb, line 29110
def add_from_vm_snapshot(template, opts = {})
  internal_add(template, Template, ADD_FROM_VM_SNAPSHOT, opts)
end
list(opts = {}) click to toggle source

Returns the list of virtual machine templates.

For example:

source

GET /ovirt-engine/api/templates


Will return the list of virtual machines and virtual machine templates.

The order of the returned list of templates is not guaranteed.

@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 [Boolean] :filter Indicates if the results should be filtered according to the permissions of the user.

@option opts [String] :follow Indicates which inner links should be followed. The objects referenced by these links will be fetched as part

of the current request. See <<documents/003_common_concepts/follow, here>> for details.

@option opts [Integer] :max Sets the maximum number of templates to return. If not specified, all the templates are returned.

@option opts [String] :search A query string used to restrict the returned templates.

@option opts [Hash] :headers ({}) Additional HTTP headers.

@option opts [Hash] :query ({}) Additional URL query parameters.

@option opts [Integer] :timeout (nil) The timeout for this request, in seconds. If no value is explicitly

given then the timeout set globally for the connection will be used.

@option opts [Boolean] :wait (true) If `true` wait for the response.

@return [Array<Template>]

# File lib/ovirtsdk4/services.rb, line 29164
def list(opts = {})
  internal_get(LIST, opts)
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 29186
def service(path)
  if path.nil? || path == ''
    return self
  end
  index = path.index('/')
  if index.nil?
    return template_service(path)
  end
  return template_service(path[0..(index - 1)]).service(path[(index + 1)..-1])
end
template_service(id) click to toggle source

Returns a reference to the service that manages a specific virtual machine template.

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

@return [TemplateService] A reference to the `template` service.

# File lib/ovirtsdk4/services.rb, line 29175
def template_service(id)
  TemplateService.new(self, id)
end