示例#1
0
    def restore_ntp_data(self):    
        """
        Method: restore_ntp_data
        Description: 还原NTPD服务数据
        Parameter: 无
        Return: return_code,还原NTPD服务数据处理结果的错误码
        Others: 无
        """

        return_code, description = ntpd_set.ntpd_write(self._mit_manager) 
        return return_code
示例#2
0
    def handle_cmd(self, frame):
        """
        Method: handle_cmd
        Description: 打开关闭NTPD服务
        Parameter: 
            frame: 收到的处理消息
            data区1个参数:
            msg:NtpdControl对象
        Return: 无
        Others: 1. 开关参数为on,off
                2. 打开服务时,stratum有效值为1-15,数值越小,优先级越高
        """

        try:
            msg = ntpd_params.NtpdControl().deserialize(frame.get_data())
        except:
            result = ntpd_params.GetNtpdHandlerResult()
            result.return_code = err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR
            result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR)
            self.get_worker().send_ack(frame, (result.serialize(), ))
            return
        
        rdms = self.get_worker().get_mit_manager().rdm_find("NtpdControlMOC")
        if len(rdms)==0:
            result = ntpd_params.GetNtpdHandlerResult()
            result.return_code = err_code_mgr.ER_NTPD_DB_ERROR
            result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_DB_ERROR)
            self.get_worker().send_ack(frame, (result.serialize(), ))
            return
            
        if rdms[0].openserver==msg.openserver:
            response= ntpd_params.GetNtpdHandlerResult() 
            response.return_code = err_code_mgr.ER_NTPD_HAS_OP_ERROR
            response.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_HAS_OP_ERROR)
            self.get_worker().send_ack(frame, (response.serialize(), ))
            return

        rdms[0].openserver = msg.openserver
        rdms[0].stratum = msg.stratum
        ret = self.get_worker().get_mit_manager().rdm_mod(rdms[0])
        if ret.get_err_code()!=err_code_mgr.ER_SUCCESS:
            result = ntpd_params.GetNtpdHandlerResult() 
            result.init_all_attr()
            result.return_code = ret.get_err_code()
            result.description = ret.get_msg()
            self.get_worker().send_ack(frame, (result.serialize(), ))
            return

        return_code, description = ntpd_set.ntpd_write(self.get_worker().get_mit_manager()) 
        response= ntpd_params.GetNtpdHandlerResult()    
        response.return_code = return_code
        response.description = description
        self.get_worker().send_ack(frame, (response.serialize(), ))    
示例#3
0
    def handle_cmd(self, frame):
        """
        Method: handle_cmd
        Description: 删除NTPD的某个服务器IP地址
        Parameter: 
            frame: 收到的处理消息
            data区一个参数
            msg:NtpdServer对象
        Return: 无
        Others: 无
        """

        try:
            msg = ntpd_params.NtpdServer().deserialize(frame.get_data())
        except:
            result = ntpd_params.GetNtpdHandlerResult()
            result.return_code = err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR
            result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR)
            self.get_worker().send_ack(frame, (result.serialize(), ))
            return
        
        if msg.serverip is None:
            result = ntpd_params.GetNtpdHandlerResult()
            result.return_code = err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR
            result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR)
            self.get_worker().send_ack(frame, (result.serialize(), ))
            return
        
        ntpdserver_moc = self.get_worker().get_mit_manager().gen_rdm("NtpdServerMOC")  
        ntpdserver_moc.serverip = msg.serverip
           
        ret = self.get_worker().get_mit_manager().rdm_remove(ntpdserver_moc)
        if ret.get_err_code() == err_code_mgr.ER_OBJECT_NOT_EXIST:
            result = ntpd_params.GetNtpdHandlerResult()
            result.return_code = err_code_mgr.ER_NTPD_SERVER_NOT_EXIST
            result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_SERVER_NOT_EXIST)
            self.get_worker().send_ack(frame, (result.serialize(), ))
            return 
        if ret.get_err_code()!=err_code_mgr.ER_SUCCESS:
            result = ntpd_params.GetNtpdHandlerResult()
            result.return_code = ret.get_err_code()
            result.description = ret.get_msg()
            self.get_worker().send_ack(frame, (result.serialize(), ))
            return   

        return_code, description = ntpd_set.ntpd_write(self.get_worker().get_mit_manager()) 
        response= ntpd_params.GetNtpdHandlerResult()    
        response.return_code = return_code
        response.description = description    
        self.get_worker().send_ack(frame, (response.serialize(), ))
        
示例#4
0
    def handle_cmd(self, frame):
        """
        Method: handle_cmd
        Description: 为NTPD服务设置子网段
        Parameter: 
            frame: 收到的处理消息
            data区一个参数:
            msg:NtpdSubnet对象
        Return: 无
        Others: 无
        """

        try:
            msg = ntpd_params.NtpdSubnet().deserialize(frame.get_data())
        except:
            result = ntpd_params.GetNtpdHandlerResult()
            result.return_code = err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR
            result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR)
            self.get_worker().send_ack(frame, (result.serialize(), ))
            return
        
        if msg.subnetip is None or msg.mask is None:
            result = ntpd_params.GetNtpdHandlerResult()
            result.return_code = err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR
            result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_NTPD_INVALID_DESERIALIZE_ERROR)
            self.get_worker().send_ack(frame, (result.serialize(), ))
            return

        ntpdsubnet_moc = self.get_worker().get_mit_manager().gen_rdm("NtpdSubnetMOC")        
        ntpdsubnet_moc.subnetip = msg.subnetip
        ntpdsubnet_moc.mask = msg.mask  
        ret = self.get_worker().get_mit_manager().rdm_add(ntpdsubnet_moc)
        
        if ret.get_err_code()==err_code_mgr.ER_OBJECT_ADD_CONFLICT:
            result = ntpd_params.GetNtpdHandlerResult()
            result.return_code = err_code_mgr.ER_DUPLICATE_NTPD_SUBNET_ERROR
            result.description = err_code_mgr.get_error_msg(err_code_mgr.ER_DUPLICATE_NTPD_SUBNET_ERROR)
            self.get_worker().send_ack(frame, (result.serialize(), ))
            return
        if ret.get_err_code()!=err_code_mgr.ER_SUCCESS:
            result = ntpd_params.GetNtpdHandlerResult()
            result.return_code = ret.get_err_code()
            result.description = ret.get_msg()
            self.get_worker().send_ack(frame, (result.serialize(), ))
            return
 
        return_code, description = ntpd_set.ntpd_write(self.get_worker().get_mit_manager()) 
        response= ntpd_params.GetNtpdHandlerResult()    
        response.return_code = return_code
        response.description = description
        self.get_worker().send_ack(frame, (response.serialize(), ))