我在 Azure (ARM) 中配置了负载均衡器,并且有 2 个后端池:prod、stage。通过 GUI,当我想将登台服务器提升到生产环境时,我将其从舞台池中删除并将其放入产品池中。我对这一切是如何工作的感到非常困惑,因为当我配置堆栈时,我首先配置负载平衡器,当我配置 VM 将附加到的 NIC 时,我将该 NIC 放置在我想要的后端池中。但是,当我想将 VM 移动到另一个池时,我不再在 NIC 级别执行此操作。我必须在负载均衡器上这样做。
使用 Python SDK,如果我查询 LB,我可以看到后端池中的 NIC,但似乎没有办法修改它。我还可以查询 NIC 并查看它与哪个后端池相关联,但同样无法修改(据我所知)。这是我到目前为止所拥有的:
# Create the client
network_client = azure.mgmt.network.NetworkResourceProviderClient(creds)
# Get all LBs
lbs = network_client.load_balancers
# select LB in question
lb = lbs.get(group,'cc-lb01')
# get all pools
pools = lb.load_balancer.backend_address_pools
# set variables for pools
prod = pools[0]
stage = pools[1]
print(dir(stage)) 的输出是:
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_backend_ip_configurations', '_etag', '_id', '_load_balancing_rules', '_name', '_provisioning_state', 'backend_ip_configurations', 'etag', 'id', 'load_balancing_rules', 'name', 'provisioning_state']
所以当我看到'backend_ip_configurations'时,我以为我在做某事。当在那里查看我的选项时(通过输入):
print(stage.backend_ip_configurations)
它返回一个对象数组:
[<azure.mgmt.network.networkresourceprovider.ResourceId object at 0x03C9C090>]
该数组中只有一项,因此我将该项设置为一个变量:
beip = stage.backend_ip_configurations[0].id
当我看到“beip”有什么选择时,这就是我的死胡同。
/subscriptions/xxx-xxx-xxx/resourceGroups/myresourcegroup/providers/Microsoft.Network/networkInterfaces/app-green04-nic/ipConfigurations/ipconfig1
print(dir(beip)) 的输出是:
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
我无法弄清楚如何查看后端池中的 NIC 并修改该池,而不是通过 GUI。