# # Copyright (c) 2011 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # # VMware® End User License Agreement # VMware, Inc. (“VMware”) provides the vSphere Command-Line Interface (vSphere CLI) # and/or vSphere Software Development Kit for Perl (vSphere SDK for Perl) (collectively # the “Software”) to you subject to the following terms and conditions. If you # disagree with any of the following terms, then do not use the Software. # 1. The Software contains a variety of materials, interface definitions, documentation, # sample utility applications and sample code regarding programming interfaces to one or # more VMware products as referenced in such materials (“VMware Products”). This Software # is intended to be used to execute supplied commands and utility applications and to # create scripts that interact with the VMware Products. # 2. Use Rights: Subject to the restrictions below, you may download and make a # reasonable number of copies of the Software contents for your use solely for the purpose # of creating software that communicates with VMware Products (“Developer Software”). For # vSphere SDK for Perl, some code may be designated as “distributable code” and/or # “modifiable code” at http://www.vmware.com/go/vsdkperl-redistribution-info. For vSphere # CLI, some code may be designated as “distributable code” and/ or “modifiable code” at # http://www.vmware.com/go/vcli-redistribution-info. You may use and merge all or portions # of the “distributable code” with your Developer Software. Any merged portion of any # “distributable code” is subject to this Agreement. Additionally, you may modify or create # derivative works of all or portions of the “modifiable code.” You are permitted to # re-distribute the “distributable code” and the modified or derivative works of the # “modifiable code” only as part of your Developer Software for non-commercial or commercial # use. Open source software components provided with the Software are licensed to you under # the terms of the applicable license agreements included with such open source software # components. The open source software licenses can be found in the open_source_licenses.txt # file, other materials accompanying the Software, the documentation or corresponding source # files available at http://www.vmware.com/download/vi/open_source.html. # 3. Restrictions: You agree that you will not (1) use the Software to create, design or # develop anything other than Developer Software; (2) make any more copies of the Software # than are reasonably necessary for the authorized use and backup and archival purposes; # (3) modify, create derivative works of, reverse engineer, reverse compile, or disassemble # the Software, except as expressly permitted in Section 2; (4) distribute, sell, lease, rent, # lend, or sublicense any part of the Software to any third party except as expressly permitted # in Section 2 or; (5) use the Software to (a) create, design or develop software or service to # circumvent, enable, modify or provide access, permissions or rights which would violate the # technical restrictions of VMware Products, any additional licensing terms provided by VMware # via product documentation, email notification and/or policy change on VMware website, and/or # the terms of the End User License Agreements of VMware products; (b) disable, remove, over-ride # or modify the display of any VMware product End User License Agreements to the end customers; # and (c) upload or otherwise transmit any material containing software viruses or other computer # code, files or programs designed to interrupt, destroy, or limit the functionality of any # software or hardware. # The restrictions in this Section 3 shall not apply if and to the extent they contradict # mandatory local law (including, but not limited to, law implementing the EC Software Directive) # provided that, before you exercise any rights that you believe to be entitled to based on # mandatory law, you provide VMware with 30 days prior written notice at SDK_Legal@vmware.com and # provide all reasonably requested information to allow VMware to assess your claim and, at # VMware’s sole discretion, to provide alternatives that reduce any adverse impact on VMware’s # intellectual property or other rights. # 4. VMware retains ownership of the Software, including without limitation all copyrights and # other intellectual property rights therein. You may not remove, delete or modify any of VMware # copyright statements in the Software. # 5. You may not use VMware’s name, trademarks or service marks in your Developer Software’s # names or in a way that suggests your Developer Software is certified or endorsed by VMware. Your # use of VMware product names and trademarks shall comply with the Branding Guidelines posted at # www.vmware.com. # 6. If you are currently entitled to support from VMware, you may submit a support request # for installation assistance of this Software and assistance in executing unmodified utility # applications or vSphere CLI commands provided with this Software. Except as provided herein, # you are not entitled to any VMware support for this Software or any other services from VMware # in connection with this Software or your Developer Software. # 7. Term, Termination and Changes: This Agreement shall continue as long as you are in compliance # with the terms specified herein or until otherwise terminated. You and or VMware each may # terminate this Agreement for any reason at any time. You agree, upon termination, to destroy # all copies of the Software within your possession or control. The Confidential Information, # Limitations of Warranties, Liability and Indemnification sections set out in this Agreement # shall survive any termination or expiration of this Agreement. # 8. Limitations of Warranties and Liability: THE SOFTWARE IS PROVIDED “AS IS” WITHOUT ANY # WARRANTIES OF ANY KIND. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, VMWARE DISCLAIMS # ANY IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS. # TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT WILL VMWARE BE LIABLE FOR ANY # LOST PROFITS OR BUSINESS OPPORTUNITIES, LOSS OF USE, BUSINESS INTERRUPTION, LOSS OF DATA, OR ANY # OTHER INDIRECT, SPECIAL, INCIDENTAL, OR CONSE¬QUEN¬TIAL DAMAGES ARISING OUT OF THE SOFTWARE OR # YOUR USE OF THE SOFTWARE, UNDER ANY THEORY OF LIABILITY, WHETHER BASED IN CONTRACT, TORT, # NEGLIGENCE, PRODUCT LIABILITY, OR OTHERWISE. BECAUSE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION # OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, THE PRECEDING LIMITATION MAY # NOT APPLY TO YOU. # VMWARE’S LIABILITY ARISING OUT OF THE SOFTWARE PROVIDED HEREUNDER WILL NOT, IN ANY EVENT, # EXCEED US$5.00. # THE FOREGOING LIMITATIONS SHALL APPLY TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, REGARDLESS # OF WHETHER VMWARE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND REGARDLESS OF WHETHER # ANY REMEDY FAILS OF ITS ESSENTIAL PURPOSE. # 9. Indemnification: You agree to defend, indemnify and hold harmless VMware, and any of its # directors, officers, employees, affiliates or agents, from and against any and all claims, losses, # damages, liabilities and other expenses (including reasonable attorneys’ fees), arising from your # modification or derivative works of the “modifiable code”, distribution or use of your Developer # Software or breach of this Agreement. # 10. These terms are governed by the laws of the State of California and the United States of # America without regard to conflict of laws principles. You may not assign any part of this Agreement # without the prior written consent of VMware. Any attempted assignment without consent shall be void. # These terms constitute the entire agreement between you and VMware with respect to the Software, and # supersede all prior written or oral communications, understandings and agreements. Any waiver of these # terms must be in writing to be effective. If any provision of these terms is found to be invalid or # unenforceable, the remaining terms will continue to be valid and enforceable to the fullest extent # permitted by law. ## @summary VirtualMachine ComponentState Module ## @author kathar.hidayath@netapp.com, dl-nacl-dev@netapp.com ## @status shared ## @pod here =head1 NAME NACL::CS::HyperV::VirtualMachine =head1 DESCRIPTION C is a derived class of L. It represents the state of Virtual machine on the given HyperV Server. A related class isL, access to the Virtual machine managed object reference of an HyperV Server. =head1 ATTRIBUTES The individual pieces of data that are part of the state of the VM element are the attributes of the VM ComponentState. =over =item C<< vm_name >> Filled in for at least ESX VMAPI and Xen XAPI =item C<< numCpu >> Filled in for at least ESX VMAPI and Xen XAPI =item C<< template >> Filled in for at least ESX VMAPI and Xen XAPI =item C<< guestId >> Filled in for at least ESX VMAPI and Xen XAPI =item C<< powerState >> Filled in for at least ESX VMAPI and Xen XAPI =item C<< memorySizeMB >> Filled in for ESX VMAPI =item C<< numVirtualDisks >> Filled in for ESX VMAPI =item C<< vmPathName >> Filled in for ESX VMAPI =item C<< guestFullName >> Filled in for ESX VMAPI =item C<< hostName >> Filled in for at least ESX VMAPI and Xen XAPI =item C<< ipAddress >> Filled in for ESX VMAPI =item C<< toolsStatus >> Filled in for ESX VMAPI =item C<< overallCpuUsage >> Filled in for ESX VMAPI =item C<< hostMemoryUsage >> Filled in for ESX VMAPI =item C<< guestMemoryUsage >> Filled in for ESX VMAPI =item C<< overallStatus >> Filled in for ESX VMAPI =item C<< cpuMax >> Filled in for Xen XAPI =item C<< dynamicMaxMemorySizeMB >> Filled in for Xen XAPI =item C<< dynamicMinMemorySizeMB >> Filled in for Xen XAPI =item C<< staticMaxMemorySizeMB >> Filled in for Xen XAPI =item C<< staticMinMemorySizeMB >> Filled in for Xen XAPI =item C<< isSnapshot >> Filled in for Xen XAPI =item C<< virtualBlockDevices >> Filled in for Xen XAPI =item C<< snapshots >> Filled in for Xen XAPI =back =cut package NACL::CS::HyperV::VirtualMachine; use strict; use warnings; use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use Data::Dumper; use Params::Validate qw (validate); use NACL::ComponentUtils qw (_dump_one); use NACL::Exceptions::NoElementsFound qw(:try); use base 'NACL::CS::ComponentState::HyperV'; use Class::MethodMaker [ # Common to both Xen and ESX scalar => "vm_name", scalar => "numCpu", scalar => "powerState", scalar => "template", scalar => "guestId", scalar => "hostName", # ESX Specific scalar => "memorySizeMB", scalar => "numVirtualDisks", scalar => "vmPathName", scalar => "guestFullName", scalar => "ipAddress", scalar => "toolsStatus", scalar => "overallCpuUsage", scalar => "hostMemoryUsage", scalar => "guestMemoryUsage", scalar => "overallStatus", # Xen Specific scalar => "cpuMax", scalar => "dynamicMaxMemorySizeMB", scalar => "dynamicMinMemorySizeMB", scalar => "staticMaxMemorySizeMB", scalar => "staticMinMemorySizeMB", scalar => "isSnapshot", array => "virtualBlockDevices", array => "snapshots", ]; =head1 METHODS =head2 fetch my $vm_state = NACL::CS::HyperV::VirtualMachine->fetch(command_interface=>$ci,...); my @vm_states = NACL::CS::HyperV::VirtualMachine->fetch(command_interface=>$ci,...); see L. =cut sub fetch { $Log->enter() if $may_enter; my ($pkg, @args) = @_; my @state_objs = $pkg->SUPER::fetch( @args, choices => [ { method => "_fetch_vm_info_esx", interface => 'VMAPI', set => 'ESX' }, { method => "_fetch_vm_info_xen", interface => 'XAPI', set => 'Xen' }, ], exception_text => 'No matching virtual machines found' ); $Log->exit() if $may_exit; return wantarray ? @state_objs : $state_objs[0]; } ## end sub fetch sub _fetch_vm_info_esx { $Log->enter() if $may_enter; my ($pkg, @args) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my $filter = $opts{filter}; my $requested_fields = $opts{requested_fields}; my $command_interface = $opts{command_interface}; my $deleted_filter = $pkg->_remove_relational_regex_filters( filter => $filter, requested_fields => $requested_fields ); my @state_objs; my $vms = $command_interface->virtualmachines(); foreach my $vm ( @{$vms} ) { my $configs = $vm->summary->config; my $guest = $vm->summary->guest; my $quickstats = $vm->summary->quickStats; my $obj = $pkg->new( command_interface => $opts{command_interface}, vm_name => $vm->config->name, ); $obj->numCpu( $configs->numCpu ); $obj->powerState( $vm->runtime->powerState->val ); $obj->memorySizeMB( $configs->memorySizeMB ); $obj->numVirtualDisks( $configs->numVirtualDisks ); $obj->template( $configs->template ); $obj->vmPathName( $configs->vmPathName ); $obj->guestFullName( $guest->guestFullName ); $obj->guestId( $guest->guestId ); $obj->hostName( $guest->hostName ); $obj->ipAddress( $guest->ipAddress ); $obj->toolsStatus( $guest->toolsStatus ); $obj->overallCpuUsage( $quickstats->overallCpuUsage ); $obj->hostMemoryUsage( $quickstats->hostMemoryUsage ); $obj->guestMemoryUsage( $quickstats->guestMemoryUsage ); $obj->overallStatus( $vm->summary->overallStatus->val ); push @state_objs, $obj; } $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_vm_info sub _fetch_vm_info_xen { $Log->enter() if $may_enter; my ($pkg, @args) = @_; my %opts = validate @args, $pkg->_fetch_backend_validate_spec(); my $apiset = $opts{apiset}; my $filter = $opts{filter}; my $requested_fields = $opts{requested_fields}; my $command_interface = $opts{command_interface}; my $deleted_filter = $pkg->_remove_relational_regex_filters( filter => $filter, requested_fields => $requested_fields ); my @state_objs; my @vms; if ($filter->{vm_name}) { my $vm_ref = $command_interface->_get_vm_ref( vm_name => $filter->{vm_name}, apiset => $apiset, ); push(@vms, $vm_ref); } else { @vms = @{$command_interface->virtualmachines()}; } foreach my $vm ( @vms ) { my $vm_record; $pkg->get_ref(ref => $vm, ref_of => "VM", apiset => $apiset, record => \$vm_record); if (! defined($vm_record)){ $Log->exit() if $may_exit; return; } if ($vm_record->{name_label} !~ /Control domain on host/) { my $obj = $pkg->new( command_interface => $opts{command_interface}, vm_name => $vm_record->{name_label}, ); $obj->powerState( $vm_record->{power_state} ); $obj->numCpu( $vm_record->{VCPUs_at_startup} ); $obj->cpuMax( $vm_record->{VCPUs_max} ); $obj->virtualBlockDevices( $vm_record->{VBDs} ); $obj->dynamicMaxMemorySizeMB( $vm_record->{memory_dynamic_max} ); $obj->dynamicMinMemorySizeMB( $vm_record->{memory_dynamic_min} ); $obj->staticMaxMemorySizeMB( $vm_record->{memory_static_max} ); $obj->staticMinMemorySizeMB( $vm_record->{memory_static_min} ); $obj->isSnapshot( $vm_record->{is_a_snapshot} ); $obj->template( $vm_record->{is_a_template} ); $obj->guestId( $vm_record->{uuid} ); # For VMs that are snapshots it might be possible that it doesnt have any resident host. # In such cases make "OpaqueRef:NULL" as default resident_host for the VM. my $resident_host = 'OpaqueRef:NULL'; if ($vm_record->{resident_on} ne 'OpaqueRef:NULL') { $resident_host = $apiset->simple_request("host.get_name_label", $vm_record->{resident_on})->get_parsed_output()->[0]; } $obj->hostName($resident_host); $obj->snapshots( $vm_record->{snapshots} ); push @state_objs, $obj; } } $Log->exit() if $may_exit; return @state_objs; } ## end sub _fetch_vm_info 1;