コード例 #1
0
ファイル: AddCmd.py プロジェクト: Erignik/http_configure
    def execute(self):
        is_suc, moc_name, para_2_val = CmdTextHandle.parse_cmd(self.cmd)
        if not is_suc:
            logger.error("parse_cmd error, cmd is [%s]." % self.cmd)
            return False, "AddCmd, Error cmd format...."

        moc_ins = MocSingleton.get_instance()
        moc_obj = moc_ins.get_moc(moc_name)
        if moc_obj is None:
            logger.error("can not get moc, moc_name is [%s]." % moc_name)
            return False, "AddCmd, Error cmd name...."

        if not self.check_para_consist(moc_obj, para_2_val):
            return False, "cmd is Add, input para should consist with module...."

        ret_flag, error_info = moc_obj.pre_add_cmd_check(para_2_val)
        if not ret_flag:
            logger.error("pre_add_cmd_check fail, error info is [%s]." %
                         error_info)
            return ret_flag, error_info

        key_para_lst = moc_obj.get_key_para()
        key_dict = {
            para: val
            for para, val in para_2_val.items() if para in key_para_lst
        }
        para_dict = {
            para: val
            for para, val in para_2_val.items() if para not in key_para_lst
        }
        db_obj = DbSingleton.get_instance().get_db_obj()
        return db_obj.execute(DB_ACTION_ADD, moc_name, key_dict, para_dict)
コード例 #2
0
    def execute(self):
        is_suc, moc_name, para_2_val = CmdTextHandle.parse_cmd(self.cmd)
        if not is_suc:
            logger.error("parse_cmd error, cmd is [%s]." % self.cmd)
            return False, "LstCmd, Error cmd format...."

        moc_ins = MocSingleton.get_instance()
        moc_obj = moc_ins.get_moc(moc_name)
        if moc_obj is None:
            logger.error("can not get moc, moc_name is [%s]." % moc_name)
            return False, "LstCmd, Error cmd name...."

        key_para_lst = moc_obj.get_key_para()
        if not self.check_lst_para(para_2_val, key_para_lst):
            return False, "LstCmd, Error para name...."

        db_obj = DbSingleton.get_instance().get_db_obj()
        ret, query_dict_lst = db_obj.query(moc_name)
        if not ret:
            logger.error(
                "db_obj.query fail. ret is %s, query_dict_lst is %s." %
                (ret, query_dict_lst))
            return False, "LstCmd error...."

        query_dict_lst = moc_obj.post_lst_handle(query_dict_lst)

        ret, record_info = self.__get_format_record(query_dict_lst, para_2_val)
        if not ret:
            return True, "No record find...."
        else:
            return True, record_info
コード例 #3
0
def get_para_lst_db(moc_name):
    db_obj = DbSingleton.get_instance().get_db_obj()
    ret, query_dict_lst = db_obj.query(moc_name)
    if not ret:
        logger.error("query moc name %s fail. info is %s." %
                     (moc_name, query_dict_lst))
        return False, []

    para_lst = []
    for query_dict in query_dict_lst:
        for key, _ in query_dict.items():
            para_lst.append(key)
    return True, list(set(para_lst))
コード例 #4
0
    def pre_add_cmd_check(self, para_2_val):
        ret, info = self.check_para(para_2_val)
        if not ret:
            logger.error("check_para fail. info is %s..." % info)
            return False, info

        db_obj = DbSingleton.get_instance().get_db_obj()
        ret, query_dict_lst = db_obj.query('MOCDBFILEBACKUPINFO')
        if not ret:
            logger.error("query moc name MOCDBFILEBACKUPINFO fail.")
            return False, "query moc info error..."

        if len(query_dict_lst) >= 1:
            return False, "moc MOCDBFILEBACKUPINFO should be unique..."

        return True, ""
コード例 #5
0
def backup_db_file():
    logger.info("start to backup_db_file...")
    db_obj = DbSingleton.get_instance().get_db_obj()
    ret, query_dict_lst = db_obj.query('MOCDBFILEBACKUPINFO')
    if not ret:
        logger.error("query moc name MOCDBFILEBACKUPINFO fail. info is %s." %
                     query_dict_lst)
        return

    for query_dict in query_dict_lst:
        ret, info = MocDbFileBackupInfo.check_para(query_dict)
        if not ret:
            logger.error("check_para fail. info is %s." % info)
            continue

        if MocDbFileBackupInfo.is_local_backup(query_dict['TYPE']):
            do_local_backup(query_dict)

        if MocDbFileBackupInfo.is_ftp_backup(query_dict['TYPE']):
            do_ftp_backup(query_dict)

    logger.info("done to backup_db_file...")