1Rex::Commands::VirtualiUzsaetrioCno(n3t)ributed Perl DocRuemxe:n:tCaotmimoannds::Virtualization(3)
2
3
4

NAME

6       Rex::Commands::Virtualization - Virtualization module
7

DESCRIPTION

9       With this module you can manage your virtualization.
10
11       Version <= 1.0: All these functions will not be reported.
12
13       All these functions are not idempotent.
14

SYNOPSIS

16        use Rex::Commands::Virtualization;
17
18        set virtualization => "LibVirt";
19        set virtualization => "VBox";
20
21        use Data::Dumper;
22
23        print Dumper vm list => "all";
24        print Dumper vm list => "running";
25
26        vm destroy => "vm01";
27
28        vm delete => "vm01";
29
30        vm start => "vm01";
31
32        vm shutdown => "vm01";
33
34        vm reboot => "vm01";
35
36        vm option => "vm01",
37              max_memory => 1024*1024,
38              memory    => 512*1024;
39
40        print Dumper vm info => "vm01";
41
42        # creating a vm on a kvm host
43        vm create => "vm01",
44           storage    => [
45             {
46               file  => "/mnt/data/libvirt/images/vm01.img",
47               dev   => "vda",
48             }
49           ];
50
51        print Dumper vm hypervisor => "capabilities";
52

EXPORTED FUNCTIONS

54   vm($action => $name, %option)
55       This module only exports the vm function. You can manage everything
56       with this function.
57

EXAMPLES

