解析keepalived.conf,翻译为json
解析 keepalived.conf 格式并将其返回为 json 的(首选 python)最佳方法是什么?我想自动添加/删除虚拟和真实服务器。
我的第一个猜测是 pyparsing,遵循 stackoverflow 的一些答案,但我无法让它工作!
keepalived.conf 的格式如下:
virtual_server 192.168.1.1 80
{
lb_algo wrr
lb_kind DR
protocol TCP
ha_suspend
delay_loop 10
# server-01
real_server 192.168.1.100 80
{
weight 100
inhibit_on_failure
TCP_CHECK
{
connect_port 80
connect_timeout 5
}
}
# server-02
real_server 192.168.1.101 80
{
weight 100
inhibit_on_failure
TCP_CHECK
{
connect_port 80
connect_timeout 5
}
}
}
提前致谢!
What would be the (python preferred) best way to parse the keepalived.conf format and return it to json ? I'd like to automate the adding/removing of virtual and real servers.
My first guess is pyparsing, following a few answers from stackoverflow, but I can't get it to work !
The format of keepalived.conf is like this :
virtual_server 192.168.1.1 80
{
lb_algo wrr
lb_kind DR
protocol TCP
ha_suspend
delay_loop 10
# server-01
real_server 192.168.1.100 80
{
weight 100
inhibit_on_failure
TCP_CHECK
{
connect_port 80
connect_timeout 5
}
}
# server-02
real_server 192.168.1.101 80
{
weight 100
inhibit_on_failure
TCP_CHECK
{
connect_port 80
connect_timeout 5
}
}
}
Thanks in advance !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是解析此数据的粗略第一步:
打印以下内容:
Here is a rough first pass at parsing this data:
Prints the following: