Class: OvirtSDK4::VmsService
- Defined in:
- lib/ovirtsdk4/services.rb,
lib/ovirtsdk4/services.rb
Instance Method Summary collapse
-
#add(vm, opts = {}) ⇒ Vm
Creates a new virtual machine.
-
#add_from_configuration(vm, opts = {}) ⇒ Vm
add a virtual machine to the system from a configuration - requires the configuration type and the configuration data.
-
#add_from_scratch(vm, opts = {}) ⇒ Vm
add a virtual machine to the system from scratch.
-
#add_from_snapshot(vm, opts = {}) ⇒ Vm
add a virtual machine to the system by cloning from a snapshot.
-
#list(opts = {}) ⇒ Array<Vm>
Returns the list of virtual machines of the system.
-
#service(path) ⇒ Service
Locates the service corresponding to the given path.
-
#vm_service(id) ⇒ VmService
Locates the
vm
service.
Methods inherited from Service
Instance Method Details
#add(vm, opts = {}) ⇒ Vm
Creates a new virtual machine.
The virtual machine can be created in different ways:
-
From a template. In this case the identifier or name of the template must be provided. For example, using a plain shell script and XML:
#!/bin/sh -ex
url="https://engine.example.com/ovirt-engine/api"
user="[email protected]"
password="..."
curl \
--verbose \
--cacert /etc/pki/ovirt-engine/ca.pem \
--user "${user}:${password}" \
--request POST \
--header "Version: 4" \
--header "Content-Type: application/xml" \
--header "Accept: application/xml" \
--data '
<vm>
<name>myvm</name>
<template>
<name>Blank</name>
</template>
<cluster>
<name>mycluster</name>
</cluster>
</vm>
' \
"${url}/vms"
-
From a snapshot. In this case the identifier of the snapshot has to be provided. For example, using a plain shel script and XML:
#!/bin/sh -ex
url="https://engine.example.com/ovirt-engine/api"
user="[email protected]"
password="..."
curl \
--verbose \
--cacert /etc/pki/ovirt-engine/ca.pem \
--user "${user}:${password}" \
--request POST \
--header "Content-Type: application/xml" \
--header "Accept: application/xml" \
--data '
<vm>
<name>myvm</name>
<snapshots>
<snapshot id="266742a5-6a65-483c-816d-d2ce49746680"/>
</snapshots>
<cluster>
<name>mycluster</name>
</cluster>
</vm>
' \
"${url}/vms"
When creating a virtual machine from a template or from a snapshot it is usually useful to explicitly indicate
in what storage domain to create the disks for the virtual machine. If the virtual machine is created from
a template then this is achieved passing a set of disk_attachment
elements that indicate the mapping:
<vm>
...
<disk_attachments>
<disk_attachment>
<disk id="8d4bd566-6c86-4592-a4a7-912dbf93c298">
<storage_domains>
<storage_domain id="9cb6cb0a-cf1d-41c2-92ca-5a6d665649c9"/>
</storage_domains>
</disk>
<disk_attachment>
</disk_attachments>
</vm>
When the virtual machine is created from a snapshot this set of disks is slightly different, it uses the
image_id
attribute instead of id
.
<vm>
...
<disk_attachments>
<disk_attachment>
<disk>
<image_id>8d4bd566-6c86-4592-a4a7-912dbf93c298</image_id>
<storage_domains>
<storage_domain id="9cb6cb0a-cf1d-41c2-92ca-5a6d665649c9"/>
</storage_domains>
</disk>
<disk_attachment>
</disk_attachments>
</vm>
It is possible to specify additional virtual machine parameters in the XML description, e.g. a virtual machine
of desktop
type, with 2 GiB of RAM and additional description can be added sending a request body like the
following:
<vm>
<name>myvm</name>
<description>My Desktop Virtual Machine</description>
<type>desktop</type>
<memory>2147483648</memory>
...
</vm>
A bootable CDROM device can be set like this:
<vm>
...
<os>
<boot dev="cdrom"/>
</os>
</vm>
In order to boot from CDROM, you first need to insert a disk, as described in the
CDROM service. Then booting from that CDROM can be specified using the os.boot.devices
attribute:
<vm>
...
<os>
<boot>
<devices>
<device>cdrom</device>
</devices>
</boot>
</os>
</vm>
In all cases the name or identifier of the cluster where the virtual machine will be created is mandatory.
35053 35054 35055 |
# File 'lib/ovirtsdk4/services.rb', line 35053 def add(vm, opts = {}) internal_add(vm, Vm, ADD, opts) end |
#add_from_configuration(vm, opts = {}) ⇒ Vm
add a virtual machine to the system from a configuration - requires the configuration type and the configuration data
35149 35150 35151 |
# File 'lib/ovirtsdk4/services.rb', line 35149 def add_from_configuration(vm, opts = {}) internal_add(vm, Vm, ADD_FROM_CONFIGURATION, opts) end |
#add_from_scratch(vm, opts = {}) ⇒ Vm
add a virtual machine to the system from scratch
35245 35246 35247 |
# File 'lib/ovirtsdk4/services.rb', line 35245 def add_from_scratch(vm, opts = {}) internal_add(vm, Vm, ADD_FROM_SCRATCH, opts) end |
#add_from_snapshot(vm, opts = {}) ⇒ Vm
add a virtual machine to the system by cloning from a snapshot
35341 35342 35343 |
# File 'lib/ovirtsdk4/services.rb', line 35341 def add_from_snapshot(vm, opts = {}) internal_add(vm, Vm, ADD_FROM_SNAPSHOT, opts) end |
#list(opts = {}) ⇒ Array<Vm>
Returns the list of virtual machines of the system.
The order of the returned list of virtual machines is guaranteed only if the sortby
clause is included
in the search
parameter.
35418 35419 35420 |
# File 'lib/ovirtsdk4/services.rb', line 35418 def list(opts = {}) internal_get(LIST, opts) end |
#service(path) ⇒ Service
Locates the service corresponding to the given path.
35440 35441 35442 35443 35444 35445 35446 35447 35448 35449 |
# File 'lib/ovirtsdk4/services.rb', line 35440 def service(path) if path.nil? || path == '' return self end index = path.index('/') if index.nil? return vm_service(path) end return vm_service(path[0..(index - 1)]).service(path[(index + 1)..-1]) end |