Changeset 602

Show
Ignore:
Timestamp:
06/21/07 17:30:17 (1 year ago)
Author:
kindlund
Message:

Added start() support to Clone object.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/trunk/lib/HoneyClient/Manager/VM/Clone.pm

    r597 r602  
    293293# The global variable, used to count the number of 
    294294# Clone objects that have been created. 
    295 our $OBJECT_COUNT = 0; 
     295our $OBJECT_COUNT : shared = 0; 
    296296 
    297297=pod 
     
    333333    # internal variable should never be modified externally.) 
    334334    _clone_vm_config => undef, 
     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, 
    335356); 
    336357 
     
    397418# mechanism. 
    398419sub DESTROY { 
     420    # Get the object. 
     421    my $self = shift; 
     422 
     423    if (defined($self->{'_clone_vm_config'})) { 
     424        my $som = $self->{'_vm_handle'}->getMACaddrVM(config => $self->{'_clone_vm_config'}); 
     425        if (!$som->result()) { 
     426            $LOG->error("Unable to suspend VM (" . $self->{'_clone_vm_config'} . ")."); 
     427        } 
     428    } 
     429 
    399430    # Decrement our global object count. 
    400431    $OBJECT_COUNT--; 
     
    591622 
    592623sub start { 
     624 
    593625    # Extract arguments. 
    594626    my ($self, %args) = @_; 
     
    628660        # If the VM isn't registered yet, wait before trying again. 
    629661        if (!defined($ret) or !$ret) { 
    630             sleep (2); 
     662            sleep ($self->{'_retry_period'}); 
    631663        } 
    632664    } 
     
    634666    # Once registered, check if the VM is ON yet. 
    635667    $ret = undef; 
     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; 
    636725} 
    637726