home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2007 April / PCpro_2007_04.ISO / files / usb / VMware-server-installer101.exe / enumerate.pl < prev    next >
Encoding:
Perl Script  |  2006-08-09  |  2.1 KB  |  69 lines

  1. #!/usr/bin/perl -w
  2. #
  3. # Copyright 1998 VMware, Inc.  All rights reserved. -- VMware Confidential
  4. #
  5. # enumerate.pl
  6. #
  7. # This script lists all of the registered virtual machines
  8. # on the server specified by hostname.
  9. #
  10. # usage:
  11. #   enumerate.pl <hostname> <user> <password>
  12. #
  13.  
  14. BEGIN {
  15.    if ($^O eq "MSWin32") {
  16.       @INC = (
  17.          # Set the path to your VmPerl Scripting directory if different
  18.          'C:\Program Files\VMware\VMware VmPerl Scripting API\perl5\site_perl\5.005',
  19.          'C:\Program Files\VMware\VMware VmPerl Scripting API\perl5\site_perl\5.005\MSWin32-x86');
  20.    }
  21. }
  22.  
  23. use VMware::VmPerl;
  24. use VMware::VmPerl::Server;
  25. use VMware::VmPerl::ConnectParams;
  26. use strict;
  27.  
  28. my ($server_name, $user, $passwd) = @ARGV;
  29.  
  30. # Use the default port of 902.  Change this if your port is different.
  31. my $port = 902;
  32.  
  33. # Create a new VMware::VmPerl::Server to connect to the server
  34. # To connect to the remote server, use the following line:
  35. my $connect_params = 
  36.    VMware::VmPerl::ConnectParams::new($server_name,$port,$user,$passwd);
  37.  
  38. # To connect to a local server, you would use the following line:
  39. # my $connect_params = 
  40. #    VMware::VmPerl::ConnectParams::new(undef,$port,$user,$passwd);
  41.  
  42. # To connect to a local server as the current user, you would use the 
  43. # following line:
  44. # my $connect_params = VMware::VmPerl::ConnectParams::new();
  45.  
  46.  
  47. # Establish a persistent connection with server
  48. my $server = VMware::VmPerl::Server::new();
  49. if (!$server->connect($connect_params)) {
  50.    my ($error_number, $error_string) = $server->get_last_error();
  51.    die "Could not connect to server: Error $error_number: $error_string\n";
  52. }
  53.  
  54. print "\nThe following virtual machines are registered:\n";
  55.  
  56. # Obtain a list containing every config file path registered with the server.
  57. my @list = $server->registered_vm_names();
  58. if (!defined($list[0])) {
  59.    my ($error_number, $error_string) = $server->get_last_error();
  60.    die "Could not get list of VMs from server: Error $error_number: ".
  61.        "$error_string\n";
  62. }
  63.  
  64. print "$_\n" foreach (@list);
  65.  
  66. # Destroys the server object, thus disconnecting from the server.
  67. undef $server;
  68.  
  69.