Cloud Native应用交付

  • 首页
  • 关于本站
  • 个人介绍
  • Downloads
  • Repo
    • Github
    • Container
  • F5
    • F5 Python SDK
    • F5-container
    • F5-LBaaS
  • 社交
    • 联系我
    • 微信/微博
    • 公众号
    • 打赏赞助
行至水穷处 坐看云起时
Cloud Native Application Services: cnadn.net
  1. 首页
  2. F5-Tech tips
  3. 正文

基于业务模板自动化配置F5

2016年08月23日 7710点热度 0人点赞 0条评论

这是很早前写的一个样例,基于业务模板,系统自动化创建业务配置

业务输入模板(可以通过任何形式产生,例如一个自服务的portal website):

createvs.txt  createpool.txt createmonitor.txt

中间程序F5_Deploy.py, 中间输出 tmsh.txt (作为ssh.py的输入)

(如果系统支持iControlRest,可以直接利用Python执行REST)

自动执行ssh.py

 

图标

基于业务模板自动化配置F5业务

1 文件 3.91 KB
下载

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
###Tested on v11.6###
#only support tcp,http,icmp monitor now
## Created by WWW.MYF5.NET @2015
def createmonitor():
   try:
    f=file('createmonitor.txt')
    lines=f.readlines()
    print lines
    l=[]
    for line in lines:
        print line
        #get value of each line
        linedata=line.split(",")[1]
        #remove"\n"
        i=linedata.split("\n")[0]
        print i
        l.append(i)
    print l
    if l[6]=="enabled":
        if l[0]=="icmp" and l[7]!="" and l[7]!="*":
            #if it is icmp monitor, only need ip and it has an valid ip
            tr="transparent enabled destination %s"%l[7]
        else:
            #for other monitors, ip and port must be there
            if l[7]=="" or l[7]=="*" or l[8]=="" or l[8]=="*":
                print "Error: With transparent enabled, must have ip and port"
                return
            else:
                tr="transparent enabled destination %s:%s"%(l[7],l[8])            
    else:
        #not transparent, could set alias, f5 only support *:* or *:port or ip:port format
        if l[0]=="icmp":
            #icmp monitor,cant have port setting
            if l[7]=="" or l[7]=="*":
                #default setting
                tr=""
            else:
                tr="destination %s"%l[7]
        else:
            #not icmp,support  *:* or *:port or ip:port
            if (l[7]=="" or l[7]=="*") and (l[8]=="" or l[8]=="*"):
                #default setting
                tr=""
            elif l[7]!="" and l[7]!="*" and (l[8]=="" or l[8]=="*"):
                #it is ip:*, dont support
                print "Error: Dont support ip:* alias settting"
                return
            else:
                if l[7]=="":
                    l[7]="*"
                tr="destination %s:%s"%(l[7],l[8])
        
    if l[9]=="enabled":
        res="manual-resume enabled"
    else:
        res=""
    if l[4]!="" and l[5]!="" and l[0]!="icmp":
        sr="send \'%s\' recv \'%s\'"%(l[4],l[5])
    else:
        sr=""
    tmsh="tmsh create ltm monitor %s %s interval %s timeout %s %s %s %s\n"%(l[0],l[1],l[2],l[3],sr,tr,res)
    print tmsh
    f.close()
    out=file('tmsh.txt','a')
    out.write(tmsh)
    out.close
   except:
    print "Cant open the file,or something wrong in during creating pool. Please turn on debug for detail."
 
 
    
def createpool():
   try:
    tmsh=""
    monitor=""
    member=""
    mr=""
    noratio=1
    sda=""
    f=file('createpool.txt')
    lines=f.readlines()
    print lines
    l=[]
    for line in lines:
        print line
        #get value of each line
        linedata=line.split(",")[1]
        #remove "\n"
        i=linedata.split("\n")[0]
        print i
        #create string list for pool
        l.append(i)
    print l
    if l[1]=="":
        print "No monitor, will use tcp as default"
        monitor="monitor tcp"
        print l
    else:
        #handle monitor if it is more than 1
        if l[2]=="":
            #no min of monitor setting
            monitorstring=l[1].replace("|"," and ")
            monitor="monitor %s"%monitorstring
        else:
            #consider min of monitor
            monitorstring=l[1].replace("|"," ")
            monitor="monitor min %s of { %s }"%(l[2],monitorstring)
            print monitor
        print l
    if l[3]=="":
        sda=""
    else:
        sda="service-down-action %s"%l[3]
    if l[4]=="ratio-member" or l[4]=="ratio-least-connections-member":
        noratio=0
    if l[4]=="":
        l[4]="round-robin"
    if l[5]=="":
        #no priority group setting
        p=""
    else:
        #has priority, need set min-active-members in tmsh
        p="min-active-members %s"%l[5]
    if l[6]=="":
        print "No members!"
        return
    else:
        #handle members if it is more than 1
        member=l[6].split("|")
        for m in member:
            m1=m.split(":")
            if m1[2]=="" or noratio==1:
                m1[2]="1"
            if m1[3]=="":
                m1[3]="0"
            if p:
                mr=mr + " %s:%s { ratio %s priority-group %s} "%(m1[0],m1[1],m1[2],m1[3])
            else:
                mr=mr + " %s:%s { ratio %s } "%(m1[0],m1[1],m1[2])
        print mr
    tmsh="tmsh create ltm pool %s members add {%s} %s load-balancing-mode %s %s %s\n"%(l[0],mr,monitor,l[4],sda,p)
    f.close()
    out=file('tmsh.txt','a')
    out.write(tmsh)
    out.close
    print tmsh
   except:
    print "Cant open the file,or something wrong in during creating pool. Please turn on debug for detail."
  
 
