Example #1
0
    def exec_task(self, auth, ctx,node_ids):
        LOGGER.debug('entered in exec task for VMAvailability task')
        strt = p_task_timing_start(AVL_LOGGER, "VMAvailability", node_ids)
        try:
            self.completed_nodes = []
            self.pending_nodes = [node_id for node_id in node_ids]
            self.exc_node_ids = [node_id for node_id in node_ids]
            index = 0
            node_id = self.get_next_node_id(index)
            while node_id is not None:
                self.pending_nodes.remove(node_id)
                node = DBSession.query(ManagedNode).filter(ManagedNode.id == node_id).first()
                index+=1
                node_id = self.get_next_node_id(index)
                if node and node.is_up():
                    self.current_node = node
                    self.start_time = datetime.utcnow()

                    try:
                        try:
                            strt1 = p_task_timing_start(AVL_LOGGER, "RefreshVMAvail", node.id)
                            node.refresh_vm_avail()
                            p_task_timing_end(AVL_LOGGER, strt1)
                        except Exception, e:
                            LOGGER.error("Error updating VM availability . Server :"+node.hostname)
                            traceback.print_exc()
                    finally:
                        self.completed_nodes.append(node.id)
        finally:
            self.check_if_hung()
            p_task_timing_end(AVL_LOGGER, strt)
Example #2
0
    def exec_task(self, auth, ctx,node_ids):
        LOGGER.debug('entered in exec task for VMAvailability task')
        strt = p_task_timing_start(AVL_LOGGER, "VMAvailability", node_ids)
        try:
            self.completed_nodes = []
            self.pending_nodes = [node_id for node_id in node_ids]
            self.exc_node_ids = [node_id for node_id in node_ids]
            index = 0
            node_id = self.get_next_node_id(index)
            while node_id is not None:
                self.pending_nodes.remove(node_id)
                node = DBSession.query(ManagedNode).filter(ManagedNode.id == node_id).first()
                index+=1
                node_id = self.get_next_node_id(index)
                if node and node.is_up():
                    self.current_node = node
                    self.start_time = datetime.utcnow()

                    try:
                        try:
                            strt1 = p_task_timing_start(AVL_LOGGER, "RefreshVMAvail", node.id)
                            node.refresh_vm_avail()
                            p_task_timing_end(AVL_LOGGER, strt1)
                        except Exception, e:
                            LOGGER.error("Error updating VM availability . Server :"+node.hostname)
                            traceback.print_exc()
                    finally:
                        self.completed_nodes.append(node.id)
        finally:
            self.check_if_hung()
            p_task_timing_end(AVL_LOGGER, strt)
Example #3
0
    def exec_task(self, auth, ctx,node_ids):
        try:
            LOGGER.debug('entered in exec task for NodesAvailability task')
            nodes=DBSession.query(ManagedNode).filter(ManagedNode.id.in_(node_ids)).all()
            node_names = ""
            port=0
            for node in nodes:
                node_names += node.hostname + " "
                nport=node.get_connection_port()
                if port == 0:
                    port=nport
                else:
                    if port > 0 and nport != port:
                        port=-1

            strt = p_task_timing_start(AVL_LOGGER, "NodesAvailability", node_names.strip().split(' '))
            strt1 = p_task_timing_start(AVL_LOGGER, "PreProcess", node_names.strip().split(' ')[0])
            
            self.completed_nodes = []
            self.pending_nodes = [node_id for node_id in node_ids]
            self.exc_node_ids = [node_id for node_id in node_ids]
            index = 0
            node_id = self.get_next_node_id(index)

            use_nmap = eval(tg.config.get("use_nmap_for_heartbeat", "False"))

            if use_nmap == True and port > 0:
                strt2 = p_task_timing_start(AVL_LOGGER, "NodesNmap", node_names)
                (output, exit_code) = self.do_nmap_ping(node_names=node_names, port=port)
                p_task_timing_end(AVL_LOGGER, strt2)
            else:
                (output, exit_code) = ("", -1)
            p_task_timing_end(AVL_LOGGER, strt1)

            while node_id is not None:
                self.pending_nodes.remove(node_id)
                node = DBSession.query(ManagedNode).filter(ManagedNode.id == node_id).first()
                index+=1
                node_id = self.get_next_node_id(index)

                strt1 = p_task_timing_start(AVL_LOGGER, "NodeRefreshAvail", node.hostname)
                if node:
                    self.current_node = node
                    self.start_time = datetime.utcnow()

                    try:
                        try:
                            node.refresh_avail(auth, exit_code=exit_code, isUp="(" + node.hostname + ")" in output)
                        except Exception, e:
                            LOGGER.error("Error updating Node availability . Server :"+node.hostname)
                            traceback.print_exc()
                    finally:
                        self.completed_nodes.append(node.id)
                p_task_timing_end(AVL_LOGGER, strt1)
        finally:
            self.check_if_hung()
            p_task_timing_end(AVL_LOGGER, strt)
