Changeset 1649
- Timestamp:
- 07/01/08 23:42:30 (3 months ago)
- Files:
-
- honeyclient/trunk/etc/honeyclient.xml (modified) (3 diffs)
- honeyclient/trunk/lib/HoneyClient/Manager/VM.pm (modified) (8 diffs)
- honeyclient/trunk/t/honeyclient_manager_vm.t (modified) (3 diffs)
- honeyclient/trunk/t/test_vm-livecd (copied) (copied from honeyclient/trunk/t/test_vm)
- honeyclient/trunk/t/test_vm-livecd/install-x86-minimal-2007.0-r1.iso (added)
- honeyclient/trunk/t/test_vm-livecd/nvram (modified) (previous)
- honeyclient/trunk/t/test_vm-livecd/winXPPro.vmx (modified) (3 diffs)
- honeyclient/trunk/t/test_vm/winXPPro.vmx (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
honeyclient/trunk/etc/honeyclient.xml
r1643 r1649 319 319 <VM> 320 320 <master_vm_config description="The full absolute path to the VM configuration file on the host system that will be used by all subsequent cloned VMs."> 321 /vm/masters/Agent.Master-4 1-IE6/winXPPro.cfg321 /vm/masters/Agent.Master-42-IE6/winXPPro.cfg 322 322 </master_vm_config> 323 323 <port description="The TCP port number that the SOAP server of the VM daemon will listen on for requests. Note: This port should be unique and not already be used by other modules, services, or daemons running on the host system." default="7627"> … … 342 342 26 343 343 </vm_id_length> 344 <dhcp_l og description="The absolute path to the file that contains the DHCP logs, when a new VM gets a DHCP lease from the VMware Server." default="/var/log/messages">345 / var/log/messages346 </dhcp_l og>344 <dhcp_leases description="The absolute path to the file that contains the DHCP leases, when a new VM gets a DHCP lease from the VMware Server." default="/etc/vmware/vmnet1/dhcpd/dhcpd.leases"> 345 /etc/vmware/vmnet1/dhcpd/dhcpd.leases 346 </dhcp_leases> 347 347 <max_connect_retries description="When the VMware Server attempts to connect to any VM, it will repeatedly attempt to connect to the VM if the first attempt fails, for a maximum number of times specified by this value. Generally, this value should not be changed, unless the host system has an exceptionally slow disk - in which case, increasing this value may help." default="5"> 348 348 5 … … 367 367 t/test_vm/winXPPro.vmx 368 368 </test_vm_config> 369 <test_vm_config_livecd description="The relative path to the (livecd) test VM, that's used during unit testing." default="t/test_vm-livecd/winXPPro.vmx"> 370 t/test_vm-livecd/winXPPro.vmx 371 </test_vm_config_livecd> 369 372 </Test> 370 373 </VM> honeyclient/trunk/lib/HoneyClient/Manager/VM.pm
r1590 r1649 460 460 use DateTime::HiRes; 461 461 462 # Make sure Fcntl loads. 463 BEGIN { use_ok('Fcntl', qw(O_RDONLY)) or diag("Can't load Fcntl package. Check to make sure the package library is correctly listed within the path."); } 464 require_ok('Fcntl'); 465 use Fcntl qw(O_RDONLY); 462 # Make sure Text::DHCPLeases loads. 463 BEGIN { use_ok('Text::DHCPLeases') or diag("Can't load Text::DHCPLeases package. Check to make sure the package library is correctly listed within the path."); } 464 require_ok('Text::DHCPLeases'); 465 use Text::DHCPLeases; 466 467 # Make sure DateTime::Format::Natural loads. 468 BEGIN { use_ok('DateTime::Format::Natural') or diag("Can't load DateTime::Format::Natural package. Check to make sure the package library is correctly listed within the path."); } 469 require_ok('DateTime::Format::Natural'); 470 use DateTime::Format::Natural; 466 471 467 472 # Make sure Config::General loads. … … 585 590 use File::Copy::Recursive qw(dircopy pathrmdir); 586 591 use File::Basename qw(dirname basename); 587 use Tie::File;588 use Fcntl qw(O_RDONLY);589 592 use Config::General; 593 594 # Include DHCP Lease Analysis Libraries 595 use Text::DHCPLeases; 596 use DateTime::Format::Natural; 590 597 591 598 # Include Thread Libraries … … 668 675 our $VM_ID_LENGTH : shared = getVar(name => "vm_id_length"); 669 676 670 # The log file that contains DHCP lease log entries.671 our $DHCP_L OGFILE : shared = getVar(name => "dhcp_log");677 # The file that contains DHCP leases. 678 our $DHCP_LEASES : shared = getVar(name => "dhcp_leases"); 672 679 673 680 ####################################################################### … … 2849 2856 namespace => "HoneyClient::Manager::VM"); 2850 2857 my ($stub, $som, $URL); 2851 my $testVM = $ENV{PWD} . "/" . getVar(name => "test_vm_config ",2858 my $testVM = $ENV{PWD} . "/" . getVar(name => "test_vm_config_livecd", 2852 2859 namespace => "HoneyClient::Manager::VM::Test"); 2853 2860 … … 2865 2872 $som = $stub->startVM(config => $testVM); 2866 2873 2867 # Wait 10 seconds, for the DHCP server to give the testVM2874 # Wait 240 seconds, for the DHCP server to give the testVM 2868 2875 # a DHCP lease. 2869 sleep ( 10);2876 sleep (240); 2870 2877 2871 2878 # Get the IP address of the test VM. … … 2944 2951 } 2945 2952 2946 my @logArray = undef; 2947 my $match = undef; 2953 # Now, let's determine the IP address from the DHCP leases file. 2948 2954 my $IP = undef; 2949 2955 2950 if (!tie(@logArray, 'Tie::File', $DHCP_LOGFILE, mode => O_RDONLY)) { 2951 $LOG->warn("Could not open DHCP log file ($DHCP_LOGFILE)."); 2952 die SOAP::Fault->faultcode(__PACKAGE__ . "->getIPaddrVM()") 2953 ->faultstring("Could not open DHCP log file ($DHCP_LOGFILE)."); 2954 } 2955 2956 for (@logArray) { 2957 # Look for all lines that have the VM's MAC address and the keyword 2958 # DHCPACK or DHCPOFFER on it. 2959 if ((/DHCPACK/ || /DHCPOFFER/) && /$args{'mac_address'}/) { 2960 $match = $_; 2961 $match =~ s/^.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*$/$1/; 2962 if (defined($match) and ($match ne "")) { 2963 $IP = $match; 2964 } 2965 } 2966 } 2967 untie @logArray; 2956 # Create a new DHCP leases parser. 2957 my $leases = Text::DHCPLeases->new(file => $DHCP_LEASES); 2958 2959 # Create a new DateTime parser. 2960 my $parser = DateTime::Format::Natural->new( 2961 lang => 'en', 2962 format => 'yyyy/mm/dd', 2963 prefer_future => 0, 2964 time_zone => 'UTC', 2965 ); 2966 2967 # Current date/time. 2968 my $dt_now = $parser->parse_datetime("now"); 2969 2970 # Helper function designed to parse DHCP lease datetime objects. 2971 sub parse_datetime { 2972 my ($parser,$string) = @_; 2973 # Remove the beginning weekday number. 2974 $string =~ s/\d (.*)/$1/; 2975 # Return a parsed DateTime object. 2976 return $parser->parse_datetime($string); 2977 } 2978 2979 # Iterate through the lease objects. 2980 foreach my $obj ($leases->get_objects()) { 2981 # Only look for leases. 2982 next if ($obj->type() ne 'lease'); 2983 2984 # Only look for leases that haven't expired. 2985 next if (($dt_now < parse_datetime($parser,$obj->starts)) || 2986 ($dt_now > parse_datetime($parser,$obj->ends))); 2987 2988 if ($obj->mac_address eq $args{'mac_address'}) { 2989 $IP = $obj->name(); 2990 last; 2991 } 2992 } 2968 2993 2969 2994 return ($IP); … … 4433 4458 4434 4459 # Perform the snapshot operation... 4435 # XXX: Do this synchronously instead of asynchronously, since we've had problems running4436 # this code in multi-threaded environments.4460 # XXX: Do this synchronously instead of asynchronously, since we've had problems running 4461 # this code in multi-threaded environments. 4437 4462 # # Since this may take awhile, we perform the remaining operations in a child thread. 4438 4463 # my $thread = async { … … 4939 4964 threads, threads::shared, Thread::Queue, Thread::Semaphore, perlthrtut 4940 4965 4941 POSIX, File::Copy, File::Copy::Recursive, File::Basename, T ie::File4966 POSIX, File::Copy, File::Copy::Recursive, File::Basename, Text::DHCPLeases 4942 4967 4943 4968 Apache::SessionX::General::MD5 honeyclient/trunk/t/honeyclient_manager_vm.t
r1590 r1649 117 117 use DateTime::HiRes; 118 118 119 # Make sure Fcntl loads. 120 BEGIN { use_ok('Fcntl', qw(O_RDONLY)) or diag("Can't load Fcntl package. Check to make sure the package library is correctly listed within the path."); } 121 require_ok('Fcntl'); 122 use Fcntl qw(O_RDONLY); 119 # Make sure Text::DHCPLeases loads. 120 BEGIN { use_ok('Text::DHCPLeases') or diag("Can't load Text::DHCPLeases package. Check to make sure the package library is correctly listed within the path."); } 121 require_ok('Text::DHCPLeases'); 122 use Text::DHCPLeases; 123 124 # Make sure DateTime::Format::Natural loads. 125 BEGIN { use_ok('DateTime::Format::Natural') or diag("Can't load DateTime::Format::Natural package. Check to make sure the package library is correctly listed within the path."); } 126 require_ok('DateTime::Format::Natural'); 127 use DateTime::Format::Natural; 123 128 124 129 # Make sure Config::General loads. … … 761 766 namespace => "HoneyClient::Manager::VM"); 762 767 my ($stub, $som, $URL); 763 my $testVM = $ENV{PWD} . "/" . getVar(name => "test_vm_config ",768 my $testVM = $ENV{PWD} . "/" . getVar(name => "test_vm_config_livecd", 764 769 namespace => "HoneyClient::Manager::VM::Test"); 765 770 … … 777 782 $som = $stub->startVM(config => $testVM); 778 783 779 # Wait 10 seconds, for the DHCP server to give the testVM784 # Wait 240 seconds, for the DHCP server to give the testVM 780 785 # a DHCP lease. 781 sleep ( 10);786 sleep (240); 782 787 783 788 # Get the IP address of the test VM. honeyclient/trunk/t/test_vm-livecd/winXPPro.vmx
r1008 r1649 8 8 ide0:0.mode = "persistent" 9 9 ide1:0.present = "TRUE" 10 ide1:0.fileName = " auto detect"11 ide1:0.deviceType = " atapi-cdrom"10 ide1:0.fileName = "install-x86-minimal-2007.0-r1.iso" 11 ide1:0.deviceType = "cdrom-image" 12 12 floppy0.fileName = "/dev/fd0" 13 13 usb.present = "FALSE" … … 21 21 powerType.reset = "soft" 22 22 23 ide1:0.startConnected = " FALSE"23 ide1:0.startConnected = "TRUE" 24 24 floppy0.startConnected = "FALSE" 25 25 redoLogDir = "." 26 26 27 uuid.location = "56 4d a4 e9 36 ce 79 71-8e bc 38 d2 b8 3e ed ea"28 uuid.bios = "56 4d a4 e9 36 ce 79 71-8e bc 38 d2 b8 3e ed ea"27 uuid.location = "56 4d 67 c7 da f3 e5 cd-5a dc c8 79 9d 00 35 81" 28 uuid.bios = "56 4d 67 c7 da f3 e5 cd-5a dc c8 79 9d 00 35 81" 29 29 30 30 Ethernet0.present = "TRUE" 31 31 32 32 Ethernet0.addressType = "generated" 33 ethernet0.generatedAddress = "00:0c:29: 3e:ed:ea"33 ethernet0.generatedAddress = "00:0c:29:00:35:81" 34 34 ethernet0.generatedAddressOffset = "0" 35 35 … … 40 40 41 41 Ethernet0.connectionType = "hostonly" 42 43 uuid.action = "create" honeyclient/trunk/t/test_vm/winXPPro.vmx
r1008 r1649 1 1 #!/usr/bin/vmware 2 3 Ethernet0.addressType = "generated" 4 Ethernet0.connectionType = "hostonly" 5 Ethernet0.present = "TRUE" 6 Ethernet0.startConnected = "TRUE" 2 7 config.version = "7" 3 virtualHW.version = "3" 4 scsi0.present = "TRUE" 5 memsize = "256" 6 ide0:0.present = "TRUE" 8 displayName = "testVM" 9 ethernet0.generatedAddress = "00:0c:29:e2:08:e8" 10 ethernet0.generatedAddressOffset = "0" 11 floppy0.fileName = "/dev/fd0" 12 floppy0.startConnected = "FALSE" 13 guestOS = "winxppro" 14 ide0:0.deviceType = "ata-hardDisk" 7 15 ide0:0.fileName = "winXPPro.vmdk" 8 16 ide0:0.mode = "persistent" 17 ide0:0.present = "TRUE" 18 ide0:0.redo = "" 19 ide1:0.deviceType = "atapi-cdrom" 20 ide1:0.fileName = "auto detect" 9 21 ide1:0.present = "TRUE" 10 ide1:0. fileName = "auto detect"11 ide1:0.deviceType = "atapi-cdrom"12 floppy0.fileName = "/dev/fd0"13 usb.present = "FALSE"14 displayName = "testVM"15 guestOS = "winxppro"22 ide1:0.startConnected = "FALSE" 23 memsize = "256" 24 powerType.powerOff = "soft" 25 powerType.powerOn = "soft" 26 powerType.reset = "soft" 27 powerType.suspend = "soft" 16 28 priority.grabbed = "normal" 17 29 priority.ungrabbed = "normal" 18 powerType.powerOff = "soft"19 powerType.powerOn = "soft"20 powerType.suspend = "soft"21 powerType.reset = "soft"22 23 ide1:0.startConnected = "FALSE"24 floppy0.startConnected = "FALSE"25 30 redoLogDir = "." 26 27 uuid.location = "56 4d a4 e9 36 ce 79 71-8e bc 38 d2 b8 3e ed ea" 28 uuid.bios = "56 4d a4 e9 36 ce 79 71-8e bc 38 d2 b8 3e ed ea" 29 30 Ethernet0.present = "TRUE" 31 32 Ethernet0.addressType = "generated" 33 ethernet0.generatedAddress = "00:0c:29:3e:ed:ea" 34 ethernet0.generatedAddressOffset = "0" 35 36 Ethernet0.startConnected = "TRUE" 37 38 ide0:0.redo = "" 39 ide0:0.deviceType = "ata-hardDisk" 40 41 Ethernet0.connectionType = "hostonly" 31 scsi0.present = "TRUE" 32 usb.present = "FALSE" 33 uuid.bios = "56 4d 32 85 a0 59 c7 f7-64 37 b9 78 9f e2 08 e8" 34 uuid.location = "56 4d 32 85 a0 59 c7 f7-64 37 b9 78 9f e2 08 e8" 35 virtualHW.version = "3"
