コード例 #1
0
ファイル: ITA_driver.py プロジェクト: hokuto-fukunaga/oase
    def set_action_server_list(self, aryActionParameter, exe_order, response_detail_id):
        """
        [概要]
        アクションサーバーリストをメンバ変数にセットする
        """
        logger.logic_log('LOSI00001', 'aryActionParameter: %s' %
                        aryActionParameter)
        ActionDriverCommonModules.SaveActionLog(
            self.response_id, exe_order, self.trace_id, 'MOSJA01001')

        key1 = 'ACTION_PARAMETER_INFO'
        if key1 not in aryActionParameter:
            ActionDriverCommonModules.SaveActionLog(
                self.response_id, exe_order, self.trace_id, 'MOSJA01005')
            raise OASEError('', 'LOSE01114', log_params=[self.trace_id, 'OASE_T_RHDM_RESPONSE_ACTION', response_detail_id, key1], msg_params={
                            'sts': ACTION_DATA_ERROR, 'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_SRVLIST_KEY})

        # SERVER_LIST サーチ
        key_server_list = 'SERVER_LIST'
        check_info = self.analysis_parameters(aryActionParameter[key1])

        for key, val in check_info.items():
            if key != key_server_list:
                continue

            server_list = val.split(':') if val else []
            if len(server_list) == 0:
                ActionDriverCommonModules.SaveActionLog(
                    self.response_id, exe_order, self.trace_id, 'MOSJA01002')
                raise OASEError('', 'LOSE01113', log_params=['OASE_T_RHDM_RESPONSE_ACTION', response_detail_id, key_server_list, self.trace_id], msg_params={
                                'sts': ACTION_DATA_ERROR, 'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_SRVLIST_VAL})

            # 一意のホストリストにする
            self.listActionServer.extend(server_list)
コード例 #2
0
    def select_c_pattern_per_orch(self, ary_movement_list):
        """
        [概要]
        Movement一覧検索メゾット
        正常なら0を、異常ならエラーコードを返す。
        """
        logger.logic_log(
            'LOSI00001', 'trace_id: %s, ary_movement_list: %s' %
            (self.trace_id, ary_movement_list))
        target_table = 'C_PATTERN_PER_ORCH'
        self.restobj.menu_id = '2100000305'

        for movement_id, Items in ary_movement_list.items():
            aryfilter = {
                Cstobj.COL_DISUSE_FLAG: {
                    'NORMAL': '0'
                },
                Cstobj.CPPO_PATTERN_ID: {
                    'LIST': {
                        0: movement_id
                    }
                }
            }
            ary_result = {}
            ret = self.restobj.rest_select(aryfilter, ary_result)
            if ret:
                row_count = self.restobj.rest_get_row_count(ary_result)
                if row_count < 1:
                    # Movement未登録
                    logger.system_log('LOSE01017', self.trace_id, target_table,
                                      self.response_id, self.execution_order,
                                      movement_id)
                    logger.logic_log(
                        'LOSI00002', 'trace_id: %s, return: %s' %
                        (self.trace_id, Cstobj.RET_DATA_ERROR))
                    ActionDriverCommonModules.SaveActionLog(
                        self.response_id, self.execution_order, self.trace_id,
                        'MOSJA01020')
                    return Cstobj.RET_DATA_ERROR
                select_data = self.restobj.rest_get_row_data(ary_result)
                ary_movement_list[movement_id][
                    'MovementIDName'] = movement_id + ':' + select_data[0][
                        Cstobj.CPPO_PATTERN_NAME]
            else:
                logger.system_log('LOSE01000', self.trace_id, target_table,
                                  'Filter', ary_result['status'])
                logger.logic_log(
                    'LOSI00002', 'trace_id: %s, return: %s' %
                    (self.trace_id, Cstobj.RET_REST_ERROR))
                ActionDriverCommonModules.SaveActionLog(
                    self.response_id, self.execution_order, self.trace_id,
                    'MOSJA01019')
                return Cstobj.RET_REST_ERROR
        logger.logic_log('LOSI00002',
                         'trace_id: %s, return: %s' % (self.trace_id, 'True'))
        return 0
コード例 #3
0
    def select_c_operation_list(self, ary_config, operation_id, row_data):
        """
        [概要]
        投入オペレーション一覧検索メゾット
        """
        logger.logic_log(
            'LOSI00001', 'trace_id: %s, ary_config: %s, operation_id: %s' %
            (self.trace_id, ary_config, operation_id))
        target_table = 'C_OPERATION_LIST'
        ary_config['menuID'] = '2100000304'
        self.restobj.rest_set_config(ary_config)
        aryfilter = {
            Cstobj.COL_DISUSE_FLAG: {
                'NORMAL': '0'
            },
            Cstobj.COL_OPERATION_NO_IDBH: {
                'LIST': {
                    1: operation_id
                }
            }
        }
        ary_result = {}
        ret = self.restobj.rest_select(aryfilter, ary_result)
        if ret:
            row_count = self.restobj.rest_get_row_count(ary_result)
            if row_count < 1:
                # オペレーション未登録
                logger.system_log('LOSE01022', self.trace_id, target_table,
                                  self.response_id, self.execution_order,
                                  operation_id)
                logger.logic_log(
                    'LOSI00002', 'trace_id: %s, return: %s' %
                    (self.trace_id, Cstobj.RET_DATA_ERROR))
                ActionDriverCommonModules.SaveActionLog(
                    self.response_id, self.execution_order, self.trace_id,
                    'MOSJA01026')
                return Cstobj.RET_DATA_ERROR
            select_data = self.restobj.rest_get_row_data(ary_result)
            for row in select_data:
                row_data.append(row)
        else:
            logger.system_log('LOSE01000', self.trace_id, target_table,
                              'Filter', ary_result['status'])
            logger.logic_log(
                'LOSI00002', 'trace_id: %s, return: %s' %
                (self.trace_id, Cstobj.RET_REST_ERROR))
            ActionDriverCommonModules.SaveActionLog(self.response_id,
                                                    self.execution_order,
                                                    self.trace_id,
                                                    'MOSJA01026')
            return Cstobj.RET_REST_ERROR

        logger.logic_log('LOSI00002',
                         'trace_id: %s, return: %s' % (self.trace_id, 'True'))
        return 0
コード例 #4
0
    def select_c_movement_class_mng(self, result):
        """
        [概要]
        "Symphony紐付Movement一覧"検索メゾット
        正常終了なら0を、異常があればエラーコードを返す。
        """
        logger.logic_log('LOSI00001', 'trace_id: %s' % (self.trace_id))
        target_table = 'C_MOVEMENT_CLASS_MNG'
        self.restobj.menu_id = '2100000311'
        aryfilter = {
            Cstobj.COL_DISUSE_FLAG: {
                'NORMAL': '0'
            },
            Cstobj.CMCM_SYMPHONY_CLASS_NO: {
                'LIST': {
                    0: self.symphony_class_no
                }
            }
        }
        ary_result = {}
        ret = self.restobj.rest_select(aryfilter, ary_result)
        if ret:
            row_count = self.restobj.rest_get_row_count(ary_result)
            if row_count < 1:
                # Movement未登録
                logger.system_log('LOSE01018', self.trace_id, target_table,
                                  self.response_id, self.execution_order,
                                  self.symphony_class_no)
                logger.logic_log(
                    'LOSI00002', 'trace_id: %s, return: %s' %
                    (self.trace_id, Cstobj.RET_DATA_ERROR))
                ActionDriverCommonModules.SaveActionLog(
                    self.response_id, self.execution_order, self.trace_id,
                    'MOSJA01017')
                return Cstobj.RET_DATA_ERROR
            select_data = self.restobj.rest_get_row_data(ary_result)
            for row in select_data:
                result.append(row)
        else:
            logger.system_log('LOSE01000', self.trace_id, target_table,
                              'Filter', ary_result['status'])
            logger.logic_log(
                'LOSI00002', 'trace_id: %s, return: %s' %
                (self.trace_id, Cstobj.RET_REST_ERROR))
            ActionDriverCommonModules.SaveActionLog(self.response_id,
                                                    self.execution_order,
                                                    self.trace_id,
                                                    'MOSJA01016')
            return Cstobj.RET_REST_ERROR

        logger.logic_log('LOSI00002',
                         'trace_id: %s, return: %s' % (self.trace_id, 'True'))
        return 0
コード例 #5
0
    def select_c_stm_list(self, configs, action_servers,
                          action_server_id_names):
        """
        [概要]
          機器一覧検索メゾット
        """
        logger.logic_log(
            'LOSI00001',
            'trace_id: %s, configs: %s, action_servers: %s, action_server_id_names: %s'
            % (self.trace_id, configs, action_servers, action_server_id_names))
        target_table = 'C_STM_LIST'
        configs['menuID'] = '2100000303'
        self.restobj.rest_set_config(configs)
        for server_name in action_servers:
            aryfilter = {
                Cstobj.COL_DISUSE_FLAG: {
                    'NORMAL': '0'
                },
                Cstobj.CSL_HOSTNAME: {
                    'LIST': {
                        0: server_name
                    }
                }
            }
            ary_result = {}
            ret = self.restobj.rest_select(aryfilter, ary_result)
            if ret:
                row_count = self.restobj.rest_get_row_count(ary_result)
                if row_count < 1:
                    # 機器一覧に未登録
                    logger.system_log('LOSE01020', self.trace_id, target_table,
                                      self.response_id, self.execution_order,
                                      server_name)
                    ActionDriverCommonModules.SaveActionLog(
                        self.response_id, self.execution_order, self.trace_id,
                        'MOSJA01022')
                    return Cstobj.RET_DATA_ERROR
                row_data = self.restobj.rest_get_row_data(ary_result)
                # ホスト名とPkeyの対応表作成
                action_server_id_names[server_name] = row_data[0][
                    Cstobj.CSL_SYSTEM_ID] + ':' + server_name
            else:
                logger.system_log('LOSE01000', self.trace_id, target_table,
                                  'Filter', ary_result['status'])
                ActionDriverCommonModules.SaveActionLog(
                    self.response_id, self.execution_order, self.trace_id,
                    'MOSJA01021')
                return Cstobj.RET_REST_ERROR

        logger.logic_log('LOSI00002',
                         'trace_id: %s, return: 0' % (self.trace_id))
        return 0
コード例 #6
0
    def insert_c_parameter_sheet(self, host_name, operation_id, operation_name,
                                 exec_schedule_date, parameter_list):
        """
        [概要]
        パラメーターシート登録メソッド
        """
        logger.logic_log('LOSI00001', 'trace_id: %s' % self.trace_id)
        # TODO 紐づけテーブルができたらそれを参照するよう修正する
        self.restobj.menu_id = '0000000001'
        row_data_000001 = {}
        row_data_000001[Cstobj.COL_FUNCTION_NAME] = '登録'
        row_data_000001[Cstobj.COL_HOSTNAME] = host_name
        row_data_000001[Cstobj.COL_OPERATION_ID] = operation_id
        row_data_000001[Cstobj.COL_OPERATION_NAME_PARAM] = operation_name
        row_data_000001[
            Cstobj.COL_SCHEDULE_TIMESTAMP_ID_NAME] = exec_schedule_date
        # TODO 将来的にはfor文で回して設定する予定
        row_data_000001[Cstobj.COL_PARAMETER] = parameter_list[0]

        ary_result = {}
        ret = self.restobj.rest_insert(row_data_000001, ary_result)
        if not ret:
            target_table = 'C_PARAMETER_SHEET'
            logger.system_log('LOSE01021', self.trace_id, target_table,
                              self.response_id, self.execution_order)
            logger.system_log('LOSE01000', self.trace_id, target_table,
                              'Insert', ary_result['status'])
            ActionDriverCommonModules.SaveActionLog(self.response_id,
                                                    self.execution_order,
                                                    self.trace_id,
                                                    'MOSJA01066')
            return Cstobj.RET_REST_ERROR
        logger.logic_log('LOSI00002',
                         'trace_id: %s, return: %s' % (self.trace_id, 'True'))
        return 0
コード例 #7
0
    def ita_parameta_commitinfo_insert(self, execution_order, order, parameter_value):
        """
        [概要]
        ITAパラメータ実行管理登録メゾット
        """
        logger.logic_log('LOSI00001', 'execution_order: %s, order: %s, parameter_value: %s' % (
            execution_order, order, parameter_value))

        try:
            with transaction.atomic():
                itaparcom = ItaParametaCommitInfo(
                    response_id = self.response_id,
                    commit_order = execution_order,
                    ita_order = order,
                    parameter_value = parameter_value,
                    last_update_timestamp = Comobj.getStringNowDateTime(),
                    last_update_user = self.last_update_user,
                )
                itaparcom.save(force_insert=True)

        except Exception as e:
            logger.system_log('LOSE01133', self.trace_id, traceback.format_exc())
            ActionDriverCommonModules.SaveActionLog(self.response_id, execution_order, self.trace_id, 'MOSJA01071')
            return None

        logger.logic_log('LOSI00002', 'ItaParametaCommitInfo pk: %s' % itaparcom.pk)
        return itaparcom
コード例 #8
0
ファイル: ITA_driver.py プロジェクト: hokuto-fukunaga/oase
    def set_action_parameters(self, aryActionParameter, exe_order, res_detail_id):
        """
        [概要]
          ITAパラメータ解析
        """
        logger.logic_log('LOSI00001', 'aryActionParameter: %s' % (aryActionParameter))
        ActionDriverCommonModules.SaveActionLog(self.response_id, exe_order, self.trace_id, 'MOSJA01004')

        key1 = 'ACTION_PARAMETER_INFO'
        if key1 not in aryActionParameter:
            ActionDriverCommonModules.SaveActionLog(self.response_id, exe_order, self.trace_id, 'MOSJA01005')
            raise OASEError('', 'LOSE01114', log_params=[self.trace_id, 'OASE_T_RHDM_RESPONSE_ACTION', res_detail_id, key1], msg_params={'sts':ACTION_DATA_ERROR, 'detail':ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_PARAM_KEY})

        # ITA_NAME/SYMPHONY_CLASS_ID/OPERATION_ID/SERVER_LIST/MENU_ID/CONVERT_FLAG サーチ
        check_info = self.analysis_parameters(aryActionParameter[key1])
        for key, val in check_info.items():
            if val:
                self.aryActionParameter[key] = val
コード例 #9
0
ファイル: ITA_driver.py プロジェクト: hokuto-fukunaga/oase
 def set_driver(self, exe_order):
     """
     ITAドライバをセット
     """
     disp_name = self.aryActionParameter['ITA_NAME']
     try:
         self.ita_driver = ItaDriver.objects.get(ita_disp_name=disp_name)
     except ItaDriver.DoesNotExist:
         ActionDriverCommonModules.SaveActionLog(self.response_id, exe_order, self.trace_id, 'MOSJA01013')
         raise OASEError('', 'LOSE01115', log_params=['OASE_T_ITA_DRIVER', 'ITA_NAME', self.trace_id], msg_params={'sts':ACTION_DATA_ERROR, 'detail':ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_PARAM_VAL})
コード例 #10
0
ファイル: ITA_driver.py プロジェクト: hokuto-fukunaga/oase
    def ita_action_history_insert(self,aryAnzActionParameter,SymphonyInstanceNO,
            OperationID,SymphonyWorkflowURL, exe_order, parameter_item_info=''):
        """
        [概要]
        ITAアクション履歴登録メゾット
        """
        logger.logic_log('LOSI00001', 'trace_id: %s, aryAnzActionParameter: %s, ActionHistoryID: %s, SymphonyInstanceNO: %s, OperationID: %s, SymphonyWorkflowURL: %s' % (self.trace_id, aryAnzActionParameter, self.action_history.pk, SymphonyInstanceNO, OperationID, SymphonyWorkflowURL))

        try:
            with transaction.atomic():
                rcnt = ItaActionHistory.objects.filter(action_his_id=self.action_history.pk).count()
                if rcnt > 0:
                    itaacthist = ItaActionHistory.objects.get(action_his_id=self.action_history.pk)
                    itaacthist.ita_disp_name = aryAnzActionParameter['ITA_NAME']
                    itaacthist.symphony_instance_no = SymphonyInstanceNO
                    itaacthist.symphony_class_id = aryAnzActionParameter['SYMPHONY_CLASS_ID']
                    itaacthist.operation_id = OperationID
                    itaacthist.symphony_workflow_confirm_url = SymphonyWorkflowURL
                    itaacthist.last_update_timestamp = Comobj.getStringNowDateTime()
                    itaacthist.last_update_user = self.last_update_user
                    itaacthist.save(force_update=True)
                else:
                    itaacthist = ItaActionHistory(
                        action_his_id=self.action_history.pk,
                        ita_disp_name=aryAnzActionParameter['ITA_NAME'],
                        symphony_instance_no=SymphonyInstanceNO,
                        symphony_class_id=aryAnzActionParameter['SYMPHONY_CLASS_ID'],
                        operation_id=OperationID,
                        symphony_workflow_confirm_url=SymphonyWorkflowURL,
                        parameter_item_info=parameter_item_info,
                        last_update_timestamp=Comobj.getStringNowDateTime(),
                        last_update_user=self.last_update_user,
                    )
                    itaacthist.save(force_insert=True)

        except Exception as e:
            logger.system_log('LOSE01101', self.trace_id, traceback.format_exc())
            ActionDriverCommonModules.SaveActionLog(self.response_id, exe_order, self.trace_id, 'MOSJA01036')
            return None

        logger.logic_log('LOSI00002', 'ItaActionHistory pk: %s' % itaacthist.pk)
        return itaacthist
コード例 #11
0
    def select_substitution_value_mng(self, config, operation_name, menu_id,
                                      target_table):
        """
        [概要]
          代入値管理検索メゾット
        """
        logger.logic_log(
            'LOSI00001',
            'trace_id: %s, operation_name: %s, menu_id: %s, target_table: %s' %
            (self.trace_id, operation_name, menu_id, target_table))
        aryfilter = {
            Cstobj.COL_DISUSE_FLAG: {
                'NORMAL': '0'
            },
            3: {
                'NORMAL': operation_name
            }
        }

        config['menuID'] = menu_id
        self.restobj.rest_set_config(config)

        ary_result = {}
        ret = self.restobj.rest_select(aryfilter, ary_result)
        if ret:
            row_count = self.restobj.rest_get_row_count(ary_result)
            logger.logic_log(
                'LOSI00002',
                'trace_id: %s, return: %s' % (self.trace_id, 'True'))
            return row_count
        else:
            logger.system_log('LOSE01025', self.trace_id, self.restobj.menu_id,
                              'Filter', ary_result['status'])
            ActionDriverCommonModules.SaveActionLog(self.response_id,
                                                    self.execution_order,
                                                    self.trace_id,
                                                    'MOSJA01065')
            return None
コード例 #12
0
 def _insert_c_operation_list(self, insert_row_data):
     """
     [概要]
       投入オペレーション一覧登録メゾット
     """
     logger.logic_log('LOSI00001', 'trace_id: %s' % self.trace_id)
     self.restobj.menu_id = '2100000304'
     ary_result = {}
     ret = self.restobj.rest_insert(insert_row_data, ary_result)
     if not ret:
         target_table = 'C_OPERATION_LIST'
         logger.system_log('LOSE01021', self.trace_id, target_table,
                           self.response_id, self.execution_order)
         logger.system_log('LOSE01000', self.trace_id, target_table,
                           'Insert', ary_result['status'])
         ActionDriverCommonModules.SaveActionLog(self.response_id,
                                                 self.execution_order,
                                                 self.trace_id,
                                                 'MOSJA01025')
         return Cstobj.RET_REST_ERROR
     logger.logic_log('LOSI00002',
                      'trace_id: %s, return: %s' % (self.trace_id, 'True'))
     return 0
コード例 #13
0
 def _insert_b_ansible_pho_link(self, target_table, insert_row_data):
     """
     [概要]
       作業対象ホスト登録メゾット
     """
     logger.logic_log(
         'LOSI00001',
         'trace_id: %s, target_table: %s' % (self.trace_id, target_table))
     ary_result = {}
     ret = self.restobj.rest_insert(insert_row_data, ary_result)
     if not ret:
         logger.system_log('LOSE01021', self.trace_id, target_table,
                           self.response_id, self.execution_order)
         logger.system_log('LOSE01000', self.trace_id, target_table,
                           'Insert', ary_result['status'])
         ActionDriverCommonModules.SaveActionLog(self.response_id,
                                                 self.execution_order,
                                                 self.trace_id,
                                                 'MOSJA01027')
         return Cstobj.RET_REST_ERROR
     logger.logic_log('LOSI00002',
                      'trace_id: %s, return: 0' % self.trace_id)
     return 0
コード例 #14
0
    def act_with_menuid(self, act_his_id, exec_order):
        """
        [概要]
        """
        logger.logic_log('LOSI00001', 'self.trace_id: %s, act_his_id: %s, exec_order: %s' % (self.trace_id, act_his_id, exec_order))
        symphony_instance_id = 0
        operation_id = 0
        symphony_url = ''

        self.ITAobj = ITA1Core(self.trace_id, self.aryActionParameter['SYMPHONY_CLASS_ID'], self.response_id, exec_order)
        self.set_ary_ita_config()

        code = self.ITAobj.select_symphony_movement_master(self.ary_ita_config, self.ary_movement_list)

        if code > 0:
            logger.system_log('LOSE01107', self.trace_id, code)
            return ACTION_DATA_ERROR, ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_PARAM_VAL

        operation_name = '%s%s' % (self.trace_id, exec_order)

        operation_list = []
        ret = self.ITAobj._select_c_operation_list_by_operation_name(operation_name, operation_list)
        if ret > 0:
            logger.system_log('LOSE01011', self.trace_id, 'C_PATTERN_PER_ORCH', self.response_id, exec_order)
            logger.logic_log('LOSI00002', 'trace_id: %s, return: %s' % (self.trace_id, ret))

            ActionDriverCommonModules.SaveActionLog(self.response_id, exec_order, self.trace_id, 'MOSJA01040')
            return ACTION_EXEC_ERROR, DetailStatus

        operation_id = operation_list[0][Cstobj.COL_OPERATION_NO_IDBH]

        operation_id_name = operation_id + ":" + operation_name

        for movement_id, value in self.ary_movement_list.items():
            menu_id, target_table = self.orchestrator_id_to_menu_id(value['ORCHESTRATOR_ID'])

            if not menu_id or not target_table:
                logger.logic_log('LOSI00002', 'orchestrator_id: %s, menu_id: %s, target_table: %s' % (value['ORCHESTRATOR_ID'], menu_id, target_table))

                return ACTION_EXEC_ERROR, DetailStatus

            if not self.ITAobj.select_substitution_value_mng(self.ary_ita_config, operation_id_name, menu_id, target_table):
                logger.logic_log('LOSI00002', 'orchestrator_id: %s, menu_id: %s, target_table: %s' % (value['ORCHESTRATOR_ID'], menu_id, target_table))

                return ITA_REGISTERING_SUBSTITUTION_VALUE, ACTION_HISTORY_STATUS.DETAIL_STS.NONE

        # Symphony実行()
        code, symphony_instance_id, symphony_url = self.ITAobj.symphony_execute(self.ary_ita_config, operation_id)

        # ITAアクション履歴登録
        logger.logic_log('LOSI01104', str(exec_order), self.trace_id)
        ret = self.ita_action_history_insert(
            self.aryActionParameter,
            symphony_instance_id,
            operation_id,
            symphony_url,
            exec_order
        )

        logger.logic_log('LOSI00002', 'return: PROCESSED')
        return ACTION_HISTORY_STATUS.EXASTRO_REQUEST, ACTION_HISTORY_STATUS.DETAIL_STS.NONE
コード例 #15
0
ファイル: ITA_driver.py プロジェクト: hokuto-fukunaga/oase
    def set_information(self, rhdm_res_act, action_history):
        """
        [概要]
          ITA情報登録
        """
        logger.logic_log('LOSI00001', 'action_type_id: %s' % (rhdm_res_act.action_type_id))

        self.action_history = action_history

        param_info = json.loads(rhdm_res_act.action_parameter_info)

        try:
            # アクションサーバリストセット
            self.set_action_server_list(
                param_info, rhdm_res_act.execution_order, rhdm_res_act.response_detail_id)
            # アクションパラメータセット
            self.set_action_parameters(
                param_info, rhdm_res_act.execution_order, rhdm_res_act.response_detail_id)

            # アクションパラメーターチェック
            err_info = self.check_action_parameters()
            if err_info:
                ActionDriverCommonModules.SaveActionLog(
                    self.response_id,
                    rhdm_res_act.execution_order,
                    self.trace_id,
                    err_info['msg_id'],
                    **({'key': err_info['key']})
                )

                raise OASEError(
                    '',
                    'LOSE01114',
                    log_params=[self.trace_id, 'OASE_T_RHDM_RESPONSE_ACTION',
                                rhdm_res_act.response_detail_id, err_info['key']],
                    msg_params={'sts': ACTION_DATA_ERROR,
                                'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_PARAM_VAL}
                )

            # ドライバーセット
            self.set_driver(rhdm_res_act.execution_order)

        except OASEError as e:
            if e.log_id:
                if e.arg_list and isinstance(e.arg_list, list):
                    logger.system_log(e.log_id, *(e.arg_list))
                else:
                    logger.system_log(e.log_id)

            logger.system_log('LOSE01106', self.trace_id, ACTION_DATA_ERROR)

            if e.arg_dict and isinstance(e.arg_dict, dict) \
                    and 'sts' in e.arg_dict and 'detail' in e.arg_dict:
                return e.arg_dict['sts'], e.arg_dict['detail']

        except Exception as e:
            logger.system_log(*e.args)
            logger.system_log('LOSE01106', self.trace_id, ACTION_DATA_ERROR)
            return ACTION_DATA_ERROR, 0

        logger.logic_log('LOSI00002', 'return: True')
        return 0, 0
コード例 #16
0
ファイル: ITA_driver.py プロジェクト: hokuto-fukunaga/oase
    def act_with_menuid(self, act_his_id, exec_order):
        """
        [概要]
        """
        logger.logic_log('LOSI00001', 'self.trace_id: %s, act_his_id: %s, exec_order: %s' % (self.trace_id, act_his_id, exec_order))
        symphony_instance_id = 0
        operation_id = 0
        symphony_url = ''
        restapi_error_info = ''

        self.ITAobj = ITA1Core(self.trace_id, self.aryActionParameter['SYMPHONY_CLASS_ID'], self.response_id, exec_order)
        self.set_ary_ita_config()

        code = self.ITAobj.select_symphony_movement_master(self.ary_ita_config, self.ary_movement_list)

        if code > 0:
            logger.system_log('LOSE01107', self.trace_id, code)
            return ACTION_DATA_ERROR, ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_PARAM_VAL

        operation_name = '%s%s' % (self.trace_id, exec_order)

        operation_list = []
        ret = self.ITAobj._select_c_operation_list_by_operation_name(operation_name, operation_list)
        if ret > 0:
            logger.system_log('LOSE01011', self.trace_id, 'C_PATTERN_PER_ORCH', self.response_id, exec_order)
            logger.logic_log('LOSI00002', 'trace_id: %s, return: %s' % (self.trace_id, ret))

            ActionDriverCommonModules.SaveActionLog(self.response_id, exec_order, self.trace_id, 'MOSJA01040')
            return ACTION_EXEC_ERROR, DetailStatus

        operation_id = operation_list[0][Cstobj.COL_OPERATION_NO_IDBH]

        operation_id_name = operation_id + ":" + operation_name

        # オーケストレーターID別のムーブメントIDリストを作成
        orch_move_list = {}
        for movement_id, value in self.ary_movement_list.items():
            if value['ORCHESTRATOR_ID'] not in orch_move_list:
                orch_move_list[value['ORCHESTRATOR_ID']] = []

            orch_move_list[value['ORCHESTRATOR_ID']].append(movement_id)

        # オーケストレーターID別の変数カウントを取得
        var_count = {}
        for orch_id, movement_ids in orch_move_list.items():
            menu_id, target_table, target_col = self.orchestrator_id_to_menu_movement(orch_id)
            if not menu_id or not target_table:
                logger.logic_log('LOSI00002', 'orchestrator_id: %s, menu_id: %s, target_table: %s' % (orch_id, menu_id, target_table))
                return ACTION_EXEC_ERROR, DetailStatus

            if orch_id not in var_count:
                var_count[orch_id] = 0

            ret = self.ITAobj.select_e_movent_list(self.ary_ita_config, movement_ids, orch_id, menu_id, target_table, target_col, var_count)
            if ret > 0:
                logger.system_log('LOSE01011', self.trace_id, 'C_PATTERN_PER_ORCH', self.response_id, exec_order)
                logger.logic_log('LOSI00002', 'trace_id: %s, return: %s' % (self.trace_id, ret))

                ActionDriverCommonModules.SaveActionLog(self.response_id, exec_order, self.trace_id, 'MOSJA01040')
                return ACTION_EXEC_ERROR, DetailStatus

        # 変数カウントのあるパラメーターシートに対して取得要求
        total_count = 0
        subst_count = 0
        for orch_id, num in var_count.items():
            total_count += num

            if num <= 0:
                continue

            menu_id, target_table = self.orchestrator_id_to_menu_id(orch_id)

            if not menu_id or not target_table:
                logger.logic_log('LOSI00002', 'orchestrator_id: %s, menu_id: %s, target_table: %s' % (orch_id, menu_id, target_table))

                return ACTION_EXEC_ERROR, DetailStatus

            ret = self.ITAobj.select_substitution_value_mng(self.ary_ita_config, operation_id_name, menu_id, target_table)
            if ret is None or (isinstance(ret, list) and len(ret) <= 0):
                logger.logic_log('LOSI00002', 'orchestrator_id: %s, menu_id: %s, target_table: %s' % (orch_id, menu_id, target_table))

                return ACTION_HISTORY_STATUS.ITA_REGISTERING_SUBSTITUTION_VALUE, ACTION_HISTORY_STATUS.DETAIL_STS.NONE

            subst_count += ret

        if subst_count < total_count:
            logger.logic_log('LOSI00002', 'trace_id: %s, subst_count: %s, total_count: %s' % (self.trace_id, subst_count, total_count))
            return ACTION_HISTORY_STATUS.ITA_REGISTERING_SUBSTITUTION_VALUE, ACTION_HISTORY_STATUS.DETAIL_STS.NONE

        # Symphony実行()
        code, symphony_instance_id, symphony_url = self.ITAobj.symphony_execute(self.ary_ita_config, operation_id)

        # ITAアクション履歴登録
        logger.logic_log('LOSI01104', str(exec_order), self.trace_id)
        ret = self.ita_action_history_insert(
            self.aryActionParameter,
            symphony_instance_id,
            operation_id,
            symphony_url,
            exec_order
        )

        logger.logic_log('LOSI00002', 'return: PROCESSED')
        return ACTION_HISTORY_STATUS.EXASTRO_REQUEST, ACTION_HISTORY_STATUS.DETAIL_STS.NONE
コード例 #17
0
ファイル: ITA_driver.py プロジェクト: hokuto-fukunaga/oase
    def act(self, rhdm_res_act, retry=False):
        """
        [概要]
            ITAアクションを実行
        """
        logger.logic_log('LOSI00001', 'self.trace_id: %s' % (self.trace_id,))
        ActionStatus = ACTION_EXEC_ERROR
        DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.NONE

        list_operation_id = []
        symphony_instance_id = None
        symphony_url = ''
        server_list = ''
        operation_id = None
        menu_id = None
        convert_flg = None
        dt_host_name = None
        hostgroup_name = None

        param_info = json.loads(rhdm_res_act.action_parameter_info)

        status, detail = self.check_ita_master(rhdm_res_act.execution_order)
        if status > 0:
            raise OASEError('', 'LOSE01129', log_params=[self.trace_id], msg_params={
                            'sts': status, 'detail': detail})

        key1 = 'ACTION_PARAMETER_INFO'
        if key1 not in param_info:
            ActionDriverCommonModules.SaveActionLog(
                self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01005')
            raise OASEError('', 'LOSE01114', log_params=[self.trace_id, 'OASE_T_RHDM_RESPONSE_ACTION', rhdm_res_act.response_detail_id, key1], msg_params={
                            'sts': ACTION_DATA_ERROR, 'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_SRVLIST_KEY})

        # OPERATION_ID/SERVER_LIST/MENU_ID サーチ
        key_operation_id = 'OPERATION_ID'
        key_server_list = 'SERVER_LIST'
        key_menu_id = 'MENU_ID'
        key_convert_flg = 'CONVERT_FLG'
        key_hostgroup_name = 'HOSTGROUP_NAME'
        key_dt_host_name = 'HOST_NAME'
        check_info = self.analysis_parameters(param_info[key1])

        # OPERATION_IDのパターン
        if key_operation_id in check_info:
            if len(check_info[key_operation_id]) == 0:
                ActionDriverCommonModules.SaveActionLog(
                    self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01059')
                raise OASEError('', 'LOSE01128', log_params=['OASE_T_RHDM_RESPONSE_ACTION', rhdm_res_act.response_detail_id, key_operation_id, self.trace_id], msg_params={
                                'sts': ACTION_DATA_ERROR, 'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_OPEID_VAL})

            operation_id = check_info[key_operation_id]

        # SERVER_LISTのパターン
        elif key_server_list in check_info:
            if len(check_info[key_server_list]) == 0:
                ActionDriverCommonModules.SaveActionLog(
                    self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01064')
                raise OASEError('', 'LOSE01130', log_params=['OASE_T_RHDM_RESPONSE_ACTION', rhdm_res_act.response_detail_id, key_server_list, self.trace_id], msg_params={
                                'sts': ACTION_DATA_ERROR, 'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_OPEID_VAL})

            if retry:
                # 再実行の際、登録前にエラーになっていた場合は登録処理から行う。
                ret = self.ITAobj.select_ope_ita_master(
                    self.ary_ita_config, operation_id)
                if ret == Cstobj.RET_DATA_ERROR:
                    ActionDriverCommonModules.SaveActionLog(
                        self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01056')
                    ret = self.ITAobj.insert_ita_master(
                        self.ary_ita_config, self.ary_movement_list, self.ary_action_server_id_name, list_operation_id)

            else:
                ret = self.ITAobj.insert_ita_master(
                    self.ary_ita_config, self.ary_movement_list, self.ary_action_server_id_name, list_operation_id)
                if ret > 0:
                    DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_OPEID_FAIL
            operation_id = list_operation_id[0]

        # MENU_IDのパターン
        elif key_menu_id in check_info:
            if len(check_info[key_menu_id]) == 0:
                ActionDriverCommonModules.SaveActionLog(
                    self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01070')
                raise OASEError('', 'LOSE01132', log_params=['OASE_T_RHDM_RESPONSE_ACTION', rhdm_res_act.response_detail_id, key_menu_id, self.trace_id], msg_params={
                                'sts': ACTION_DATA_ERROR, 'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_OPEID_VAL})

            if len(check_info[key_convert_flg]) == 0 or not check_info[key_convert_flg] or (check_info[key_convert_flg].upper() != 'TRUE' and check_info[key_convert_flg].upper() != 'FALSE'):
                raise OASEError('', 'LOSE01134', log_params=['OASE_T_RHDM_RESPONSE_ACTION', rhdm_res_act.response_detail_id, key_convert_flg, self.trace_id], msg_params={
                                'sts': ACTION_DATA_ERROR, 'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_OPEID_VAL})

            if key_hostgroup_name in check_info:
                hostgroup_name = check_info[key_hostgroup_name]
                if not hostgroup_name:
                    raise OASEError('', 'LOSE0113X', log_params=['OASE_T_RHDM_RESPONSE_ACTION', rhdm_res_act.response_detail_id, key_convert_flg, self.trace_id], msg_params={
                                    'sts': ACTION_DATA_ERROR, 'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_OPEID_VAL})

            if key_dt_host_name in check_info:
                dt_host_name = check_info[key_dt_host_name]
                if not dt_host_name:
                    raise OASEError('', 'LOSE0113X', log_params=['OASE_T_RHDM_RESPONSE_ACTION', rhdm_res_act.response_detail_id, key_convert_flg, self.trace_id], msg_params={
                                    'sts': ACTION_DATA_ERROR, 'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_OPEID_VAL})

            menu_id = check_info[key_menu_id]
            convert_flg = check_info[key_convert_flg]

            menu_id_list = menu_id.split(':')
            if len(menu_id_list) != 1 and convert_flg.upper() == 'TRUE':
                raise OASEError('', 'LOSE01137', log_params=['OASE_T_RHDM_RESPONSE_ACTION', rhdm_res_act.response_detail_id, key_convert_flg, self.trace_id], msg_params={
                                'sts': ACTION_DATA_ERROR, 'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_OPEID_VAL})

            target_host_name = {}

            for menu_id in menu_id_list:
                if menu_id not in target_host_name:
                    target_host_name[menu_id] = {
                        'H': [],
                        'HG': [],
                    }

            if hostgroup_name:
                target_host_name = self.set_host_data(target_host_name, 'HG', hostgroup_name)

            if dt_host_name:
                target_host_name = self.set_host_data(target_host_name, 'H', dt_host_name)

            host_name = None
            events_request = EventsRequest.objects.get(trace_id=self.trace_id)
            if convert_flg.upper() == 'FALSE':
                commitinfo_list = ItaParametaCommitInfo.objects.filter(response_id=self.response_id, commit_order=rhdm_res_act.execution_order).order_by('ita_order')
                if len(commitinfo_list) == 0:
                    commitinfo_list = []
                    for menu_id in menu_id_list:
                        ita_param_matchinfo_list = list(ItaParameterMatchInfo.objects.filter(menu_id=menu_id).order_by('match_id'))
                        events_request = EventsRequest.objects.get(trace_id=self.trace_id)
                        data_object_list = list(DataObject.objects.filter(rule_type_id=events_request.rule_type_id).order_by('data_object_id'))

                        for match in ita_param_matchinfo_list:
                            label_list = []
                            for obj in data_object_list:

                                if match.conditional_name == obj.conditional_name and not obj.label in label_list:
                                    label_list.append(obj.label)
                                    number = int(obj.label[5:])
                                    message = ast.literal_eval(events_request.event_info)['EVENT_INFO'][number]

                                    parameter_value = ''

                                    pattern = match.extraction_method1
                                    m = re.search(pattern, message)
                                    if m is None:
                                        continue
                                    elif match.extraction_method2 == '':
                                        parameter_value = m.group(0).strip()
                                    elif match.extraction_method2 != '':
                                        value = m.group(0).split(match.extraction_method2)
                                        parameter_value = value[1].strip()

                                    itaparcom = ItaParametaCommitInfo(
                                        response_id = self.response_id,
                                        commit_order = rhdm_res_act.execution_order,
                                        menu_id = int(menu_id),
                                        ita_order = match.order,
                                        parameter_value = parameter_value,
                                        last_update_timestamp = Comobj.getStringNowDateTime(),
                                        last_update_user = self.last_update_user,
                                    )
                                    commitinfo_list.append(itaparcom)

                    try:
                        ItaParametaCommitInfo.objects.bulk_create(commitinfo_list)
                    except Exception as e:
                        logger.system_log('LOSE01133', self.trace_id, traceback.format_exc())
                        ActionDriverCommonModules.SaveActionLog(
                            self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01071')
                        return ACTION_EXEC_ERROR, DetailStatus

                parameter_list = {}

                commitinfo_list = ItaParametaCommitInfo.objects.filter(response_id=self.response_id, commit_order=rhdm_res_act.execution_order).order_by('ita_order')
                for commit_info in commitinfo_list:
                    if commit_info.menu_id not in parameter_list:
                        parameter_list[commit_info.menu_id] = {'host_name':'', 'param_list':[]}

                    if commit_info.ita_order == 0:
                        parameter_list[commit_info.menu_id]['host_name'] = commit_info.parameter_value
                    else:
                        parameter_list[commit_info.menu_id]['param_list'].append(commit_info.parameter_value)

            elif convert_flg.upper() == 'TRUE':
                menu_id = int(menu_id_list[0])
                parameter_list = {}

                event_info_list = ast.literal_eval(events_request.event_info)['EVENT_INFO']
                if len(event_info_list) == 0:
                    logger.system_log('LOSE01135', self.trace_id, traceback.format_exc())
                    return ACTION_EXEC_ERROR, DetailStatus

                for i, v in enumerate(event_info_list):
                    if menu_id not in parameter_list:
                        parameter_list[menu_id] = {'host_name':'', 'param_list':[]}

                    if i == 0:
                        parameter_list[menu_id]['host_name'] = event_info_list[0]
                    else:
                        parameter_list[menu_id]['param_list'].append(event_info_list[i])

            for k, v in parameter_list.items():
                if not v['host_name']:
                    logger.system_log('LOSE01136', self.trace_id, traceback.format_exc())
                    return ACTION_EXEC_ERROR, DetailStatus

            operation_data = []
            if retry:
                operation_name = '%s%s' % (self.trace_id, rhdm_res_act.execution_order)
                ret = self.ITAobj._select_c_operation_list_by_operation_name(operation_name, operation_data, False)
                if ret == Cstobj.RET_DATA_ERROR:
                    ActionDriverCommonModules.SaveActionLog(
                        self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01056')

                    operation_name = ''
                    ret, operation_name = self.ITAobj.insert_operation(self.ary_ita_config)
                    if ret != True:
                        logger.system_log('LOSE01110', ActionStatus, self.trace_id)
                        DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_OPEID_FAIL

                        return ACTION_EXEC_ERROR, DetailStatus

                    ret, operation_data = self.ITAobj.select_operation(
                        self.ary_ita_config, operation_name)
                    if ret != True:
                        logger.system_log('LOSE01110', ActionStatus, self.trace_id)
                        DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_OPEID_FAIL

                        return ACTION_EXEC_ERROR, DetailStatus
                elif ret == Cstobj.RET_REST_ERROR:
                    logger.system_log('LOSE01110', ActionStatus, self.trace_id)
                    DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_OPEID_FAIL

                    return ACTION_EXEC_ERROR, DetailStatus

            else:
                # オペレーションID登録
                ret, operation_name = self.ITAobj.insert_operation(self.ary_ita_config)
                if ret != True:
                    logger.system_log('LOSE01110', ActionStatus, self.trace_id)
                    DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_OPEID_FAIL

                    return ACTION_EXEC_ERROR, DetailStatus

                # オペレーション検索
                ret, operation_data = self.ITAobj.select_operation(self.ary_ita_config, operation_name)
                if ret != True:
                    logger.system_log('LOSE01110', ActionStatus, self.trace_id)
                    DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_OPEID_FAIL

                    return ACTION_EXEC_ERROR, DetailStatus

            # パラメータシート登録情報作成
            operation_id = operation_data[0][Cstobj.COL_OPERATION_NO_IDBH]
            operation_name = operation_data[0][Cstobj.COL_OPERATION_NAME]
            exec_schedule_date = '%s_%s:%s' % (
                operation_data[0][Cstobj.COL_OPERATION_DATE],
                operation_data[0][Cstobj.COL_OPERATION_NO_IDBH],
                operation_data[0][Cstobj.COL_OPERATION_NAME])

            hg_flg_info = {}
            rset = ItaMenuName.objects.filter(ita_driver_id=self.ita_driver.ita_driver_id, menu_id__in=menu_id_list)
            rset = rset.values('menu_id', 'hostgroup_flag')
            for r in rset:
                hg_flg_info[r['menu_id']] = r['hostgroup_flag']

            for menu_id in menu_id_list:
                menu_id = int(menu_id)
                host_name = ''
                param_list = []

                if menu_id not in hg_flg_info:
                    logger.system_log(
                        'LOSM01101', self.trace_id, self.response_id, rhdm_res_act.execution_order, menu_id
                    )
                    return ACTION_EXEC_ERROR, ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_PARAM_FAIL

                if not parameter_list[menu_id]['host_name']:
                    logger.system_log(
                        'LOSE01138', self.trace_id, self.response_id, rhdm_res_act.execution_order, menu_id
                    )
                    return ACTION_EXEC_ERROR, ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_PARAM_FAIL

                set_host = []
                target_id = str(menu_id)
                if target_id in target_host_name.keys():
                    for h in target_host_name[target_id]['HG']:
                        host_name_tmp = '[HG]%s' % (h) if hg_flg_info[menu_id] else h

                        set_host.append(host_name_tmp)

                    for h in target_host_name[target_id]['H']:
                        host_name_tmp = '[H]%s' % (h) if hg_flg_info[menu_id] else h
                        set_host.append(host_name_tmp)

                if len(set_host) == 0 and menu_id in parameter_list and parameter_list[menu_id]['host_name']:
                    h = parameter_list[menu_id]['host_name']
                    host_name_tmp = '[H]%s' % (h) if hg_flg_info[menu_id] else h
                    set_host.append(host_name_tmp)

                param_list = parameter_list[menu_id]['param_list']

                if len(set_host) == 0:
                    # Error
                    logger.system_log(
                        'LOSM01101', self.trace_id, self.response_id, rhdm_res_act.execution_order, menu_id
                    )
                    return ACTION_EXEC_ERROR, ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_PARAM_FAIL

                for sh in set_host:
                    host_name = sh
                    ret = self.ITAobj.insert_c_parameter_sheet(
                        host_name, operation_id, operation_name, exec_schedule_date, param_list, str(menu_id).zfill(10))
                    if ret == Cstobj.RET_REST_ERROR:
                        logger.system_log('LOSE01110', ActionStatus, self.trace_id)
                        DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_PARAM_FAIL

                        return ACTION_EXEC_ERROR, DetailStatus

                ActionDriverCommonModules.SaveActionLog(
                    self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01067')

            # 連携項目整形
            parameter_item_info = self.make_parameter_item_info(menu_id_list, rhdm_res_act, target_host_name)

            # ITAアクション履歴登録
            ret = self.ita_action_history_insert(
                self.aryActionParameter,
                symphony_instance_id,
                operation_id,
                symphony_url,
                rhdm_res_act.execution_order,
                parameter_item_info
            )

            return ACTION_HISTORY_STATUS.ITA_REGISTERING_SUBSTITUTION_VALUE, DetailStatus

        ret = self.ITAobj.select_ope_ita_master(
            self.ary_ita_config, operation_id)
        if ret == Cstobj.RET_DATA_ERROR:
            raise OASEError('', 'LOSE01128', log_params=['OASE_T_RHDM_RESPONSE_ACTION', rhdm_res_act.response_detail_id, key_operation_id, self.trace_id], msg_params={
                            'sts': ACTION_DATA_ERROR, 'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_OPEID_VAL})

        code, symphony_instance_id, symphony_url = self.ITAobj.symphony_execute(
            self.ary_ita_config, operation_id)
        if code == 0:
            ActionStatus = PROCESSED

        else:
            DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_SYMP_FAIL

        logger.logic_log('LOSI01105', ActionStatus, rhdm_res_act.execution_order, self.trace_id)

        # ITAアクション履歴登録
        logger.logic_log('LOSI01104', str(rhdm_res_act.execution_order), self.trace_id)
        ret = self.ita_action_history_insert(
            self.aryActionParameter,
            symphony_instance_id,
            operation_id,
            symphony_url,
            rhdm_res_act.execution_order
        )

        # Symphonyに失敗した場合は異常終了する。
        if ActionStatus != PROCESSED:
            logger.system_log('LOSE01110', ActionStatus, self.trace_id)
            ActionDriverCommonModules.SaveActionLog(self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01040')
            return ACTION_EXEC_ERROR, DetailStatus

        logger.logic_log('LOSI00002', 'return: PROCESSED')
        return ACTION_HISTORY_STATUS.EXASTRO_REQUEST, DetailStatus
コード例 #18
0
    def rest_symphony_execute(self, symphony_class_no, operation_id,
                              list_symphony_instance_id, ary_result, resp_id,
                              exe_order):
        """
        [概要]
          ITA RestAPI Symphony実行メゾット
        """
        logger.logic_log(
            'LOSI00001',
            'trace_id: %s, symphony_class_no: %s, operation_id: %s, list_symphony_instance_id: %s'
            % (self.trace_id, symphony_class_no, operation_id,
               list_symphony_instance_id))
        # サ事開用設定
        proxies = {
            "http": None,
            "https": None,
        }

        keystr = self.user + ':' + self.password
        access_key_id = base64.encodestring(
            keystr.encode('utf8')).decode("ascii").replace('\n', '')
        url = "{}://{}:{}/default/menu/07_rest_api_ver1.php?no={}".format(
            self.protocol, self.host, self.portno, self.menu_id)

        logger.system_log('LOSI01000', url, self.trace_id)

        headers = {
            'host': '%s:%s' % (self.host, self.portno),
            'Content-Type': 'application/json',
            'Authorization': access_key_id
        }

        # X-Command
        headers['X-Command'] = 'EXECUTE'

        # SymphonyクラスIDとオペレーションを設定
        ary_execute = {}
        ary_execute['SYMPHONY_CLASS_NO'] = symphony_class_no
        ary_execute['OPERATION_ID'] = operation_id

        str_para_json_encoded = json.dumps(ary_execute)

        try:
            response = requests.post(
                url,
                headers=headers,
                timeout=30,
                verify=False,
                data=str_para_json_encoded.encode('utf-8'),
                proxies=proxies)
            ary_result['status'] = response.status_code
            ary_result['text'] = response.text

            try:
                json_string = json.dumps(response.json(),
                                         ensure_ascii=False,
                                         separators=(',', ': '))
                ary_result['response'] = json.loads(json_string)

                if ary_result['status'] != 200:
                    ary_result['response'] = json_string
                    logger.system_log('LOSM01300', self.trace_id,
                                      ary_execute['SYMPHONY_CLASS_NO'],
                                      ary_execute['OPERATION_ID'],
                                      ary_result['status'], ary_result['text'])
                    logger.logic_log(
                        'LOSI00002',
                        'trace_id: %s, return: %s' % (self.trace_id, 'False'))
                    ActionDriverCommonModules.SaveActionLog(
                        resp_id, exe_order, self.trace_id, 'MOSJA01030')
                    return False

                if ary_result['response']['status'] != 'SUCCEED':
                    ary_result['response'] = json_string
                    logger.logic_log('LOSM01300', self.trace_id,
                                     ary_execute['SYMPHONY_CLASS_NO'],
                                     ary_execute['OPERATION_ID'],
                                     ary_result['status'], ary_result['text'])
                    logger.logic_log(
                        'LOSI00002',
                        'trace_id: %s, return: %s' % (self.trace_id, 'False'))
                    ActionDriverCommonModules.SaveActionLog(
                        resp_id, exe_order, self.trace_id, 'MOSJA01029')
                    return False

                list_symphony_instance_id.append(
                    ary_result['response']['resultdata']
                    ['SYMPHONY_INSTANCE_ID'])

            except Exception as ex:
                ary_result['status'] = '-1'
                back_trace = ActionDriverCommonModules.back_trace()
                ary_result['response'] = back_trace + '\nresponse.status_code:' + \
                    str(response.status_code) + '\nresponse.text\n' + response.text
                logger.system_log('LOSM01301', self.trace_id,
                                  traceback.format_exc())
                logger.logic_log(
                    'LOSI00002',
                    'trace_id: %s, return: %s' % (self.trace_id, 'False'))
                ActionDriverCommonModules.SaveActionLog(
                    resp_id, exe_order, self.trace_id, 'MOSJA01031')
                return False

        except Exception as ex:
            ary_result['status'] = '-1'
            back_trace = ActionDriverCommonModules.back_trace()
            ary_result['response'] = back_trace + '\nhttp header\n' + str(
                headers)
            logger.system_log('LOSM01301', self.trace_id,
                              traceback.format_exc())
            logger.logic_log(
                'LOSI00002',
                'trace_id: %s, return: %s' % (self.trace_id, 'False'))
            ActionDriverCommonModules.SaveActionLog(resp_id, exe_order,
                                                    self.trace_id,
                                                    'MOSJA01032')
            return False

        logger.logic_log('LOSI00002',
                         'trace_id: %s, return: %s' % (self.trace_id, 'True'))
        ActionDriverCommonModules.SaveActionLog(resp_id, exe_order,
                                                self.trace_id, 'MOSJA01028')
        return True
コード例 #19
0
    def act(self, rhdm_res_act, retry=False):
        """
        [概要]
            ITAアクションを実行
        """
        logger.logic_log('LOSI00001', 'self.trace_id: %s' % (self.trace_id,))
        ActionStatus = ACTION_EXEC_ERROR
        DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.NONE

        list_operation_id = []
        symphony_instance_id = 0
        symphony_url = ''
        server_list = ''
        operation_id = None
        menu_id = None

        param_info = json.loads(rhdm_res_act.action_parameter_info)

        status, detail = self.check_ita_master(rhdm_res_act.execution_order)
        if status > 0:
            raise OASEError('', 'LOSE01129', log_params=[self.trace_id], msg_params={
                            'sts': status, 'detail': detail})

        key1 = 'ACTION_PARAMETER_INFO'
        if key1 not in param_info:
            ActionDriverCommonModules.SaveActionLog(
                self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01005')
            raise OASEError('', 'LOSE01114', log_params=[self.trace_id, 'OASE_T_RHDM_RESPONSE_ACTION', rhdm_res_act.response_detail_id, key1], msg_params={
                            'sts': ACTION_DATA_ERROR, 'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_SRVLIST_KEY})

        # OPERATION_ID/SERVER_LIST サーチ
        key_operation_id = 'OPERATION_ID'
        key_server_list = 'SERVER_LIST'
        key_menu_id = 'MENU_ID'
        check_info = self.analysis_parameters(param_info[key1])

        if key_operation_id in check_info:
            if len(check_info[key_operation_id]) == 0:
                ActionDriverCommonModules.SaveActionLog(
                    self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01059')
                raise OASEError('', 'LOSE01128', log_params=['OASE_T_RHDM_RESPONSE_ACTION', rhdm_res_act.response_detail_id, key_operation_id, self.trace_id], msg_params={
                                'sts': ACTION_DATA_ERROR, 'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_OPEID_VAL})

            operation_id = check_info[key_operation_id]

        elif key_server_list in check_info:
            if len(check_info[key_server_list]) == 0:
                ActionDriverCommonModules.SaveActionLog(
                    self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01064')
                raise OASEError('', 'LOSE01130', log_params=['OASE_T_RHDM_RESPONSE_ACTION', rhdm_res_act.response_detail_id, key_server_list, self.trace_id], msg_params={
                                'sts': ACTION_DATA_ERROR, 'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_OPEID_VAL})

            server_list = check_info[key_server_list]

        elif key_menu_id in check_info:
            if len(check_info[key_menu_id]) == 0:
                ActionDriverCommonModules.SaveActionLog(
                    self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01070')
                raise OASEError('', 'LOSE01132', log_params=['OASE_T_RHDM_RESPONSE_ACTION', rhdm_res_act.response_detail_id, key_server_list, self.trace_id], msg_params={
                                'sts': ACTION_DATA_ERROR, 'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_OPEID_VAL})

            menu_id = check_info[key_menu_id]

        # MENU_IDのパターン
        if menu_id:
            # 抽出条件
            ita_param_matchinfo_list = list(ItaParameterMatchInfo.objects.filter(menu_id=menu_id).order_by('match_id'))

            # イベント情報抽出
            events_request = EventsRequest.objects.get(trace_id=self.trace_id)

            # 条件名
            data_object_list = list(DataObject.objects.filter(
                rule_type_id=events_request.rule_type_id).order_by('data_object_id'))

            # イベント情報
            for match in ita_param_matchinfo_list:
                label_list = []
                for obj in data_object_list:
                    if match.conditional_name == obj.conditional_name and not obj.label in label_list:
                        label_list.append(obj.label)
                        number = int(obj.label[5:])
                        message = ast.literal_eval(events_request.event_info)['EVENT_INFO'][number]

                        pattern = match.extraction_method1
                        m = re.search(pattern, message)

                        if m is None:
                            continue
                        elif match.extraction_method2 == '':
                            parameter_value = m.group(0).strip()
                        elif match.extraction_method2 != '':
                            value = m.group(0).split(match.extraction_method2)
                            parameter_value = value[1].strip()

                        ret = self.ita_parameta_commitinfo_insert(
                            rhdm_res_act.execution_order, match.order, parameter_value)

                        if ret is None:
                            return ACTION_EXEC_ERROR, DetailStatus

            return PROCESSED, DetailStatus

        # パラメータシート登録パターン
        if not operation_id and not server_list:
            operation_data = []
            if retry:
                operation_name = '%s%s' % (self.trace_id, rhdm_res_act.execution_order)
                ret = self.ITAobj._select_c_operation_list_by_operation_name(operation_name, operation_data, False)
                if ret == Cstobj.RET_DATA_ERROR:
                    ActionDriverCommonModules.SaveActionLog(
                        self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01056')

                    operation_name = ''
                    ret, operation_name = self.ITAobj.insert_operation(self.ary_ita_config)
                    if ret != True:
                        logger.system_log('LOSE01110', ActionStatus, self.trace_id)
                        DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_OPEID_FAIL

                        return ACTION_EXEC_ERROR, DetailStatus

                    ret, operation_data = self.ITAobj.select_operation(
                        self.ary_ita_config, operation_name)
                    if ret != True:
                        logger.system_log('LOSE01110', ActionStatus, self.trace_id)
                        DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_OPEID_FAIL

                        return ACTION_EXEC_ERROR, DetailStatus
                elif ret == Cstobj.RET_REST_ERROR:
                    logger.system_log('LOSE01110', ActionStatus, self.trace_id)
                    DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_OPEID_FAIL

                    return ACTION_EXEC_ERROR, DetailStatus

            else:
                # オペレーションID登録
                ret, operation_name = self.ITAobj.insert_operation(self.ary_ita_config)
                if ret != True:
                    logger.system_log('LOSE01110', ActionStatus, self.trace_id)
                    DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_OPEID_FAIL

                    return ACTION_EXEC_ERROR, DetailStatus

                # オペレーション検索
                ret, operation_data = self.ITAobj.select_operation(self.ary_ita_config, operation_name)
                if ret != True:
                    logger.system_log('LOSE01110', ActionStatus, self.trace_id)
                    DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_OPEID_FAIL

                    return ACTION_EXEC_ERROR, DetailStatus

            # パラメータシート登録
            parameter_list = []
            events_request = EventsRequest.objects.get(trace_id=self.trace_id)
            host_name = ast.literal_eval(events_request.event_info)['EVENT_INFO'][0]
            operation_id = operation_data[0][Cstobj.COL_OPERATION_NO_IDBH]
            operation_name = operation_data[0][Cstobj.COL_OPERATION_NAME]
            exec_schedule_date = '%s_%s:%s' % (
                operation_data[0][Cstobj.COL_OPERATION_DATE],
                operation_data[0][Cstobj.COL_OPERATION_NO_IDBH],
                operation_data[0][Cstobj.COL_OPERATION_NAME])
            parameter_list.append(ast.literal_eval(events_request.event_info)['EVENT_INFO'][1])

            ret = self.ITAobj.insert_c_parameter_sheet(
                host_name, operation_id, operation_name, exec_schedule_date, parameter_list)
            if ret == Cstobj.RET_REST_ERROR:
                logger.system_log('LOSE01110', ActionStatus, self.trace_id)
                DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_PARAM_FAIL

                return ACTION_EXEC_ERROR, DetailStatus

            ActionDriverCommonModules.SaveActionLog(
                self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01067')

            return ACTION_HISTORY_STATUS.ITA_REGISTERING_SUBSTITUTION_VALUE, DetailStatus

        # SERVER_LISTのパターン
        if server_list:
            if retry:
                # 再実行の際、登録前にエラーになっていた場合は登録処理から行う。
                ret = self.ITAobj.select_ope_ita_master(
                    self.ary_ita_config, operation_id)
                if ret == Cstobj.RET_DATA_ERROR:
                    ActionDriverCommonModules.SaveActionLog(
                        self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01056')
                    ret = self.ITAobj.insert_ita_master(
                        self.ary_ita_config, self.ary_movement_list, self.ary_action_server_id_name, list_operation_id)

            else:
                ret = self.ITAobj.insert_ita_master(
                    self.ary_ita_config, self.ary_movement_list, self.ary_action_server_id_name, list_operation_id)
                if ret > 0:
                    DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_OPEID_FAIL
            operation_id = list_operation_id[0]

        ret = self.ITAobj.select_ope_ita_master(
            self.ary_ita_config, operation_id)
        if ret == Cstobj.RET_DATA_ERROR:
            raise OASEError('', 'LOSE01128', log_params=['OASE_T_RHDM_RESPONSE_ACTION', rhdm_res_act.response_detail_id, key_operation_id, self.trace_id], msg_params={
                            'sts': ACTION_DATA_ERROR, 'detail': ACTION_HISTORY_STATUS.DETAIL_STS.DATAERR_OPEID_VAL})

        code, symphony_instance_id, symphony_url = self.ITAobj.symphony_execute(
            self.ary_ita_config, operation_id)
        if code == 0:
            ActionStatus = PROCESSED

        else:
            DetailStatus = ACTION_HISTORY_STATUS.DETAIL_STS.EXECERR_SYMP_FAIL

        logger.logic_log('LOSI01105', ActionStatus, rhdm_res_act.execution_order, self.trace_id)

        # ITAアクション履歴登録
        logger.logic_log('LOSI01104', str(rhdm_res_act.execution_order), self.trace_id)
        ret = self.ita_action_history_insert(
            self.aryActionParameter,
            symphony_instance_id,
            operation_id,
            symphony_url,
            rhdm_res_act.execution_order
        )

        # Symphonyに失敗した場合は異常終了する。
        if ActionStatus != PROCESSED:
            logger.system_log('LOSE01110', ActionStatus, self.trace_id)
            ActionDriverCommonModules.SaveActionLog(self.response_id, rhdm_res_act.execution_order, self.trace_id, 'MOSJA01040')
            return ACTION_EXEC_ERROR, DetailStatus

        logger.logic_log('LOSI00002', 'return: PROCESSED')
        return ACTION_HISTORY_STATUS.EXASTRO_REQUEST, DetailStatus