2

Azure (ARM) で構成されたロード バランサーがあり、prod、stage の 2 つのバックエンド プールがあります。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>]

その配列には項目が 1 つしかないため、その項目を変数に設定します。

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 以外でそのプールを変更する方法がわかりません。

4

2 に答える 2

2

このビデオと、REST および Python を介してプール メンバーシップを変更する方法を示す GitHub リポジトリをご覧ください。

最後に、更新を介して送信される適切なjsonに到達することです

https://mix.office.com/watch/f4cvoa3cnfoe

/src以下のパスには Python のバージョンがあることに注意してください

https://github.com/cicorias/AzureLoadbalancedPoolUpdate r

アプローチと注文

実際には、ロード バランサではなく、NIC 方向からこれを行います。更新 (PUT) は「NIC」に対するものです。

一般的な順番は
  1. VM とその NIC を取得する
  2. バックエンド プールに対する NIC の関係を取得する
  3. loadBalancerBackendAddressPools空のままにして削除
  4. リソース ID を「loadBalancerBackendAddressPools」配列に入れて追加します

PUT による REST リクエストの作成は、こちらです。

def build_request(vm_object, nic_object, load_balancer=None):
"""
:param vm_object : azure.mgmt.compute.VirtualMachine
:param nic_object : azure.mgmt.network.networkresourceprovider.NetworkInterface
:param load_balancer : azure.mgmt.network.LoadBalancer
:return: dict
"""
if load_balancer == None:
    backend_pool = []
else:
    backend_pool = [{ 'id' : load_balancer.load_balancer.backend_address_pools[0].id }]

request = {
    'properties': {
        'virtualMachine' : {
            'id' : vm_object.virtual_machine.id
            },
        'ipConfigurations' : [{ #may have to build by hand
            'properties' : {
                'loadBalancerBackendAddressPools' : backend_pool,
                'subnet' : {
                    'id' :  nic_object.ip_configurations[0].subnet.id
                    }
                },
            'name' : nic_object.ip_configurations[0].name,
            'id' : nic_object.ip_configurations[0].id
             }]
        },
    'id' : nic_object.id,
    'name' : nic_object.name,
    'location' : vm_object.virtual_machine.location,
    'type' : 'Microsoft.Network/networkInterfaces'
    }


return request
于 2015-11-28T20:25:32.683 に答える
1

Hugues が github で同じ質問に回答しました: https://github.com/Azure/azure-sdk-for-python/issues/471

他のコミュニティ メンバーから同様の問い合わせを受けた場合に備えて、ここに回答を引用してください。

参照 ID を使用してフェッチできるようにする get() がないため、現在、リソース参照に従うのは不便です。そのため、ID を構成するリソースの名前を解析する必要があります。

この場合、リソース ID を解析して「myresourcegroup」、「app-green04-nic」、および「ipconfig1」という名前を取得する必要があります。これらを使用すると、 network_client.network_interfaces.get('myresourcegroup, 'app-green04-nic') で NIC にアクセスできるようになります。

LoadBalancerOperations を見ると、get() を実行し、ResourceId オブジェクトを追加/変更/削除して load_balancer.backend_address_pools[0].backend_ip_configurations の内容を変更し、変更された LoadBalancer で create_or_update() を呼び出すことができるようです。物体。

リソース ID を取得して ResourceId を作成するのは簡単です。自分で文字列を作成する必要はありません。通常は get() メソッドを呼び出すだけで、Azure が ID を入力して返します。たとえば、NIC 構成のリソース ID を取得するには、次のようにします。

result = network_client.network_interfaces.get('myresourcegroup', 'app-green04-nic')
result.network_interface.ip_configurations[0].name
#ipconfig1
result.network_interface.ip_configurations[0].id
#/subscriptions/xxx-xxx-xxx/resourceGroups/myresourcegroup/providers/Microsoft.Network/networkInterfaces/app-green04-nic/ipConfigurations/ipconfig1

これらのコレクションでは名前でインデックスを作成できないため、探しているコレクションを見つけるために反復する必要があります。

ご不明な点がございましたら、お気軽にお問い合わせください。

于 2015-09-14T21:31:04.103 に答える