NAME

Ovirt::VM - Bindings for oVirt VM API

VERSION

Version 0.04

SYNOPSIS

use Ovirt::VM;

my %con = (
           username            => 'admin',
           password            => 'password',
           manager             => 'ovirt-mgr.example.com',
           vm_output_attrs     => 'id,name,state,description', # optional
           vm_output_delimiter => '||', # optional
);

my $vm = Ovirt::VM->new(%con);

# return xml / json output
print $vm->list_xml; 
print $vm->list_json;

# list vm separated by new line
# return attributes specified on 'vm_output_attrs'
print $vm->list;

# list specific vm 
print $vm->list('b4738b0f-b73d-4a66-baa8-2ba465d63132');

# create, remove, get all running vm, stop all vm
$vm->create('vm1','Default','CentOS7');
$vm->remove('2d83bb51-9a77-432d-939c-35be207017b9');
$vm->get_running();
$vm->stop_all();

# start, stop, reboot, migrate vm
$vm->start     ('b4738b0f-b73d-4a66-baa8-2ba465d63132');
$vm->stop      ('b4738b0f-b73d-4a66-baa8-2ba465d63132');
$vm->reboot    ('b4738b0f-b73d-4a66-baa8-2ba465d63132');
$vm->migrate   ('b4738b0f-b73d-4a66-baa8-2ba465d63132');

# get vm's statistics
$vm->get_statistics($vmid);

# add/remove/list nic and disk
$vm->add_disk('6efc0cfa-8495-4a96-93e5-ee490328cf48',  # vm id
               'virtio',                               # driver interface
               'cow',                                  # format
               '1073741824',                           # size
               'mydisk1',                              # disk name
               '9b952bdc-b7ec-4673-84b0-477b48945a9a'  # storage domain id
             );

$vm->add_nic('6efc0cfa-8495-4a96-93e5-ee490328cf48',   # vm id
             'virtio',                                 # driver interface
             'nic1',                                   # nic name
             'rhevm'                                   # network name
            );

# Output also available in hash
# for example to print all vm name and state
my $hash = $vm->hash_output;
for my $array (keys $hash->{vm}) {
   print $hash->{vm}[$array]->{name} . " " . 
           $hash->{vm}[$array]->{status}->{state};
}

# we can also specify specific vm 'id' when initiating an object
# so we can direct access the element for specific vm
print $vm->hash_output->{name};                   
print $vm->hash_output->{cluster}->{id};

Attributes

Other attributes is also inherited from Ovirt.pm
Check 'perldoc Ovirt' for detail

notes :
ro                     = read only, can be specified only during initialization
rw                     = read write, user can set this attribute
rwp                    = read write protected, for internal class

vm_url                 = (ro) store default vm url path                  
vm_cdrom_xml           = (ro) store xml to be post on start/stop vm action with boot device set to cdrom
vm_hd_xml              = (ro) store xml to be post on start/stop vm action with boot device set to hd
vm_boot_dev            = (rw) set boot device when start / stopping vm, default to hd
vm_output_delimiter    = (rw) specify output delimiter between attribute, default is '||'
vm_output_attrs        = (rw) store vm attributes to be returned, default is (id, name, state)
                         supported attributes :
                           id              name    
                           memory          description
                           state           cpu_cores
                           cpu_sockets     cpu_arch
                           cpu_shares      os_type
                           boot_dev        ha_enabled
                           ha_priority     display_type
                           display_address display_port
                           cluster_id      template_id
                           stop_time       creation_time
                           timezone        usb_enabled
                           host_id         display_host_subject
                           

SUBROUTINES/METHODS

BUILD

The Constructor, build logging, call pass_log_obj method
Built root_url with vm_url
set output with get_api_response method from Ovirt.pm
check if output attributes is valid

vm_action_output

this method handle the output e.g start / stop vm
required arguments ($xml), output passed by start/stop method

remove

remove vm

list_snapshot

list vm's snapshot
required argument ('vm id')

create_snapshot

required arguments ('vm id', 'snapshot description', 'memorystate')
memorystate can be true/false

