1- import os
21import abc
3- import logging
42import datetime
5- import time
3+ import logging
4+ import os
65import re
6+ import time
77from typing import Union
88
9- from spaceone .core .manager import BaseManager
109from spaceone .core import utils
10+ from spaceone .core .manager import BaseManager
1111from spaceone .inventory .plugin .collector .lib import *
1212
1313_LOGGER = logging .getLogger ("spaceone" )
@@ -47,7 +47,10 @@ def list_managers_by_cloud_service_groups(cls, cloud_service_groups: list):
4747 yield manager
4848 elif cloud_service_groups :
4949 for manager in cls .__subclasses__ ():
50- if manager .cloud_service_group and manager .cloud_service_group in cloud_service_groups :
50+ if (
51+ manager .cloud_service_group
52+ and manager .cloud_service_group in cloud_service_groups
53+ ):
5154 yield manager
5255
5356 @classmethod
@@ -62,21 +65,23 @@ def collect_metrics(cls, cloud_service_group: str):
6265 if not os .path .exists (os .path .join (_METRIC_DIR , cloud_service_group )):
6366 os .mkdir (os .path .join (_METRIC_DIR , cloud_service_group ))
6467 for dirname in os .listdir (os .path .join (_METRIC_DIR , cloud_service_group )):
65- for filename in os .listdir (os .path .join (_METRIC_DIR , cloud_service_group , dirname )):
68+ for filename in os .listdir (
69+ os .path .join (_METRIC_DIR , cloud_service_group , dirname )
70+ ):
6671 if filename .endswith (".yaml" ):
67- file_path = os .path .join (_METRIC_DIR , cloud_service_group , dirname , filename )
72+ file_path = os .path .join (
73+ _METRIC_DIR , cloud_service_group , dirname , filename
74+ )
6875 info = utils .load_yaml_from_file (file_path )
6976 if filename == "namespace.yaml" :
7077 yield make_response (
7178 namespace = info ,
7279 resource_type = "inventory.Namespace" ,
73- match_keys = []
80+ match_keys = [],
7481 )
7582 else :
7683 yield make_response (
77- metric = info ,
78- resource_type = "inventory.Metric" ,
79- match_keys = []
84+ metric = info , resource_type = "inventory.Metric" , match_keys = []
8085 )
8186
8287 def collect_resources (self , options : dict , secret_data : dict , schema : str ):
@@ -89,17 +94,21 @@ def collect_resources(self, options: dict, secret_data: dict, schema: str):
8994 try :
9095 yield from self .collect_cloud_service_type ()
9196
92- cloud_services , total_count = self .collect_cloud_service (options , secret_data , schema
93- )
97+ cloud_services , total_count = self .collect_cloud_service (
98+ options , secret_data , schema
99+ )
94100 for cloud_service in cloud_services :
95101 yield cloud_service
96102 success_count , error_count = total_count
97103
98- subscriptions_manager = AzureBaseManager .get_managers_by_cloud_service_group ("SubscriptionsManager" )
104+ subscriptions_manager = (
105+ AzureBaseManager .get_managers_by_cloud_service_group (
106+ "SubscriptionsManager"
107+ )
108+ )
99109 location_info = subscriptions_manager ().list_location_info (secret_data )
100110
101111 yield from self .collect_region (location_info )
102- # yield from self.collect_region(secret_data)
103112
104113 except Exception as e :
105114 yield make_error_response (
@@ -166,7 +175,7 @@ def collect_cloud_service(self, options: dict, secret_data: dict, schema: str):
166175 "provider" ,
167176 "cloud_service_type" ,
168177 "cloud_service_group" ,
169- "account"
178+ "account" ,
170179 ]
171180 ],
172181 )
@@ -188,18 +197,22 @@ def get_metadata_path(self):
188197 _cloud_service_group = self ._camel_to_snake (self .cloud_service_group )
189198 _cloud_service_type = self ._camel_to_snake (self .cloud_service_type )
190199
191- return os .path .join (_METADATA_DIR , _cloud_service_group , f"{ _cloud_service_type } .yaml" )
200+ return os .path .join (
201+ _METADATA_DIR , _cloud_service_group , f"{ _cloud_service_type } .yaml"
202+ )
192203
193- def convert_nested_dictionary (self , cloud_svc_object : object ) -> Union [object , dict ]:
204+ def convert_nested_dictionary (
205+ self , cloud_svc_object : object
206+ ) -> Union [object , dict ]:
194207 cloud_svc_dict = {}
195208 if hasattr (
196- cloud_svc_object , "__dict__"
209+ cloud_svc_object , "__dict__"
197210 ): # if cloud_svc_object is not a dictionary type but has dict method
198211 cloud_svc_dict = cloud_svc_object .__dict__
199212 elif isinstance (cloud_svc_object , dict ):
200213 cloud_svc_dict = cloud_svc_object
201214 elif not isinstance (
202- cloud_svc_object , list
215+ cloud_svc_object , list
203216 ): # if cloud_svc_object is one of type like int, float, char, ...
204217 return cloud_svc_object
205218
@@ -232,15 +245,12 @@ def make_reference(resource_id: str, external_link_format: str = None) -> dict:
232245 external_link = external_link_format .format (resource_id = resource_id )
233246 else :
234247 external_link = f"https://portal.azure.com/#@.onmicrosoft.com/resource{ resource_id } /overview"
235- return {
236- "resource_id" : resource_id ,
237- "external_link" : external_link
238- }
248+ return {"resource_id" : resource_id , "external_link" : external_link }
239249
240250 @staticmethod
241251 def _camel_to_snake (name ):
242- name = re .sub (' (.)([A-Z][a-z]+)' , r' \1_\2' , name )
243- return re .sub (' ([a-z0-9])([A-Z])' , r' \1_\2' , name ).lower ()
252+ name = re .sub (" (.)([A-Z][a-z]+)" , r" \1_\2" , name )
253+ return re .sub (" ([a-z0-9])([A-Z])" , r" \1_\2" , name ).lower ()
244254
245255 @staticmethod
246256 def get_resource_group_from_id (dict_id ):
@@ -249,7 +259,7 @@ def get_resource_group_from_id(dict_id):
249259
250260 @staticmethod
251261 def update_tenant_id_from_secret_data (
252- cloud_service_data : dict , secret_data : dict
262+ cloud_service_data : dict , secret_data : dict
253263 ) -> dict :
254264 if tenant_id := secret_data .get ("tenant_id" ):
255265 cloud_service_data .update ({"tenant_id" : tenant_id })
0 commit comments