2 回答
TA贡献1906条经验 获得超3个赞
如果要对虚拟机磁盘创建锁,请参考以下示例
为一个磁盘创建锁
compute_client=get_client_from_cli_profile(ComputeManagementClient)
lock_client = get_client_from_cli_profile(ManagementLockClient)
disk = compute_client.disks.get(resource_group_name='testLinux', disk_name='testLinux_OsDisk_1_41c3d0e2e7b74dcca653b4e058a9332f')
lock_client.management_locks.create_or_update_by_scope(scope=disk.id,lock_name='DeleteLock',parameters={'level' : LockLevel.can_not_delete})
为一个订阅中的所有磁盘创建锁
from azure.common.client_factory import get_client_from_cli_profile
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.resource import ManagementLockClient
from azure.mgmt.resource.locks.models import LockLevel
compute_client=get_client_from_cli_profile(ComputeManagementClient)
lock_client = get_client_from_cli_profile(ManagementLockClient)
disks = compute_client.disks.list()
for disk in disks:
lock_client.management_locks.create_or_update_by_scope(scope=disk.id,lock_name='DeleteLock',parameters={'level' : LockLevel.can_not_delete})
添加回答
举报