2016-04-13 12 views
1

Pythonを使用してAzure 2.0.0rc2でタグを作成しようとしています。create tags Python Azure SDKの使い方は?

def __update_tags(self): 
    username = '[email protected]' 
    password = '[email protected]' 
    subscription_id = '478-ytehn-47ds5-784aa-4758a' 
    credentials = UserPassCredentials(username=username, password=password) 
    resource_client = ResourceManagementClient(credentials=credentials) 
    tag_operations = TagOperations(client=resource_client) 
    tag_operations.create_or_update_value(tag_name='key_1', tag_value='val_1') 

私のようなエラーを取得しています。このコードを実行するには:

if self.client.credentials.subscription_id is not None: 
AttributeError: 'UserPassCredentials' object has no attribute 'subscription_id' 

誰もがこの問題を解決するためのアイデアを持っているの 私が使用したコードを以下に示します。

答えて

0

コードでは、subscription_idが指定されていますが使用されていません。 resource_clientを作成するときは、subscription_idが必要です。詳細については、

resource_client = ResourceManagementClient(
ResourceManagementClientConfiguration(
    credentials, 
    subscription_id 
) 

チェックhere:以下のコードで "resource_client = ResourceManagementClient(資格情報=資格情報)" を交換してください。

更新: 確認インポートResourceManagementClientConfiguration enter image description here

+0

私はこの方法を試してみましたが、azure.mgmt.resource.resourcesから '紺碧2.0.0rc2にはResourceManagementClientConfiguration をインポート'は使用できません。一度確認してください。 –

+0

@ramkumarどういう意味ですか?私は私の側から** azure.mgmt.resource.resources import ResourceManagementClientConfiguration **が確実に動作することを確認できます。私の返信で更新をチェックしてください。 – forester123

0

書類(Resource ManagementResource Management Authentication)によると、forester123 @として以下のようなコードをまとめる、と述べました。

from azure.common.credentials import UserPassCredentials 
from azure.mgmt.resource.resources import ResourceManagementClient, ResourceManagementClientConfiguration 

username = '[email protected]' 
password = '[email protected]' 
subscription_id = '478-ytehn-47ds5-784aa-4758a' 

credentials = UserPassCredentials(username, password) 
resource_client = ResourceManagementClient(
    ResourceManagementClientConfiguration(
     credentials, 
     subscription_id 
    ) 
) 
関連する問題