$vm->create_snapshot('ec191b8c-b3ec-41b9-9f9f-6d92bc32732b', 'test3', 'false');

delete_snapshot

required arguments ('vm id', 'snapshot id')
$vm->delete_snapshot('ec191b8c-b3ec-41b9-9f9f-6d92bc32732b', 'b0e9198c-a404-4659-8a82-421ae85f54e1');

list_disk

list vm's disk
required argument ('vm id')

add_disk

create vm disk
required arguments ('vm id', 'driver type', 'format' , 'size in bytes', 'disk name', 'storage domain id' )

supported driver type :
- virtio
- ide

supported format:
- cow
- raw

use Ovirt::Storage to get more information for the storage domain id
see 'perldoc Ovirt::Storage' for example

example :
$vm->add_disk('6efc0cfa-8495-4a96-93e5-ee490328cf48',  # vm id
               'virtio',                               # driver interface
               'cow',                                  # format
               '1073741824',                           # size
               'mydisk1',                              # disk name
               '9b952bdc-b7ec-4673-84b0-477b48945a9a'  # storage domain id
             );

remove_disk

remove vm disk
required arguments ('vm id', 'disk id')
use method list_disk to get the 'disk id' for particular vm

example :
$vm->remove_disk('6efc0cfa-8495-4a96-93e5-ee490328cf48', '99a4f585-9a39-465b-ae24-0068bd4eaad6');

list_nic

list vm's nic
required argument ('vm id')

add_nic

create vm nic
required arguments ('vm id', 'driver type', 'nic name', 'network name' )

supported driver type :
- virtio
- e1000
- rtl8139

use Ovirt::Network to get more information for the network name
see 'perldoc Ovirt::Network' for example

example :
$vm->add_nic('6efc0cfa-8495-4a96-93e5-ee490328cf48', 'virtio', 'nic1', 'rhevm');

remove_nic

remove vm nic
required arguments ('vm id', 'nic id')
use method list_nic to get the 'nic id' for particular vm

example :
$vm->remove_nic('6efc0cfa-8495-4a96-93e5-ee490328cf48', '82416c65-d8b2-4c82-8134-0e73e5ead624');

create

create vm using template
required arguments (vm name, cluster name, template name)
optional argument 'memory in bytes'
example :
# with memory specified 
$vm->create('vm1', 'production_cluster', 'RHEL7', 1073741824);

# without memory specified (will be based on template's memory)
$vm->create('vm1', 'production_cluster', 'RHEL7');

start

start vm
required arguments ($vmid)
if $self->id is set during initialization, argument is not required

stop

stop vm
required arguments ($vmid)
if $self->id is set during initialization, argument is not required

stop_all

stop all vm if vm state = 'up'
do not set 'id' during initialization because it will not return all vm
this will loop using stop method
$vm->stop_all();

get_running

return vmid,name if state = 'up' 
each vm separated by new line
do not set 'id' during initialization because it will not return all vm
$vm->get_running();

reboot

reboot vm
required arguments ($vmid)
if $self->id is set during initialization, argument is not required

suspend

suspend vm
required arguments ($vmid)
if $self->id is set during initialization, argument is not required

migrate

migrate vm
required arguments ($vmid)
if $self->id is set during initialization, argument is not required

is_vmid_valid

return false if vmid not valid

get_statistics

required argument ($vmid) or set 'id' during initialization
return vm statistics
$vm->get_statistics($vmid);

list

return vm's attributes text output from hash_output attribute
if no argument spesified, it will return all vm attributes (based on vm_output_attrs)
argument supported is 'vm id'
example :
$vm->list('b4738b0f-b73d-4a66-baa8-2ba465d63132');

get_vm_by_element_id

This method is used by list method to list all vm attribute requested
An array element id and attribute name is required

get_vm_by_self_id

This method is used by list method if $self->id is defined
The id is set during initialization (id => 'vmid')
attribute name is required

AUTHOR

"Heince Kurniawan", C<< <"heince at cpan.org"> >>

BUGS

Please report any bugs or feature requests to C<bug-ovirt at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Ovirt::VM>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

   perldoc Ovirt::VM

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2015 "Heince Kurniawan".

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.