def createvs():
    try:
     f=file('createvs.txt')
     lines = f.readlines()
     print lines
     vlan=""
     snat=""
     l=[]
     tmsh=''
     for line in lines:
         print line
         #get value of each line
         linedata=line.split(",")[1]
         #remove "\n"
         i= linedata.split("\n")[0]
         print i
         #create string list for vs
         l.append(i)
     print l
     if l[3]=="":
         #vs_type is blank, so it will be performance l4 or standard vs
         if l[13]!="":
             #vlan enabled_on has setting
             vlan="vlans add { %s } vlans-enabled"%l[13]
         if l[14]!="":
             #vlan disabled_on has setting
             vlan="vlans add { %s } vlans-disabled"%l[14]
         if l[15]!="":
             #it is snat automap
             snat="source-address-translation { type automap } "
         if l[16]!="":
             #it is snat pool
             snat="source-address-translation { type snat pool %s }"%l[16]
         tmsh="tmsh create ltm virtual %s destination %s:%s ip-protocol %s profiles add { %s %s %s %s %s %s %s %s} %s %s mirror %s persist replace-all-with { %s %s } pool %s rules { %s %s} %s\n"\
         %(l[0],l[1],l[2],l[4],l[5],l[6],l[7],l[8],l[9],l[10],l[11],l[12],vlan,snat,l[17],l[18],l[19],l[20],l[21],l[22],l[23])
     elif l[3]=="ipforwarding":
         print "it is ip forwarding vs"
         return
     else:
         print "Not support vs type"
         return
     print tmsh
     f.close()
     out=file('tmsh.txt','a')
     out.write(tmsh)
     out.close()
    except:
     print "Cant open the file,or something wrong in during creating vs. Please turn on debug for detail."
    
createmonitor()
createpool()
createvs()

 

相关文章

  • 密码保护:F5OS docker-compose.yml
  • 密码保护:F5OS 底层容器、网络及k8s状态
  • F5 BIG-IP链接Istio 增强入口服务能力
  • Prometheus metrics of F5 CIS/CC
  • How to build Nginx Plus as k8s Ingress controller and run with F5 CIS together
本作品采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可
标签: 暂无
最后更新:2016年08月29日

纳米

linjing.io

打赏 点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理。

页面AI聊天助手

纳米

linjing.io

☁️迈向Cloud Native ADC ☁️

认证获得:
TOGAF: ID 152743
Kubernetes: CKA #664
Microsoft: MCSE MCDBA
Cisco: CCNP
Juniper: JNCIS
F5:
F5 Certified Solution Expert, Security
F5 Certified Technology Specialist, LTM/GTM/APM/ASM
F5 Certified BIG-IP Administrator
  • 点击查看本博技术要素列表
  • 归档
    分类
    • AI
    • Automation
    • Avi Networks
    • Cisco ACI
    • CISCO资源
    • F5 with ELK
    • F5-Tech tips
    • F5技术
    • Juniper
    • Linux
    • NGINX
    • SDN
    • ServiceMesh
    • WEB编程
    • WINDOWS相关
    • 业界文章
    • 交换机技术
    • 化云为雨/Openstack
    • 协议原理
    • 容器/k8s
    • 我的工作
    • 我的生活
    • 网站技术
    • 路由器技术
    • 项目案例
    标签聚合
    istio api gtm flannel bigip F5 neutron docker openstack k8s envoy irule DNS network nginx
    最近评论
    汤姆 发布于 8 个月前(09月10日) 嗨,楼主,里面的json怎么下载啊,怎么收费啊?
    汤姆 发布于 8 个月前(09月09日) 大佬,kib的页面可以分享下吗?谢谢
    zhangsha 发布于 1 年前(05月12日) 资料发给我下,谢谢纳米同志!!!!lyx895@qq.com
    李成才 发布于 1 年前(01月02日) 麻烦了,谢谢大佬
    纳米 发布于 1 年前(01月02日) 你好。是的,因为以前下载系统插件在一次升级后将所有的下载生成信息全弄丢了。所以不少文件无法下载。DN...
    浏览次数
    • Downloads - 183,772 views
    • 联系我 - 118,966 views
    • 迄今为止最全最深入的BIGIP-DNS/GTM原理及培训资料 - 116,511 views
    • Github - 103,661 views
    • F5常见log日志解释 - 79,774 views
    • 从传统ADC迈向CLOUD NATIVE ADC - 下载 - 74,625 views
    • Sniffer Pro 4 70 530抓包软件 中文版+视频教程 - 74,320 views
    • 迄今为止最全最深入的BIGIP-DNS/GTM原理及培训资料 - 67,770 views
    • 关于本站 - 60,911 views
    • 这篇文档您是否感兴趣 - 55,495 views
    链接表
    • F5SE创新
    • Jimmy Song‘s Blog
    • SDNlab
    • Service Mesh社区
    • 三斗室
    • 个人profile
    • 云原生社区

    COPYRIGHT © 2023 Cloud Native 应用交付. ALL RIGHTS RESERVED.

    Theme Kratos Made By Seaton Jiang

    京ICP备14048088号-1

    京公网安备 11010502041506号