通过Python API在Azure附加数据磁盘
有没有人知道怎么通过Python的ARM 1.0.2版本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'},
相关文章:
- 暂无相关问题
1 个回答
0
我们可以利用Python的SDK来管理服务,为虚拟机添加数据磁盘。具体的操作可以参考add_data_disk()这个链接上的内容。
在Python项目中实现这个功能之前,我们需要先创建一个证书。首先,下载你的发布设置,然后使用这个文件中的名为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)