我们可以使用 F5-common-python 使用 ManagementRoot 实例创建 Monitor 并与 Pools 关联吗?

Can we create Monitor and associate with Pools using the ManagementRoot instance using F5-common-python?

我们使用 REST 创建监视器(例如 ltm):

[POST] /mgmt/tm/ltm/monitor/$template_name

POST - 正文

{
    "name": template_name,
    "description": some_description,
    "defaultsFrom": "/Common/{template_name}",
    "destination": "*:*",
    "send": some_send_string,
    "recv": some_receive_string
}

并将其与池相关联,

[GET] - /mgmt/tm/ltm/pool/~Common~$pool_name/?$select=monitor

有没有办法使用 Python SDK 实现它 - https://github.com/F5Networks/f5-common-python

-- 法汉

好的,那么我想出来的ManagementRoot代码如下

from f5.bigip import ManagementRoot

# Connect to the BIG-IP
mgmt = ManagementRoot("bigip.example.com", "admin", "somepassword")

# To Create HTTP Monitor
mgmt.tm.ltm.monitor.https.http.create(name="some_monitor_name", partition="Common")

# To Create HTTP Pool
mgmt.tm.ltm.pools.pool.create(name='mypool', partition='Common', monitor='some_monitor_name')

上面创建了监视器和新的池,然后关联。如果您忘记传递监视器来创建,那么您可以使用下面的代码进行更新

my_pool = mgmt.tm.ltm.pools.pool.load(name='mypool', partition='Common')
# Update the monitor 
my_pool.update(monitor='some_monitor_name')

一切准备就绪:)

-法汉