59   Creating a Virtual Machine
60       Create a (VirtualBox) VM named "vm01" with 512 MB ram and 1 cpu. One
61       harddrive, 10 GB in size being a file on disk.  With a cdrom as an iso
62       image and a natted network. The bootorder is set to "dvd".
63
64        vm create => "vm01",
65           storage    => [
66             {
67               file  => "/mnt/data/vbox/vm01.img",
68               size  => "10G",
69             },
70             {
71               file => "/mnt/iso/debian6.iso",
72             }
73           ],
74           memory => 512,
75           type => "Linux26",
76           cpus => 1,
77           boot => "dvd";
78
79       Create a (KVM) VM named "vm01" with 512 MB ram and 1 cpu. One
80       harddrive, 10 GB in size being a file on disk.  With a cdrom as an iso
81       image and a bridged network on the bridge virbr0. The Bootorder is set
82       to "cdrom".
83
84        vm create => "vm01",
85           boot => "cdrom",
86           storage    => [
87             {
88               size  => "10G",
89               file  => "/mnt/data/libvirt/images/vm01.img",
90             },
91
92             {
93               file    => "/mnt/data/iso/debian-6.0.2.1-amd64-netinst.iso",
94             },
95           ];
96
97       This is the same as above, but with all options in use.
98
99        vm create => "vm01",
100           memory  => 512*1024,
101           cpus    => 1,
102           arch    => "x86_64",
103           boot    => "cdrom",
104           clock   => "utc",
105           emulator => "/usr/bin/qemu-system-x86_64",
106           on_poweroff => "destroy",
107           on_reboot  => "restart",
108           on_crash   => "restart",
109           storage    => [
110             {  type  => "file",
111               size  => "10G",
112               device => "disk",
113               driver_type => "qcow2",      # supports all formats qemu-img supports.
114               file  => "/mnt/data/libvirt/images/vm01.img",
115               dev   => "vda",
116               bus   => "virtio",
117               address => {
118                 type    => "pci",
119                 domain  => "0x0000",
120                 bus    => "0x00",
121                 slot    => "0x05",
122                 function => "0x0",
123               },
124             },
125             {  type    => "file",
126               device  => "cdrom",
127               file    => "/mnt/data/iso/debian-6.0.2.1-amd64-netinst.iso",
128               dev    => "hdc",
129               bus    => "ide",
130               readonly => 1,
131               address  => {
132                 type     => "drive",
133                 controller => 0,
134                 bus      => 1,
135                 unit     => 0,
136               },
137             },
138           ],
139           network => [
140             {  type   => "bridge",
141               bridge  => "virbr0",
142               model  => "virtio",
143               address => {
144                 type    => "pci",
145                 domain  => "0x0000",
146                 bus    => "0x00",
147                 slot    => "0x03",
148                 function => "0x0",
149               },
150             },
151           ],
152           serial_devices => [
153             {
154               type => 'tcp',
155               host => '127.0.0.1',
156               port => 12345,
157             },
158           ];
159
160       Create a (Xen/HVM) VM named "vm01" with 512 MB ram and 1 cpu. One
161       harddrive, cloned from an existing one.
162
163        vm create => "vm01",
164           type  => "hvm",
165           storage    => [
166             {
167               file    => "/mnt/data/libvirt/images/vm01.img",
168               template => "/mnt/data/libvirt/images/svn01.img",
169             },
170           ];
171
172       This is the same as above, but with all options in use.
173
174        vm create => "vm01",
175           memory => 512*1024,
176           cpus  => 1,
177           boot  => "hd",
178           clock  => "utc",
179           on_poweroff => "destroy",
180           on_reboot  => "restart",
181           on_crash   => "restart",
182           storage    => [
183             {  type  => "file",
184               size  => "10G",
185               device => "disk",
186               file  => "/mnt/data/libvirt/images/vm01.img",
187               dev   => "hda",
188               bus   => "ide",
189               template => "/mnt/data/libvirt/images/svn01.img",
190             },
191             {  type    => "file",
192               device  => "cdrom",
193               dev    => "hdc",
194               bus    => "ide",
195               readonly => 1,
196             },
197           ],
198           network => [
199             {  type   => "bridge",
200               bridge  => "virbr0",
201             },
202           ],
203           type => "hvm";
204
205       Create a (Xen/PVM) VM named "vm01" with 512 MB ram and 1 cpu. With one
206       root partition (10GB in size) and one swap parition (1GB in size).
207
208        vm create => "vm01",
209           type  => "pvm",
210           storage    => [
211             {
212               file   => "/mnt/data/libvirt/images/domains/vm01/disk.img",
213               dev    => "xvda2",
214               is_root => 1,
215             },
216             {
217               file  => "/mnt/data/libvirt/images/domains/vm01/swap.img",
218               dev   => "xvda1",
219             },
220           ];
221
222       This is the same as above, but with all options in use.
223
224        vm create => "vm01",
225           type  => "pvm",
226           memory => 512*1024,
227           cpus  => 1,
228           clock  => "utc",
229           on_poweroff => "destroy",
230           on_reboot  => "restart",
231           on_crash   => "restart",
232           os       => {
233             type  => "linux",
234             kernel => "/boot/vmlinuz-2.6.32-5-xen-amd64",
235             initrd => "/boot/initrd.img-2.6.32-5-xen-amd64",
236             cmdline => "root=/dev/xvda2 ro",
237           },
238           storage    => [
239             {  type  => "file",
240               size  => "10G",
241               device => "disk",
242               file  => "/mnt/data/libvirt/images/domains/vm01/disk.img",
243               dev   => "xvda2",
244               bus   => "xen",
245               aio   => 1, # if you want to use aio
246             },
247             {  type  => "file",
248               size  => "4G",
249               device => "disk",
250               file  => "/mnt/data/libvirt/images/domains/vm01/swap.img",
251               dev   => "xvda1",
252               bus   => "xen",
253               aio   => 1, # if you want to use aio
254             },
255           ],
256           network => [
257             {  type   => "bridge",
258               bridge  => "virbr0",
259             },
260           ];
261
262   Start/Stop/Destroy
263       Start a stopped vm
264
265        vm start => "name";
266
267       Stop a running vm (send shutdown signal)
268
269        vm shutdown => "name";
270
271       Hard Stop a running vm
272
273        vm destroy => "name";
274
275   Delete
276        vm delete => "name";
277
278   Modifying a VM
279       Currently you can only modify the memory.
280
281        vm option => "name",
282             max_memory => 1024*1024, # in bytes
283             memory    => 512*1024;
284
285   Request information of a vm
286        vm info => "name";
287
288   Request info from the underlying hypervisor
289        vm hypervisor => "capabilities";
290
291
292
293perl v5.34.0                      2021-07-21  Rex::Commands::Virtualization(3)
Impressum