Beispiel #1
0
 def run(self):
     num_r = 1
     op = Operation()
     
     while True:
         self._report = {}
         chk_timestamp = int(time.time())
         appendFile('Time: ' + time.asctime(time.localtime()) + ' >> ' + str(num_r) + '\n', self.logfile)
         
         self.check_host(chk_timestamp)
         self.check_vm(chk_timestamp)
         
         if self._report != None and len(self._report) != 0:
             for host in self._report:
                 appendFile('Host: ' + host + ' -- Status: ' + self._report[host]['status'] + '\n', self.logfile)
                 
                 if self._report[host]['status'] != 'ALIVE':
                     appendFile('  TODO: Migration...\n', self.logfile)
                 else:
                     for vm in self._report[host]['vm_list']:
                         appendFile('  ' + vm['vm'] + ' [' + vm['status'] + ' - ' + str(vm['repeat_num']) + '][' + vm['status-ori'] + ']\n', self.logfile)
                         
                         if vm['status'] == 'WAITING' and vm['repeat_num'] > self._reboot_threshold:
                             op.reboot_ins(vm['vm'])
                             
         time.sleep(self._check_interval)
         num_r = num_r + 1
Beispiel #2
0
    def run(self):
        num_r = 0
        op = Operation()
        
        while True:
            self._report = {}
            chk_timestamp = int(time.time())
            utils.appendFile('Time: ' + time.asctime(time.localtime()) + ' >> ' + str(num_r) + '\n', self._params['logfile'])
            
            self.check_host(chk_timestamp)
            self.check_vm(chk_timestamp)

	    utils.appendFile('Total: ' + str(len(self._report)) + ' hosts\n', self._params['logfile'])
            
            if self._report != None and len(self._report) != 0:
                for host in self._report:
                    utils.appendFile('Host: ' + host + ' -- Status: [' + self._report[host]['status'] + '], vm: ' + str(len(self._report[host]['vm_list'])) + '\n', self._params['logfile'])
                    
                    if self._report[host]['status'] != 'ALIVE':
                        utils.appendFile('  - TODO: Migration...\n', self._params['logfile'])
                    else:
                        for vm in self._report[host]['vm_list']:
                            utils.appendFile('  - ' + vm['vm'] + ' [' + vm['status'] + ' - ' + str(vm['repeat_num']) + '][' + vm['status-ori'] + ']\n', self._params['logfile'])
                            
                            if vm['status'] == 'WAITING' and vm['repeat_num'] > self._params['reboot']:
                                op.reboot_ins(vm['vm'])
                                
            time.sleep(self._params['intvl'])
            num_r = num_r + 1
Beispiel #3
0
    def run(self):
        # Initialization
        num_r = 0 # number of round
        vm_list = {} # list of vm
        op = Operation()
        
        while True:
            appendFile('Time: ' + time.asctime(time.localtime()) + ' >> ' + str(num_r) + '\n', self.logfile)
            
            id_list = self.chk_ins(int(time.time()))
            
            if id_list != None and len(id_list) != 0:   
                for vm_c in id_list: # Notice: vm_c is uuid
                    if vm_list.has_key(vm_c):
                        # Update
                        vm_list[vm_c]['ins_status'] = id_list[vm_c]['ins_status']
#                        vm_list[vm_c]['ins_hostname'] = id_list[vm_c]['ins_hostname']
                        vm_list[vm_c]['chk_time'] = id_list[vm_c]['chk_time'] #Check time
                        
                        
                        vm_list[vm_c]['cpu_usage'] = id_list[vm_c]['cpu_usage']
                        vm_list[vm_c]['mem_free'] = id_list[vm_c]['mem_free']
                        vm_list[vm_c]['mem_max'] = id_list[vm_c]['mem_max']
                        vm_list[vm_c]['nic_in'] = id_list[vm_c]['nic_in']
                        vm_list[vm_c]['nic_out'] = id_list[vm_c]['nic_out']
                        vm_list[vm_c]['disk_read'] = id_list[vm_c]['disk_read']
                        vm_list[vm_c]['disk_write'] = id_list[vm_c]['disk_write']
                        
                        # Last report time by kanyun
                        if vm_list[vm_c]['monitor_time'] == id_list[vm_c]['monitor_time']:
                            # add repeat num
                            vm_list[vm_c]['repeat_num'] = vm_list[vm_c]['repeat_num'] + 1
                            
                            # Alarm threshold 5
                            if vm_list[vm_c]['repeat_num'] <= self.wait:
                                appendFile(vm_c + ' - [WAITING - ' + str(vm_list[vm_c]['repeat_num']) + '][' + vm_list[vm_c]['ins_status'] + ']\n', self.logfile)
                            elif vm_list[vm_c]['repeat_num'] > self.wait and vm_list[vm_c]['repeat_num'] <= self.reboot:
                                appendFile(vm_c + ' - [FAILED - ' + str(vm_list[vm_c]['repeat_num']) + '][' + vm_list[vm_c]['ins_status'] + ']\n', self.logfile)
                            else:
                                #TODO: Further operation like reboot, migration and so on
                                op.reboot_ins(vm_c)
                                appendFile(vm_c + ' - [REBOOT][' + vm_list[vm_c]['ins_status'] + ']\n', self.logfile)
                        else:
                            # set repeat num to zero
                            vm_list[vm_c]['repeat_num'] = 0
                            vm_list[vm_c]['monitor_time'] = id_list[vm_c]['monitor_time'] 
                            appendFile(vm_c + ' - [OK][' + vm_list[vm_c]['ins_status'] + ']\n', self.logfile)
                    else:
                        # Insert
                        tmp_dict = {}
                        tmp_dict['ins_name'] = id_list[vm_c]['ins_name']
                        tmp_dict['ins_status'] = id_list[vm_c]['ins_status']
#                        tmp_dict['ins_hostname'] = rc.run("nova --os-username admin --os_password csdb123cnic --os_tenant_name admin --os_auth_url http://192.168.138.32:5000/v2.0 show " + tmp_dict['ins_uuid'] + " | grep OS-EXT-SRV-ATTR:hypervisor_hostname | awk '{print $4}'").strip()

		#	print id_list[vm_c]

                        tmp_dict['cpu_usage'] = id_list[vm_c]['cpu_usage']
                        tmp_dict['mem_free'] = id_list[vm_c]['mem_free']
                        tmp_dict['mem_max'] = id_list[vm_c]['mem_max']
                        tmp_dict['nic_in'] = id_list[vm_c]['nic_in']
                        tmp_dict['nic_out'] = id_list[vm_c]['nic_out']
                        tmp_dict['disk_read'] = id_list[vm_c]['disk_read']
                        tmp_dict['disk_write'] = id_list[vm_c]['disk_write']
                        
                        tmp_dict['chk_time'] = id_list[vm_c]['chk_time']
                        tmp_dict['monitor_time'] = id_list[vm_c]['monitor_time']
                        tmp_dict['repeat_num'] = 0
                        appendFile(vm_c + ' - [NEW][' + id_list[vm_c]['ins_status'] + ']\n', self.logfile)
                        
                        vm_list[vm_c] = tmp_dict
                    
            time.sleep(self.intvl)
            num_r = num_r + 1