| | 335 | |
|---|
| | 336 | # A variable containing the MAC address of the cloned VM's primary |
|---|
| | 337 | # interface. (This internal variable should never be modified |
|---|
| | 338 | # externally.) |
|---|
| | 339 | _clone_vm_mac => undef, |
|---|
| | 340 | |
|---|
| | 341 | # A variable containing the IP address of the cloned VM's primary |
|---|
| | 342 | # interface. (This internal variable should never be modified |
|---|
| | 343 | # externally.) |
|---|
| | 344 | _clone_vm_ip => undef, |
|---|
| | 345 | |
|---|
| | 346 | # A variable containing the name the cloned VM. |
|---|
| | 347 | # (This internal variable should never be modified |
|---|
| | 348 | # externally.) |
|---|
| | 349 | _clone_vm_name => undef, |
|---|
| | 350 | |
|---|
| | 351 | # A variable indicated how long the object should wait for |
|---|
| | 352 | # between subsequent retries to the HoneyClient::Manager::VM |
|---|
| | 353 | # daemon (in seconds). (This internal variable should never |
|---|
| | 354 | # be modified externally.) |
|---|
| | 355 | _retry_period => 2, |
|---|
| | 668 | while (!defined($ret) or ($ret != VM_EXECUTION_STATE_ON)) { |
|---|
| | 669 | $som = $self->{'_vm_handle'}->getStateVM(config => $self->{'_clone_vm_config'}); |
|---|
| | 670 | $ret = $som->result(); |
|---|
| | 671 | |
|---|
| | 672 | # If the VM isn't ON yet, wait before trying again. |
|---|
| | 673 | if (!defined($ret) or ($ret != VM_EXECUTION_STATE_ON)) { |
|---|
| | 674 | sleep ($self->{'_retry_period'}); |
|---|
| | 675 | } |
|---|
| | 676 | } |
|---|
| | 677 | |
|---|
| | 678 | # Now, get the VM's MAC address. |
|---|
| | 679 | $som = $self->{'_vm_handle'}->getMACaddrVM(config => $self->{'_clone_vm_config'}); |
|---|
| | 680 | $self->{'_clone_vm_mac'} = $som->result(); |
|---|
| | 681 | |
|---|
| | 682 | # Now, get the VM's name. |
|---|
| | 683 | $som = $self->{'_vm_handle'}->getNameVM(config => $self->{'_clone_vm_config'}); |
|---|
| | 684 | $self->{'_clone_vm_name'} = $som->result(); |
|---|
| | 685 | |
|---|
| | 686 | # Now, get the VM's IP address. |
|---|
| | 687 | $ret = undef; |
|---|
| | 688 | my $stubAgent = undef; |
|---|
| | 689 | my $logMsgPrinted = 0; |
|---|
| | 690 | while (!defined($self->{'_clone_vm_ip'}) or !defined($ret)) { |
|---|
| | 691 | $som = $self->{'_vm_handle'}->getIPaddrVM(config => $self->{'_clone_vm_config'}); |
|---|
| | 692 | $self->{'_clone_vm_ip'} = $som->result(); |
|---|
| | 693 | |
|---|
| | 694 | # If the VM isn't booted yet, wait before trying again. |
|---|
| | 695 | if (!defined($self->{'_clone_vm_ip'})) { |
|---|
| | 696 | sleep ($self->{'_retry_period'}); |
|---|
| | 697 | next; # skip further processing |
|---|
| | 698 | } elsif (!$logMsgPrinted) { |
|---|
| | 699 | $LOG->info("Created clone VM (" . $self->{'_clone_vm_name'} . ") using IP (" . |
|---|
| | 700 | $self->{'_clone_vm_ip'} . ") and MAC (" . $self->{'_clone_vm_mac'} . "."); |
|---|
| | 701 | $logMsgPrinted = 1; |
|---|
| | 702 | } |
|---|
| | 703 | |
|---|
| | 704 | # Now, try contacting the Agent. |
|---|
| | 705 | $stubAgent = getClientHandle(namespace => "HoneyClient::Agent", |
|---|
| | 706 | address => $self->{'_clone_vm_ip'}, |
|---|
| | 707 | fault_handler => undef); |
|---|
| | 708 | |
|---|
| | 709 | eval { |
|---|
| | 710 | $som = $stubAgent->getStatus(); |
|---|
| | 711 | $ret = $som->result(); |
|---|
| | 712 | }; |
|---|
| | 713 | # Clear returned state, if any fault occurs. |
|---|
| | 714 | if ($@) { |
|---|
| | 715 | $ret = undef; |
|---|
| | 716 | } |
|---|
| | 717 | |
|---|
| | 718 | # If the Agent daemon isn't responding yet, wait before trying again. |
|---|
| | 719 | if (!defined($ret)) { |
|---|
| | 720 | sleep ($self->{'_retry_period'}); |
|---|
| | 721 | } |
|---|
| | 722 | } |
|---|
| | 723 | |
|---|
| | 724 | return $self; |
|---|