Exemplo n.º 1
0
    def __setup(self):
        
        LOG.info("TODO: Add code for loading 'complete_image' here")

        if not self.vm_session:
            
            LOG.info("Creating a new ESX Session to %s" % self.service_url)
            self.vm_session = esx.login(self.service_url,self.un,self.pw)
            
            # notify drone about the new host
            s, hostname = esx.getHostnameESX(self.vm_session)
            s, ip = esx.getIPaddrESX(self.vm_session)
            
            LOG.info("Setup EventEmitter host with %s %s" % (hostname,ip))

        
        # Check if there's enough disk space. If not, die
        self.__check_space_available()
        
        # Connect (or reconnect) to host via VIX, if enabled.
        #if int(getArg('vix_enable','HoneyClient::Manager::ESX::Clone')):
        #    self.vix_disconnect_vm()
        #    self.vix_disconnect_host()
        #    self.vix_connect_host()

        if self.bypass_firewall:
            LOG.info("TODO: Setup Firewall...")
        
        if self.num_snapshots >= getArg('max_num_snapshots','HoneyClient::Manager::ESX'):
            LOG.info("Suspending Clone VM. Reached the maximum number of snapshots")
            
            s,r = esx.suspendVM(self.vm_session,self.quick_clone_vm_name)
            
            self.quick_clone_vm_name = None
            self.name = None
            self.mac_address = None
            self.ip_address = None
            self.num_snapshots = 0
        
        # dont_init is ONLY used for testing without fully init() the object
        if self.dont_init:
            # we're done here
            return
        else:
            try:
                self.__do_init()
            except SystemExit:
                # Suspend the VM and try again
                LOG.error("Unable to init VM %s - Retrying..." % self.quick_clone_vm_name)
                LOG.info("Suspending the VM")

                suspended_at = datetime.now()
                
                try:
                    s,r = esx.suspendVM(self.vm_session,self.quick_clone_vm_name)
                    self.__change_status("suspended",suspended_at)
                except SystemExit:
                    LOG.error("Unable to suspend the VM")
Exemplo n.º 2
0
 def destroy(self):
     LOG.info("TODO: denyNetwork")
     try:
         desc = getArg("operational_quick_clone_snapshot_description","HoneyClient::Manager::ESX")
         s, n = esx.renameSnapshotVM(self.vm_session,self.quick_clone_vm_name,self.name,"Deleted Snapshot",desc)
         self.__change_status("deleted")
         self.name = n
     except SystemExit:
         esx.suspendVM(self.vm_session,self.quick_clone_vm_name)
         self.__change_status("error")