Convert some more files to GPLv3.
[jra/samba/.git] / source4 / selftest / win / vm_load_snapshot.pl
1 #!/usr/bin/perl -w
2
3 # A perl script to connect to a VMware server and revert a VM snapshot.
4 # Copyright Brad Henry <brad@samba.org> 2006
5 # Released under the GNU GPL version 3 or later.
6
7 use VMHost;
8
9 sub check_error {
10 my $vm = VMHost;
11         my $custom_err_str = "";
12         ($vm, $custom_err_str) = @_;
13
14         my ($err_code, $err_str) = $vm->error;
15         if ($err_code != 0) {
16                 undef $vm;
17                 die $custom_err_str . "Returned $err_code: $err_str.\n";
18         }
19 }
20
21 # Read in parameters from environment.
22 my $vm_cfg_path = $ENV{'VM_CFG_PATH'};
23 my $host_server_name = $ENV{'HOST_SERVER_NAME'};
24 my $host_server_port = $ENV{'HOST_SERVER_PORT'};
25 if (!defined($host_server_port)) {
26         $host_server_port = 902;
27 }
28
29 my $host_username = $ENV{'HOST_USERNAME'};
30 my $host_password = $ENV{'HOST_PASSWORD'};
31 my $guest_admin_username = $ENV{'GUEST_ADMIN_USERNAME'};
32 my $guest_admin_password = $ENV{'GUEST_ADMIN_PASSWORD'};
33
34 my $vm = VMHost;
35
36 $vm->host_connect($host_server_name, $host_server_port, $host_username,
37                         $host_password, $vm_cfg_path, $guest_admin_username,
38                         $guest_admin_password);
39 check_error($vm, "Error in \$vm->host_connect().\n");
40
41 $vm->revert_snapshot();
42 check_error($vm, "Error in \$vm->revert_snapshot().\n");
43
44 undef $vm;
45
46 exit 0;