Ai
1 Star 0 Fork 6

weiyp/A-Tune-Collector

forked from src-openEuler/A-Tune-Collector
关闭
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
feature-set-mysql.patch 4.60 KB
一键复制 编辑 原始数据 按行查看 历史
ayin 提交于 2023-08-01 09:43 +08:00 . feature: enable application configs
From 16ef5dc208cd79b9f9d4c7c9d66ce46dc9d013a1 Mon Sep 17 00:00:00 2001
From: gaoruoshu <gaoruoshu@huawei.com>
Date: Tue, 11 Jul 2023 20:53:28 +0800
Subject: [PATCH 07/11] feature: set mysql
---
.../plugin/configurator/__init__.py | 1 +
.../plugin/configurator/mysql/__init__.py | 21 +++++
.../plugin/configurator/mysql/mysql.py | 84 +++++++++++++++++++
3 files changed, 106 insertions(+)
create mode 100644 atune_collector/plugin/configurator/mysql/__init__.py
create mode 100644 atune_collector/plugin/configurator/mysql/mysql.py
diff --git a/atune_collector/plugin/configurator/__init__.py b/atune_collector/plugin/configurator/__init__.py
index 29c674a..677d208 100755
--- a/atune_collector/plugin/configurator/__init__.py
+++ b/atune_collector/plugin/configurator/__init__.py
@@ -31,6 +31,7 @@ __all__ = [
"sysfs",
"systemctl",
"ulimit",
+ "mysql",
"common"]
from . import *
diff --git a/atune_collector/plugin/configurator/mysql/__init__.py b/atune_collector/plugin/configurator/mysql/__init__.py
new file mode 100644
index 0000000..52bb8c3
--- /dev/null
+++ b/atune_collector/plugin/configurator/mysql/__init__.py
@@ -0,0 +1,21 @@
+#!/usr/bin/python3
+# -*- coding: utf-8 -*-
+# Copyright (c) 2023 Huawei Technologies Co., Ltd.
+# A-Tune is licensed under the Mulan PSL v2.
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
+# You may obtain a copy of Mulan PSL v2 at:
+# http://license.coscl.org.cn/MulanPSL2
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+# PURPOSE.
+# See the Mulan PSL v2 for more details.
+# Create: 2023-07-11
+
+"""
+Init file.
+"""
+
+__all__ = ["mysql"]
+
+from . import *
+
diff --git a/atune_collector/plugin/configurator/mysql/mysql.py b/atune_collector/plugin/configurator/mysql/mysql.py
new file mode 100644
index 0000000..cfc533d
--- /dev/null
+++ b/atune_collector/plugin/configurator/mysql/mysql.py
@@ -0,0 +1,84 @@
+#!/usr/bin/python3
+# -*- coding: utf-8 -*-
+# Copyright (c) 2023 Huawei Technologies Co., Ltd.
+# A-Tune is licensed under the Mulan PSL v2.
+# You can use this software according to the terms and conditions of the Mulan PSL v2.
+# You may obtain a copy of Mulan PSL v2 at:
+# http://license.coscl.org.cn/MulanPSL2
+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+# PURPOSE.
+# See the Mulan PSL v2 for more details.
+# Create: 2023-07-11
+
+"""
+The sub class of the Configurator, used to change the /etc/my.cnf config.
+"""
+
+
+import logging
+import os
+from ..common import Configurator
+
+LOGGER = logging.getLogger(__name__)
+
+class Mysql(Configurator):
+ _module = "MYSQL"
+ _submod = "MYSQL"
+
+ def __init__(self, user=None):
+ Configurator.__init__(self, user)
+ self.__cmd = ""
+ self.__file_path = "/etc/my.cnf"
+ self.__mysqld_ind = -1
+ if not os.path.isfile(self.__file_path):
+ with open(self.__file_path, 'w'):
+ pass
+ os.chmod(self.__file_path, 0o644)
+ self.__check_mysqld()
+
+ def __check_mysqld(self):
+ with open(self.__file_path, 'r') as f:
+ lines = f.readlines()
+
+ for line in lines:
+ self.__mysqld_ind = self.__mysqld_ind + 1
+ if line[:-1] == '[mysqld]':
+ self.__mysqld_ind = self.__mysqld_ind + 1
+ return
+
+ lines.insert(self.__mysqld_ind, "[mysqld]\n")
+ self.__mysqld_ind = self.__mysqld_ind + 1
+ with open(self.__file_path, 'w') as f:
+ f.writelines(lines)
+
+ def __check_file_exists(self, lines, start_with):
+ ind = -1
+ for line in lines:
+ ind = ind + 1
+ if line.split('=')[0].rstrip() == start_with:
+ return True, ind
+ return False, ind
+
+ def _set(self, key, value):
+ with open(self.__file_path, 'r') as f:
+ lines = f.readlines()
+
+ key_exist, ind = self.__check_file_exists(lines, key)
+ new_line = key + " = " + value + "\n"
+ if not key_exist:
+ lines.insert(self.__mysqld_ind, new_line)
+ else:
+ lines[ind] = new_line
+
+ with open(self.__file_path, 'w') as f:
+ f.writelines(lines)
+ return 0
+
+ def _get(self, key, _):
+ pass
+
+ @staticmethod
+ def check(config1, config2):
+ return True
+
--
2.27.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/weiyp2016/A-Tune-Collector.git
git@gitee.com:weiyp2016/A-Tune-Collector.git
weiyp2016
A-Tune-Collector
A-Tune-Collector
master

搜索帮助