#Author by Andy
#_*_ coding:utf-8 _*_
import sys
import time
Path="E:\my python study\\files\haproxy.txt"
Path_new="E:\my python study\\files\haproxy_new.txt"
examples='''\033[31;1m内容格式范例 :
arg={
'backend': 'www.oldgirl.org',
'record':{
'server': '100.1.7.10',
'weight': 20,
'maxconn': 30
}
}
\033[;0m'''
#定义主函数
def main_func():
print("Welcome to use this program!")
choice=input("See what you can do:\n"
"Add\n"
"Delete\n"
"Q or q to end program.\n"
"Search\n"
":")
return choice
#定义字符串转字典函数
def str_to_dict():
print("请输入要添加的内容:")
stop_input = ''
user_input = ''
for line in iter(input,''):
user_input = user_input+line + '\n' #input遇到空行才停止,默认是遇到回车停止
dict = eval(user_input.strip("arg = "))
return dict
#定义追加函数
def add(info):
backend_value=info['backend']
record_value=info['record']
f=open(Path,'a+',encoding='utf-8')
f.write('\nbackend %s \n' %backend_value)
f.write('\t\tserver %s weight %s maxconn %s\n'
%(record_value['server'],record_value['weight'],record_value['maxconn']))
time.sleep(2)
f.closed
# add(str_to_dict())
#定义删除函数
def dele(info):
backend_value=info['backend']
record_value=info['record']
del_record='\t\tserver %s weight %s maxconn %s\n' \
%(record_value['server'],record_value['weight'],record_value['maxconn'])
f = open(Path,'r+',encoding='utf-8')
f_new=open(Path_new,'w',encoding='utf-8')
for line in f:
if backend_value in line:
line=line.replace(line,'')
elif del_record == line:
line=line.replace(del_record,'')
f_new.write(line)
time.sleep(2)
f.closed
f_new.closed
#dele(str_to_dict()) def find_keywords(keywords):
f=open(Path,'r+',encoding='utf-8')
while True:
line = f.readline()
if keywords in line:
f.seek(f.tell()+1)
print(f.readline().strip())
target=f.readline().strip()
time.sleep(2)
f.closed
return target
while True:
choice=main_func()
if choice=='Add':
print(examples)
add(str_to_dict())
elif choice=='Search':
keywords=input("请输入关键字:")
find_keywords(keywords)
elif choice=='Delete':
print(examples)
dele(str_to_dict())
elif choice=='q'or choice =='Q':
print("Bye-bye!")
exit() 文件格式:
global
log 127.0.0.1 local2
daemon
maxconn 256
log 127.0.0.1 local2 info
defaults
log global
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
option dontlognull listen stats :8888
stats enable
stats uri /admin
stats auth admin:1234 frontend oldboy.org
bind 0.0.0.0:80
option httplog
option httpclose
option forwardfor
log global
acl www hdr_reg(host) -i www.oldboy1.org
use_backend www.oldboy1.org if www backend www.oldboy.org
server 100.1.7.9 100.1.7.9 weight 20 maxconn 3000 需求:
1、查
输入:www.oldboy.org
获取当前backend下的所有记录 2、新建
输入:
arg = {
'bakend': 'www.oldboy.org',
'record':{
'server': '100.1.7.9',
'weight': 20,
'maxconn': 30
}
} 3、删除
输入:
arg = {
'bakend': 'www.oldboy.org',
'record':{
'server': '100.1.7.9',
'weight': 20,
'maxconn': 30
}
}

最新文章

  1. oracle SQLPLUS 常用set设置
  2. 开发 web 桌面类程序几个必须关注的细节
  3. CentOS7之VMware安装
  4. 对应键盘的ASCII码(备忘)
  5. 误删system04.dbf 报:ORA-01157 ORA-01110
  6. json化表单数据
  7. ios 阻止GDB依附
  8. ActionBarActivity & FragmentActivity
  9. tp框架实现ajax注册验证
  10. Luogu 1090 合并果子(贪心,优先队列,STL运用)
  11. JavaScript面向对象(OOP)
  12. oracle 12 c 创建表空间,用户名,及表
  13. .net DBHelper
  14. linux svnserver的安装使用备用
  15. BZOJ4127Abs——树链剖分+线段树
  16. 学习笔记TF013:卷积、跨度、边界填充、卷积核
  17. hasura graphql-engine &&patroni docker-compose 环境运行
  18. [整理]C语言中字符常量与ASCII码
  19. 发布spring jar包, 报错
  20. 安装nvidia driver

热门文章

  1. Windows平板优化设置
  2. HttpGet 请求(带参数)
  3. activiti-5.15备份记录
  4. 压力测试工具JMeter入门教程
  5. ASP.NET 画图与图像处理-生成高质量缩略图
  6. Hadoop深入浅出实战经典–第02讲
  7. Arduino学习经验(一)之解决舵机库和pwm输出冲突
  8. sql 语句纵表变横表
  9. 《在纹线方向上进行平滑滤波,在纹线的垂直方向上进行锐化滤波》 --Gabor增强的具体实践
  10. [转]让窗体不显示在Alt+Tab中