NAME

Sys::Detect::Virtualization - Detect if a UNIX system is running as a virtual machine

VERSION

Version 0.107

SYNOPSIS

    use Sys::Detect::Virtualization;

    my $detector = eval { Sys::Detect::Virtualization->new() };
    if( $@ ) {
	print "Detector may not be supported for your platform.  Error was: $@\n";
    }

    my @found = $detector->detect();
    if( @found ) {
	print "Possible virtualized system.  May be running under:\n";
	print "\t$_\n" for @found;
    }

DESCRIPTION

This module attempts to detect whether or not a system is running as a guest under virtualization, using various heuristics.

METHODS

Class Methods

new ( $args )

Construct a new detector object. On success, returns the object. On failure, dies.

This constructor will fail if the system is not running a supported OS. Currently, only Linux is supported.

$args is an optional hash reference containing additional arguments for the constructor. Currently supported are:

verbose

Set to 1 if we should output verbose debugging, 0 otherwise. Defaults to 0.

ignore_host

Set to 1 if we should report no virtualization if a virtualization host (as opposed to guest) is detected. Defaults to 1.

Instance Methods

detect ( )

Runs detection heuristics. Returns a list of possible virtualization systems, or an empty list if none were detected.

Possible hits are returned in order of most likely to least likely.

Note that the failure to detect does NOT mean the system is not virtualized -- it simply means we couldn't detect it.

guess ( )

Runs detection heuristics and returns a single answer based on the "best guess" available.

Currently, this is defined as the virt platform with the most heuristic hits.

Internal Methods

You probably shouldn't ever need to call these

get_detectors ( )

Returns a list of all detector subroutines for the given instance.

_find_bin ( $command )

Returns full path to given command by searching $ENV{PATH}. If not present in the path variable, the directories /usr/sbin, /usr/bin, /sbin, and /bin are appended.

_fh_apply_patterns ( $fh, $patterns )

Check, linewise, the data from $fh against the patterns in $patterns.

$patterns is a listref read pairwise. The first item of each pair is the pattern, and the second item of each pair is a list of names of virt solutions detected by the pattern.

_check_command_output ( $command, $patterns )

Check, linewise, the output of $command against the patterns in $patterns.

$patterns is a listref read pairwise. The first item of each pair is the pattern, and the second item of each pair is the name of the virt solution detected by the pattern.

_check_file_contents ( $fileglob, $patterns )

Check, linewise, the content of each filename in $fileglob against the patterns in $patterns.

$fileglob is a glob that returns zero or more filenames.

$patterns is a listref read pairwise. The first item of each pair is the pattern, and the second item of each pair is the name of the virt solution detected by the pattern.

_check_path_exists ( $paths )

Checks for the existence of each path in $paths.

$paths is a listref read pairwise. The first item of each pair is the path name, and the second item of each pair is the name of the virt solution detected by the existence of that $path.

AUTHOR

Dave O'Neill, <dmo@dmo.ca>

BUGS

Known issues:

  • No support for non-Linux platforms. Feel free to contribute an appropriate Sys::Detect::Virtualization::foo class for your platform.

  • No weighting of tests so that high-confidence checks can be done first. Patches welcome.

Please report any bugs or feature requests to bug-sys-detect-virtualization at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sys-Detect-Virtualization. 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 Sys::Detect::Virtualization

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright (C) 2009 Roaring Penguin Software Inc.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.