Пример #1
0
    def __check_for_bsod(self,snapname):
        
        max_retry_count = int(getArg("max_retry_count","HoneyClient::Manager::ESX"))
        if self.num_failed_inits > max_retry_count:

            LOG.info("TODO: denynetwork")
            LOG.error("Detected possible BSOD in initializing clone VM %s" % self.quick_clone_vm_name)

            LOG.info("Reverting Clone VM")
            esx.revertVM(self.vm_session,self.quick_clone_vm_name,snapname)
            esx.startVM(self.vm_session,self.quick_clone_vm_name)
            self.num_failed_inits = 0
        else:
            self.num_failed_inits += 1
            LOG.info("Clone VM %s - had %i failed inits" % (self.quick_clone_vm_name,self.num_failed_inits))
Пример #2
0
    def __do_init(self):
        """
        replaces the 'init' call in the Perl code
        """
        if not self.quick_clone_vm_name or not self.name or not self.mac_address or not self.ip_address:
            LOG.info("Quick cloning master VM: %s" % self.master_vm_name)
            s, dest_name = esx.quickCloneVM(self.vm_session,self.master_vm_name)
            
            self.quick_clone_vm_name = dest_name
            self.num_snapshots += 1
            self.__change_status("initialized")

            registered = False
            while registered:
                s, registered = esx.isRegisteredVM(self.vm_session,self.quick_clone_vm_name)
                if not registered:
                    # poll for it
                    sleep( self.retry_period )
            
            LOG.info("Retrieving config of clone VM")
            s, self.vm_config = esx.getConfigVM(self.vm_session,self.quick_clone_vm_name)
            self.__change_status("registered")

            started = "no"
            while started != 'poweredOn':
                s, started = esx.getStateVM(self.vm_session,self.quick_clone_vm)
                if started != 'poweredOn':
                    sleep(self.retry_period)
            self.__change_status('running')

            LOG.info("No waiting on valid MAC/IP for clone")
            temp_ip = None
            while not self.ip_address or not self.mac_address:
                s, self.mac_address = esx.getMACaddrVM(self.vm_session,self.quick_clone_vm)
                s, temp_ip = esx.getIPaddrVM(self.vm_session,self.quick_clone_vm)
                
                if temp_ip and temp_ip != self.ip_address:
                    LOG.info("Cloned VM has a new IP")
                    
                    # TODO: call self._deny_network()
                    
                    self.ip_address = temp_ip

                if not self.ip_address or not self.mac_address:
                    snapname = getArg("default_quick_clone_snapshot_name","HoneyClient::Manager::ESX")
                    self.__check_for_bsod(snapname)
                    sleep(self.retry_period)
                    continue
                
                LOG.info("TODO: allow_network")
                LOG.info("get Agent Handle")
                LOG.info("get Agent properties")

                # NEED TO CHECK HERE FOR THE AGENT AND WAIT FOR IT
                # THIS WILL BE 'if' block
                
                LOG.info("Create operational snapshot of the VM")
                desc = getArg("operational_quick_clone_snapshot_description","HoneyClient::Manager::ESX")
                s, snapname = esx.snapshotVM(self.vm_session,self.quick_clone_vm_name,desc)
                self.name = snapname
                self.num_snapshots += 1

                s, hostname = esx.getHostnameESX(self.vm_session)
                s, ip = esx.getIPaddrESX(self.vm_session)
                
                LOG.info("TODO: notify the drone here with a message")
        else:
            
            if not self.name:
                self.__croak("Unable to start clone. No operational snapshot provided")

            LOG.info("Reverting clone VM to operational snapshot")
            
            s = esx.revertVM(self.vm_session,self.quick_clone_vm_name,self.name)
            # Rename the snapshot
            desc = getArg("operational_quick_clone_snapshot_description","HoneyClient::Manager::ESX")
            s, newname = esx.renameSnapshotVM(self.vm_session,self.quick_clone_vm_name,self.name,desc)
            self.name = newname
            LOG.info("Renamed operational snapshot from %s to %s",(self.quick_clone_vm_name,self.name))
            LOG.info("Get the VM config file")

            s, self.vm_config = esx.getConfigVM(self.vm_session,self.quick_clone_vm_name)
            LOG.info("Starting clone VM")
            esx.startVM(self.vm_session,self.quick_clone_vm_name)
            
            # Wait to make sure it's running
            running = False
            while not running:
                s, st = esx.getStateVM(self.vm_session,self.quick_clone_vm_name)
                if st == 'poweredOn':
                    running = True
                else:
                    sleep(self.retry_period)
                    
            self.__change_status("running")

            LOG.info("TODO: start agent & notify drone")