Example #4
0
def update_avail(node, new_state, monit_state, timestamp, reason, logger, update=True, auth=None):
    sv_point = transaction.savepoint()
    try:
        strt = p_task_timing_start(logger, "UpdateAvailability", node.id, log_level="DEBUG")
        #there is a status change, update and send event
        #update current availability,
        #we only update avail-state, monit_state is updated
        #only by user actions
        node.current_state.avail_state = new_state
        node.current_state.timestamp = timestamp
        node.current_state.description = reason
        avh=DBSession.query(AvailHistory).filter(AvailHistory.entity_id==node.id).\
            order_by(AvailHistory.timestamp.desc()).first()
        if avh is not None:
            avh.endtime=timestamp
            time_diff=timestamp-avh.timestamp
            avh.period=time_diff.days*24*60+time_diff.seconds/60
            DBSession.add(avh)
        #insert availability history
        ah = AvailHistory(node.id, new_state, monit_state, timestamp, reason)
        DBSession.add(ah)
        if update==True:
            ent = DBSession.query(Entity).filter(Entity.entity_id==node.id).first()
            from convirt.model.ManagedNode import ManagedNode
            if ent.type.name == constants.MANAGED_NODE:
                if new_state == ManagedNode.DOWN:
                    notify_node_down(ent.name, reason)
                else:
                    node_up_action(auth, node.id)
    except Exception, e:
        #defer to next time
        import traceback
        traceback.print_exc()
        logger.error(e)
        sv_point.rollback()
Example #5
0
 def exec_task(self, auth, ctx):
     LOGGER.debug('vm availability task is running')
     try:
         strt = p_task_timing_start(AVL_LOGGER, "VMAvailTask", [])
         VMAvailabilityWorker(auth).do_work()
         p_task_timing_end(AVL_LOGGER, strt)
     except Exception, e:
         LOGGER.debug('error while checking license.\n'+to_str(e))
Example #6
0
 def exec_task(self, auth, ctx):
     LOGGER.debug('vm availability task is running')
     try:
         strt = p_task_timing_start(AVL_LOGGER, "VMAvailTask", [])
         VMAvailabilityWorker(auth).do_work()
         p_task_timing_end(AVL_LOGGER, strt)
     except Exception, e:
         LOGGER.debug('error while checking license.\n'+to_str(e))
Example #7
0
    def exec_task(self, auth, ctx,node_ids,sp_id):
        LOGGER.debug('entered in excec task for CollectMetricsForNodes task')
        strt = p_task_timing_start(MTR_LOGGER, "CollectMetrics", node_ids)
        try:
            manager = Basic.getGridManager()
            self.completed_nodes = []
            self.pending_nodes = [node_id for node_id in node_ids]
            self.exc_node_ids = [node_id for node_id in node_ids]
            index = 0
            node_id = self.get_next_node_id(index)
            while node_id is not None:
                self.pending_nodes.remove(node_id)
                m_node=DBSession.query(ManagedNode).filter(ManagedNode.id==node_id).one()
                index+=1
                node_id = self.get_next_node_id(index)
                if m_node is None :
                    continue
                self.current_node = m_node
                self.start_time = datetime.utcnow()
                try:
                    try:
                        strt1 = p_task_timing_start(MTR_LOGGER, "NodeGetMterics", m_node.id)
                        #call function to store the Server metrics into the database
                        node_snapshot=manager.collectServerMetrics(auth, m_node,filter=True)

                        #call function to store the VM metrics into the database table
                        manager.collectVMMetrics(auth, m_node.id, node_snapshot)
                        #collect metrics at serverpool level
                        manager.collectServerPoolMetrics(auth, sp_id)
                        DBSession.flush()
                        transaction.commit()
                        p_task_timing_end(MTR_LOGGER, strt1)
                    except Exception, e:
                        LOGGER.error("Error updating metrics . Server :"+m_node.hostname)
                        traceback.print_exc()
                finally:
                    self.completed_nodes.append(m_node.id)
        finally:
            self.check_if_hung()
            p_task_timing_end(MTR_LOGGER, strt)
