File tree Expand file tree Collapse file tree 4 files changed +22
-4
lines changed Expand file tree Collapse file tree 4 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 7
7
from azure .common .credentials import (ServicePrincipalCredentials , get_azure_cli_credentials )
8
8
from azure .mgmt .resource import ResourceManagementClient
9
9
10
- from .resource_ops import (resource_extractor , check_managed_resource_status )
10
+
11
+ from .resource_ops import (resource_extractor , check_managed_resource_status , check_rg_availability )
11
12
from .util import tabulate_report
12
13
from .trigger_pipeline import trigger_pipelines
13
14
@@ -27,11 +28,15 @@ async def main(mytimer: func.TimerRequest) -> None:
27
28
# Obtain the management object for resources.
28
29
resource_client = ResourceManagementClient (credential , subscription_id )
29
30
31
+ # managed resource groups provided on env
30
32
managed_resource_groups = os .environ ["RESOURCE_GROUPS" ].split ("," )
31
-
33
+
34
+ managed_resource_groups = check_rg_availability (resource_client , managed_resource_groups )
35
+
32
36
managed_resources = []
33
37
for managed_resource_group in managed_resource_groups :
34
38
resources = resource_client .resources .list_by_resource_group (managed_resource_group )
39
+
35
40
for resource in resources :
36
41
if (resource .tags != None ) and ('ExpiryDate' in resource .tags ):
37
42
try :
Original file line number Diff line number Diff line change 5
5
"name" : " mytimer" ,
6
6
"type" : " timerTrigger" ,
7
7
"direction" : " in" ,
8
- "schedule" : " 0 */15 * * * *"
8
+ "schedule" : " 0 */5 * * * *"
9
9
}
10
10
]
11
11
}
Original file line number Diff line number Diff line change 1
1
import pytz
2
2
import logging
3
3
from datetime import datetime
4
+ from azure .mgmt .resource import ResourceManagementClient
4
5
6
+ def check_rg_availability (resource_client , managed_resource_groups ):
7
+ """
8
+ Check the resource group provided is available in Azure environment
9
+ """
10
+ # Get list of all resource groups
11
+ all_resource_groups = []
12
+ for resource_group in resource_client .resource_groups .list ():
13
+ all_resource_groups .append (resource_group .name )
14
+
15
+ # update managed resource group with existing
16
+ m_rgs = list (set (all_resource_groups ).intersection (set (managed_resource_groups )))
17
+ return m_rgs
5
18
6
19
def resource_extractor (resource , type ):
7
20
"""
Original file line number Diff line number Diff line change @@ -7,5 +7,5 @@ def tabulate_report(data):
7
7
"""
8
8
header = data [0 ].keys ()
9
9
rows = [x .values () for x in data ]
10
- return (tabulate .tabulate (rows , header , tablefmt = 'grid' ))
10
+ return (tabulate .tabulate (rows , header ))
11
11
You can’t perform that action at this time.
0 commit comments