Here is the Error I am getting ############################# Failed Traceback (most recent call last): File "C:\Temp\kukzwo13.tgf\9bd12580-5780-4109-abab-66e88fb4df87", line 59, in if not item.tags['ExpiryDate']:KeyError: 'ExpiryDate'
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
import datetime
from datetime import time
# Tenant ID for your Azure Subscription
TENANT_ID = 'tenant id '
# Your Service Principal App ID
CLIENT = 'client id'
# Your Service Principal Password
KEY = 'scret key'
subscription_id = 'subscrptionId'
credentials = ServicePrincipalCredentials(client_id=CLIENT, secret=KEY, tenant=TENANT_ID)
client = ResourceManagementClient(credentials, subscription_id)
groups = client.resource_groups.list()
null_variable = None
for item in groups:
if item.tags != null_variable:
if 'ExpiryDate' in item.tags:
expiryDate = datetime.datetime.strptime(item.tags["ExpiryDate"],"%m/%d/%Y")
timediff = expiryDate < datetime.datetime.today()
if timediff:
print(item.tags["ExpiryDate"])
print(item.name)
client.resource_groups.delete(item.name)
我将从示例页开始: https://github.com/Azure-Samples/resource-manager-python-resources-and-groups
以及支持文档 https://docs.microsoft.com/en-us/python/azure/?view=azure-python
在python代码中,我们需要检查字典的键是否有效。我用python代码做了一个用标签删除资源组的演示。在
相关问题 更多 >
编程相关推荐