Example #8
0
    def exec_task(self, auth, ctx,node_ids,sp_id):
        LOGGER.debug('entered in excec task for CollectMetricsForNodes task')
        strt = p_task_timing_start(MTR_LOGGER, "CollectMetrics", node_ids)
        try:
            manager = Basic.getGridManager()
            self.completed_nodes = []
            self.pending_nodes = [node_id for node_id in node_ids]
            self.exc_node_ids = [node_id for node_id in node_ids]
            index = 0
            node_id = self.get_next_node_id(index)
            while node_id is not None:
                self.pending_nodes.remove(node_id)
                m_node=DBSession.query(ManagedNode).filter(ManagedNode.id==node_id).one()
                index+=1
                node_id = self.get_next_node_id(index)
                if m_node is None :
                    continue
                self.current_node = m_node
                self.start_time = datetime.utcnow()
                try:
                    try:
                        strt1 = p_task_timing_start(MTR_LOGGER, "NodeGetMterics", m_node.id)
                        #call function to store the Server metrics into the database
                        node_snapshot=manager.collectServerMetrics(auth, m_node,filter=True)

                        #call function to store the VM metrics into the database table
                        manager.collectVMMetrics(auth, m_node.id, node_snapshot)
                        #collect metrics at serverpool level
                        manager.collectServerPoolMetrics(auth, sp_id)
                        DBSession.flush()
                        transaction.commit()
                        p_task_timing_end(MTR_LOGGER, strt1)
                    except Exception, e:
                        LOGGER.error("Error updating metrics . Server :"+m_node.hostname)
                        traceback.print_exc()
                finally:
                    self.completed_nodes.append(m_node.id)
        finally:
            self.check_if_hung()
            p_task_timing_end(MTR_LOGGER, strt)
Example #9
0
def update_avail(node,
                 new_state,
                 monit_state,
                 timestamp,
                 reason,
                 logger,
                 update=True,
                 auth=None):
    sv_point = transaction.savepoint()
    try:
        strt = p_task_timing_start(logger,
                                   "UpdateAvailability",
                                   node.id,
                                   log_level="DEBUG")
        #there is a status change, update and send event
        #update current availability,
        #we only update avail-state, monit_state is updated
        #only by user actions
        node.current_state.avail_state = new_state
        node.current_state.timestamp = timestamp
        node.current_state.description = reason
        avh=DBSession.query(AvailHistory).filter(AvailHistory.entity_id==node.id).\
            order_by(AvailHistory.timestamp.desc()).first()
        if avh is not None:
            avh.endtime = timestamp
            time_diff = timestamp - avh.timestamp
            avh.period = time_diff.days * 24 * 60 + time_diff.seconds / 60
            DBSession.add(avh)
        #insert availability history
        ah = AvailHistory(node.id, new_state, monit_state, timestamp, reason)
        DBSession.add(ah)
        if update == True:
            ent = DBSession.query(Entity).filter(
                Entity.entity_id == node.id).first()
            from convirt.model.ManagedNode import ManagedNode
            if ent.type.name == constants.MANAGED_NODE:
                if new_state == ManagedNode.DOWN:
                    notify_node_down(ent.name, reason)
                else:
                    node_up_action(auth, node.id)
    except Exception, e:
        #defer to next time
        import traceback
        traceback.print_exc()
        logger.error(e)
        sv_point.rollback()
Example #10
0
    def exec_task(self, auth, ctx):
        LOGGER.debug('node availability task is running')

        strt = p_task_timing_start(AVL_LOGGER, "NodeAvailTask", [])
        AvailabilityWorker(auth).do_work()
        p_task_timing_end(AVL_LOGGER, strt)
Example #11
0
 def exec_task(self, auth, ctx):
     LOGGER.debug('entered in excec task for CollectMetricsForNodes task')
     strt = p_task_timing_start(MTR_LOGGER, "CollectMetricsForNodes", [])
     CollectMetricsWorker(auth).do_work()
     p_task_timing_end(MTR_LOGGER, strt)
Example #12
0
    def exec_task(self, auth, ctx):
        LOGGER.debug('node availability task is running')

        strt = p_task_timing_start(AVL_LOGGER, "NodeAvailTask", [])
        AvailabilityWorker(auth).do_work()
        p_task_timing_end(AVL_LOGGER, strt)
Example #13
0
 def exec_task(self, auth, ctx):
     LOGGER.debug('entered in excec task for CollectMetricsForNodes task')
     strt = p_task_timing_start(MTR_LOGGER, "CollectMetricsForNodes", [])
     CollectMetricsWorker(auth).do_work()
     p_task_timing_end(MTR_LOGGER, strt)