def _copy_lib():
     """
     Copy lib file to project path
     """
     from_path = os.path.realpath(os.path.join(EXTRACT_DIR, Constant.AI_LIB_PATH))
     to_path = PYTHON_PATH
     CommonTools.copy_file_to_dest_path(from_path, to_path)
     g.logger.info('Successfully to copy lib files.')
 def _copy_manager_files(self):
     """
     Copy manager files to manager dir
     """
     from_path = os.path.join(os.path.dirname(os.path.dirname(
         os.path.realpath(__file__))), Constant.AI_MANAGER_PATH)
     to_path = self.ai_manager_path
     CommonTools.copy_file_to_dest_path(from_path, to_path)
     g.logger.info('Successfully to copy files to manager path.')
Exemple #3
0
 def restore_db_file(status, db_cabin, back_up_path):
     """
     Restore db file.
     """
     if status:
         CommonTools.mkdir_with_mode(os.path.dirname(db_cabin),
                                     Constant.AUTH_COMMON_DIR_STR)
         CommonTools.copy_file_to_dest_path(back_up_path, db_cabin)
     else:
         g.logger.info('No need Restore db file.')
Exemple #4
0
    def prepare_ca_certificates(self):
        """
        Generate server ca certificates.
        """
        ca_root_file_path, ca_root_key_path, server_cert_path, server_key_path, agent_cert_path, \
            agent_key_path = self.read_ca_cert_path()
        self.ca_info = self.param_dict.pop(Constant.CA_INFO)
        if not self.ca_info:
            raise Exception(Errors.PARAMETER['gauss_0201'] %
                            'ca root cert information')
        get_ca_root_cert_path = self.ca_info.get(Constant.CA_CERT_PATH)
        get_ca_root_key_path = self.ca_info.get(Constant.CA_KEY_PATH)
        get_ca_root_password = self.ca_info.get(Constant.CA_PASSWORD)
        if not all([
                get_ca_root_cert_path, get_ca_root_key_path,
                get_ca_root_password
        ]):
            raise Exception(Errors.PARAMETER['gauss_0201'] %
                            'items info of ca root cert')

        # copy ca root cert and key files to path of configured
        g.logger.info('Start deploy ca root files.')
        CommonTools.remove_files([ca_root_file_path, ca_root_key_path])
        CommonTools.mkdir_with_mode(os.path.dirname(ca_root_file_path),
                                    Constant.AUTH_COMMON_DIR_STR)
        CommonTools.copy_file_to_dest_path(get_ca_root_cert_path,
                                           ca_root_file_path)
        CommonTools.mkdir_with_mode(os.path.dirname(ca_root_key_path),
                                    Constant.AUTH_COMMON_DIR_STR)
        CommonTools.copy_file_to_dest_path(get_ca_root_key_path,
                                           ca_root_key_path)

        # get ssl password
        ssl_password = CertGenerator.get_rand_str()
        ca_config_path = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), Constant.CA_CONFIG)
        server_ip = CommonTools.get_local_ip(ignore=True)
        g.logger.info('Get server ip:[%s].' % server_ip)

        # create server cert
        CertGenerator.create_ca_certificate_with_script(get_ca_root_password,
                                                        ssl_password,
                                                        ca_root_file_path,
                                                        ca_root_key_path,
                                                        ca_config_path,
                                                        server_cert_path,
                                                        server_key_path,
                                                        server_ip,
                                                        crt_type='server')
        g.logger.info('Successfully generate server ca certificate.')
        return get_ca_root_password, ssl_password, ca_root_file_path, ca_root_key_path, \
            ca_config_path, agent_cert_path, agent_key_path
Exemple #5
0
 def deploy_module_files(self):
     """
     Copy files to module path.
     """
     from_path = os.path.join(
         os.path.dirname(
             os.path.dirname(
                 os.path.dirname(os.path.dirname(
                     os.path.realpath(__file__))))), self.module_name)
     to_path = os.path.realpath(
         os.path.join(self.install_path, self.module_name))
     CommonTools.copy_file_to_dest_path(from_path, to_path)
     g.logger.info('Successfully to copy files to package path.')
Exemple #6
0
 def deploy_agent_certs(self):
     """
     Copy file from temp dir to config path.
     """
     file_list = self.read_ca_cert_path(agent_only=True)
     file_list.append(os.path.join(self.module_path, Constant.PWF_PATH))
     temp_cert_list = os.listdir(TMP_CA_FILE)
     for dest_path in file_list:
         CommonTools.mkdir_with_mode(os.path.dirname(dest_path),
                                     Constant.AUTH_COMMON_DIR_STR)
     CommonTools.remove_files(file_list)
     g.logger.info('Successfully prepare the path:%s' % str(file_list))
     for file_name in temp_cert_list:
         for dest_file in file_list:
             if file_name in dest_file:
                 from_path = os.path.join(TMP_CA_FILE, file_name)
                 CommonTools.copy_file_to_dest_path(from_path, dest_file)
     CommonTools.clean_dir(TMP_CA_FILE)
Exemple #7
0
 def backup_db_file(self):
     """
     Backup data file.
     """
     ad_config_path = os.path.join(self.install_path,
                                   Constant.ANOMALY_DETECTION_CONFIG_PATH)
     if not os.path.isfile(ad_config_path):
         g.logger.info('Config file not exist, can not backup db file')
         return False, None, None
     db_cabin = CommonTools.read_info_from_config_file(
         ad_config_path, Constant.AD_CONF_SECTION_DATABASE,
         Constant.AD_CONF_DATABASE_PATH, self.module_path)
     if os.path.isdir(db_cabin):
         g.logger.info('Start backup db file.')
         back_up_path = os.path.join(EXTRACT_DIR,
                                     os.path.basename(db_cabin))
         CommonTools.copy_file_to_dest_path(db_cabin, back_up_path)
         return True, db_cabin, back_up_path
     else:
         g.logger.info('No need backup db file.')
         return False, None, None