1. Environment dependency
To operate f5, we need to download the dependency package of f5-sdk.
f5-sdk==3.0.21
urllib3==1.25.7
# 安装命令:
pip install f5-sdk==3.0.21 urllib3==1.25.7
2. Requirements research
After requirements confirmation, documentation and client operation investigations, if persist is set to cookie, HTTP Profile needs to select a value, such as /Common/http, but the type of vs is standard, which is realized in disguise after document mining For the choice of type, unfortunately, only Standard and Performance (Layer 4) can be selected.
Here, some fields are added when creating VS, type, sourceAddressTranslation, persist, and profiles.
def create_vs(self,
vs_name,
vs_type,
vs_use_pool,
destination_ip,
destination_port,
sat_type,
sat_pool,
persist=None,
partition=None,
http_profile=None):
"""
:param vs_name:
:param vs_use_pool:
:param destination_ip:
:param destination_port:
:param vs_type:
:param sat_type:
:param sat_pool:
:param persist:
:param partition:
:param http_profile:
:return:
"""
data = {}
if persist:
persist = [{"name": persist}]
else:
persist = []
try:
host = '%s:%s' % (destination_ip, destination_port)
self.mgmt.tm.ltm.virtuals.virtual.create(
name=vs_name,
partition=partition,
destination=host,
pool=vs_use_pool,
ipProtocol=vs_type, # 类型any
sourceAddressTranslation={ # sourceAddressTranslation
"type": sat_type,
"pool": sat_pool
},
persist=persist,
profiles=http_profile
)
data['result'] = True
data['message'] = 'Virtual Server create success'
except Exception as e:
logger.error(u'创建vs抛出error:{0}'.format(e))
data['result'] = False
data['message'] = self.deal_message(e)
return data
What I use here is to achieve the purpose of controlling the type of VS by changing the type of ipProtocol. When ipProtocol is tcp, the type of VS is Standard; when ipProtocol is any, the type of VS is Performance (Layer 4);
The value of sat_type is
SAT_TYPE = [
{
"name": "None",
"value": "none"
},
{
"name": "SNAT",
"value": "snat"
},
{
"name": "Auto Map",
"value": "automap"
}
]