Changeset 1590
- Timestamp:
- 05/27/08 17:17:07 (6 months ago)
- Files:
-
- honeyclient/trunk/lib/HoneyClient/Manager/VM.pm (modified) (7 diffs)
- honeyclient/trunk/t/honeyclient_manager_vm.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
honeyclient/trunk/lib/HoneyClient/Manager/VM.pm
r1577 r1590 465 465 use Fcntl qw(O_RDONLY); 466 466 467 # Make sure Config::General loads. 468 BEGIN { use_ok('Config::General') or diag("Can't load Config::General package. Check to make sure the package library is correctly listed within the path."); } 469 require_ok('Config::General'); 470 use Config::General; 471 467 472 # Make sure VMware::VmPerl loads. 468 473 BEGIN { use_ok('VMware::VmPerl', qw(VM_EXECUTION_STATE_ON VM_EXECUTION_STATE_OFF VM_EXECUTION_STATE_STUCK VM_EXECUTION_STATE_SUSPENDED)) or diag("Can't load VMware::VmPerl package. Check to make sure the package library is correctly listed within the path."); } … … 582 587 use Tie::File; 583 588 use Fcntl qw(O_RDONLY); 589 use Config::General; 584 590 585 591 # Include Thread Libraries … … 2613 2619 $vmSemaphore->down(); 2614 2620 2615 # Set the displayName within the config file on disk... 2616 if (!tie(@configArray, 'Tie::File', $args{'config'})) { 2621 my $config_obj = undef; 2622 eval { 2623 # Construct a new configuration object. 2624 $config_obj = new Config::General($args{'config'}); 2625 }; 2626 if ($@) { 2617 2627 # Unlock VM early, if failed. 2618 2628 $vmSemaphore->up(); … … 2621 2631 ->faultstring("Could not set name of VM ($args{'config'})."); 2622 2632 } 2623 2624 for (@configArray) { 2625 s/^displayName =.*$/displayName = "$args{'name'}"/g; 2626 } 2627 untie @configArray; 2628 2633 # Parse all the data. 2634 my %raw_config = $config_obj->getall; 2635 2636 # Sort the configuration. 2637 my @sorted_keys = (sort keys %raw_config); 2638 2639 # Adjust the configuration. 2640 # Set the displayName within the config file on disk... 2641 $raw_config{'displayName'} = $args{'name'}; 2642 2643 # Save the new configuration. 2644 my $OUTPUT_FILE = new IO::File($args{'config'}, "w"); 2645 print $OUTPUT_FILE "#!/usr/bin/vmware\n\n"; 2646 foreach my $key (@sorted_keys) { 2647 print $OUTPUT_FILE $key . " = \"" . $raw_config{$key} . "\"\n"; 2648 } 2649 $OUTPUT_FILE->close(); 2650 2629 2651 # Unlock the VM. 2630 2652 $vmSemaphore->up(); … … 3793 3815 $vmSemaphore->down(); 3794 3816 3795 if (!tie(@configArray, 'Tie::File', $args{'config'})) { 3817 my $config_obj = undef; 3818 eval { 3819 # Construct a new configuration object. 3820 $config_obj = new Config::General($args{'config'}); 3821 }; 3822 if ($@) { 3796 3823 # Unlock VM early, if failed. 3797 3824 $vmSemaphore->up(); … … 3800 3827 ->faultstring("Could not set Master VM ($args{'config'})."); 3801 3828 } 3802 3803 for (@configArray) { 3804 # Make sure the master VM configuration version is "7", since 3805 # versions 8 and higher have marked the undoable mode operation 3806 # as deprecated, as it's implemented differently. 3807 s/^config.version.*$/config.version = "7"/g; 3829 # Parse all the data. 3830 my %raw_config = $config_obj->getall; 3831 3832 # Sort the configuration. 3833 my @sorted_keys = (sort keys %raw_config); 3834 3835 # Adjust the configuration. 3836 # Make sure the master VM configuration version is "7", since 3837 # versions 8 and higher have marked the undoable mode operation 3838 # as deprecated, as it's implemented differently. 3839 $raw_config{'config.version'} = 7; 3840 foreach my $key (@sorted_keys) { 3808 3841 # Switch all virtual disks to undoable mode... 3809 s/^(.*)\.mode = "persistent"$/$1\.mode = "undoable"/g; 3810 # Make sure all *.vmdk files are specified with absolute paths... 3811 s/^(.*)\.fileName = "(.*\/)*(.*\.vmdk)"$/$1\.fileName = \"$srcDir\/$3\"/g; 3812 } 3813 untie @configArray; 3814 3842 if ($key =~ /^.*\.mode/) { 3843 $raw_config{$key} = "undoable"; 3844 } elsif ($key =~ /^.*\.fileName/) { 3845 # Make sure all *.vmdk files are specified with absolute paths... 3846 $raw_config{$key} =~ s/^(.*\/)*(.*\.vmdk)$/$srcDir\/$2/g; 3847 } 3848 } 3849 3850 # Save the new configuration. 3851 my $OUTPUT_FILE = new IO::File($args{'config'}, "w"); 3852 print $OUTPUT_FILE "#!/usr/bin/vmware\n\n"; 3853 foreach my $key (@sorted_keys) { 3854 print $OUTPUT_FILE $key . " = \"" . $raw_config{$key} . "\"\n"; 3855 } 3856 $OUTPUT_FILE->close(); 3857 3815 3858 # Unlock the VM. 3816 3859 $vmSemaphore->up(); … … 4669 4712 !exists($args{'snapshot_file'}) || 4670 4713 !defined($args{'snapshot_file'})) { 4671 my @configArray = undef; 4672 unless (tie(@configArray, 'Tie::File', $args{'config'})) { 4714 4715 my $config_obj = undef; 4716 eval { 4717 # Construct a new configuration object. 4718 $config_obj = new Config::General($args{'config'}); 4719 }; 4720 if ($@) { 4673 4721 $LOG->warn("Could not read VM configuration ($args{'config'})."); 4674 4722 die SOAP::Fault->faultcode(__PACKAGE__ . "->revertVM()") 4675 4723 ->faultstring("Could not read VM configuration ($args{'config'})."); 4676 4724 } 4677 for (@configArray) { 4725 # Parse all the data. 4726 my %raw_config = $config_obj->getall; 4727 4728 # Sort the configuration. 4729 my @sorted_keys = (sort keys %raw_config); 4730 4731 # Adjust the configuration. 4732 foreach my $key (@sorted_keys) { 4678 4733 # Make sure all *.vmdk files are specified with absolute paths 4679 4734 # to a Master VM... 4680 if (/^(.*)\.fileName = "(.*\/)*(.*\.vmdk)"$/) { 4681 $masterConfig = "$2$configFile"; 4682 if ((!-d $2) || (dirname("$2/x") eq dirname("$vmDir/x"))) { 4683 $LOG->warn("Could not revert; specified VM is not a quick clone ($2$3)."); 4735 if (($key =~ /^.*\.fileName/) && ($raw_config{$key} =~ /^(.*\/)*(.*\.vmdk)$/)) { 4736 my $dir = defined($1) ? $1 : ""; 4737 my $file = defined($2) ? $2 : ""; 4738 $masterConfig = $dir . $configFile; 4739 if ((!-d $dir) || (dirname("$dir/x") eq dirname("$vmDir/x"))) { 4740 $LOG->warn("Could not revert; specified VM is not a quick clone (" . $args{'config'} . ")."); 4684 4741 die SOAP::Fault->faultcode(__PACKAGE__ . "->revertVM()") 4685 ->faultstring("Could not revert; specified VM is not a quick clone ( $2$3).");4742 ->faultstring("Could not revert; specified VM is not a quick clone (" . $args{'config'} . ")."); 4686 4743 } 4687 4744 } 4688 4745 } 4689 untie @configArray;4690 4746 } 4691 4747 honeyclient/trunk/t/honeyclient_manager_vm.t
r1499 r1590 122 122 use Fcntl qw(O_RDONLY); 123 123 124 # Make sure Config::General loads. 125 BEGIN { use_ok('Config::General') or diag("Can't load Config::General package. Check to make sure the package library is correctly listed within the path."); } 126 require_ok('Config::General'); 127 use Config::General; 128 124 129 # Make sure VMware::VmPerl loads. 125 130 BEGIN { use_ok('VMware::VmPerl', qw(VM_EXECUTION_STATE_ON VM_EXECUTION_STATE_OFF VM_EXECUTION_STATE_STUCK VM_EXECUTION_STATE_SUSPENDED)) or diag("Can't load VMware::VmPerl package. Check to make sure the package library is correctly listed within the path."); }
