-
Notifications
You must be signed in to change notification settings - Fork 4
/
list-quotas-regional.py
48 lines (36 loc) · 1.54 KB
/
list-quotas-regional.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# List GCP Regional project quotas
# Official GCP SDK (Python) Documentation: https://googleapis.github.io/google-api-python-client/docs/dyn/
import json
import ipcalc
import sys
import argparse
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
from google.cloud import resource_manager
client = resource_manager.Client()
credentials = GoogleCredentials.get_application_default()
compute = discovery.build('compute', 'v1', credentials=credentials)
# Filter of Projects that will be scanned
parser_args = argparse.ArgumentParser(description='Define the projetc_id filter.'
'if empity will looking for all the active project_id that the credential have access')
parser_args.add_argument('--project')
project_Filter = parser_args.parse_args()
if project_Filter.project is None:
env_filter = {'lifecycleState': 'ACTIVE' }
else:
env_filter = {'projectId': project_Filter.project ,'lifecycleState': 'ACTIVE' }
# print csv header
print ('project_id;project_name;region;metric;limit;usage')
for project in client.list_projects(env_filter):
region_request = compute.regions().list(project=project.project_id)
regions = region_request.execute()
for region in regions['items']:
for quota in region['quotas']:
print(
project.project_id, ';',
project.name, ';',
region.get('name'),';',
quota.get('metric'),';',
quota.get('limit'),';',
quota.get('usage'),';'
)