2015-11-17 82 views
0

連接數據的磁盤沒有人有通過python的ARM版數據的磁盤附加到VM 1.0.2 API的解決方案?天青通過Python API

我已經嘗試添加元數據到磁盤,但它似乎沒有工作。

'disk5.vhd': { 'metadata': { 'x-ms-meta-microsoftazurecompute_diskid': '9bab45ae-b69c-47d6-952e-9b4320884f01', 
           'x-ms-meta-microsoftazurecompute_diskname': 'disk5', 
           'x-ms-meta-microsoftazurecompute_disksizeingb': '22', 
           'x-ms-meta-microsoftazurecompute_disktype': 'DataDisk', 
           'x-ms-meta-microsoftazurecompute_resourcegroupname': 'pythonvm10085', 
           'x-ms-meta-microsoftazurecompute_vmname': 'pythonvm10085'}, 

回答

0

我們可以利用的Python SDK服務管理的數據磁盤添加到虛擬機。請參閱GitHub repro上的add_data_disk()

在Python項目中實現這一點,我們需要先創建一個證書。要做到這一點,下載您publish settings,然後用這個代號爲ManagementCertificate在此文件來創建.pem文件。

這裏是代碼片段:

from azure.servicemanagement import get_certificate_from_publish_settings 
from azure.servicemanagement import ServiceManagementService 

cert_file = 'myCert.pem' 
subscription_id = get_certificate_from_publish_settings(
    publish_settings_path=’publish file path’, 
    path_to_write_certificate='myCert.pem', 
) 
#print subscription_id 
sms = ServiceManagementService(subscription_id, cert_file) 

service_name = 'myservicename' #cloud service name contained the VM 
deployment_name = 'myservicename' 
role_name = 'myservicename' 
lun = 0 

result = sms.add_data_disk(service_name,deployment_name,role_name,lun,media_link='http://{example}.blob.core.windows.net/vhds/testdisk.vhd',logical_disk_size_in_gb=1) 
sms.wait_for_operation_status(result.request_id, timeout=600) 
+0

謝謝你,但servicemanagement只支持蔚藍的經典門戶。我正在尋找支持新的Azure預覽門戶的Resource menagement python SDK。 –

+0

要利用ARM,您可以參考http://azure-sdk-for-python.readthedocs.org/en/latest/resourcemanagementcomputenetwork.html#create-virtual-machine,那裏有一個函數'compute_client.virtual_machines.create_or_update ()'在這個例子中 –

+1

你可以在http://azure-sdk-for-python.readthedocs.org/en/latest/ref/azure.mgmt.compute.computemanagement.html?highlight=datadisk找到datadisk類參數#azure.mgmt.compute.computemanagement.DataDisk –