删除寿命超过x天的Azure资源组中的所有资源 [英] Deleting all resources in an Azure Resource Group with age more than x days

查看:53
本文介绍了删除寿命超过x天的Azure资源组中的所有资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在资源组(python api)中的资源上扩展" creationTime,因此我可以找到它的使用期限,如果> max_age_days,我将删除该资源组中的资源.

I attempted to "expand" creationTime on a resource in a resource group (python api) so I could find it's age and if > max_age_days I would have deleted the resource within the resource group.

但是creationTime似乎在资源上不可用.

But creationTime doesn't seem to be available on resources.

还有另一种方法可以根据资源的使用期限来删除资源组中的资源吗?

Is there another way to delete resources within a resource group based on their age ?

创建日期和创建者可能是资源管理的最基本要求.

Creation Date and Created By are probably the most basic requirements of resource management.

推荐答案

Azure在可通过将$ expand参数添加到URL进行查询的所有资源上存储了createdTime和changedTime属性.

Azure stores a createdTime and changedTime property on all resources that you can query by adding the $expand parameter to the URL.

expand参数未在Resource Groups API文档中记录,但在List Resources API文档中(

The expand parameter isn't documented in the Resource Groups API docs, but it is documented in the List Resources API docs (https://docs.microsoft.com/en-us/rest/api/resources/resources/list) and it works the same way.

我不知道如何立即使用Python API添加此参数,但这是REST API本身的示例(使用

I don't know offhand how to add this parameter using the Python API, but here is an example of the REST API itself (using the Try It button from the docs at https://docs.microsoft.com/en-us/rest/api/resources/resourcegroups/list#code-try-0).

GET https://management.azure.com/subscriptions/1237f4d2-3dce-4b96-ad95-677f764e7123/resourcegroups?api-version=2019-08-01&%24expand=createdTime

{
  "value": [
    {
      "id": "/subscriptions/1237f4d2-3dce-4b96-ad95-677f764e7123/resourceGroups/test2rg-3-backup",
      "name": "test2rg-3-backup",
      "type": "Microsoft.Resources/resourceGroups",
      "location": "eastus",
      "createdTime": "2018-11-12T18:08:38.667582Z",
      "properties": {
        "provisioningState": "Succeeded"
      }
    },
    {
      "id": "/subscriptions/1237f4d2-3dce-4b96-ad95-677f764e7123/resourceGroups/proddeploy",
      "name": "proddeploy",
      "type": "Microsoft.Resources/resourceGroups",
      "location": "eastus",
      "createdTime": "2019-01-10T21:28:48.8057057Z",
      "tags": {
        "a": "b"
      },
      "properties": {
        "provisioningState": "Succeeded"
      }
    },
...

这篇关于删除寿命超过x天的Azure资源组中的所有资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