Skip to content

Commit f6e3274

Browse files
authored
Merge pull request #15 from kang2453/master
feat: update logger initialization to use "spaceone" for consistency …
2 parents a98d1be + 61684e7 commit f6e3274

3 files changed

Lines changed: 51 additions & 58 deletions

File tree

src/cloudforet/plugin/manager/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
from cloudforet.plugin.config.global_conf import REGION_INFO
77

8-
_LOGGER = logging.getLogger(__name__)
8+
# _LOGGER = logging.getLogger(__name__)
9+
_LOGGER = logging.getLogger("spaceone")
910

1011
__all__ = ["ResourceManager"]
1112

src/cloudforet/plugin/manager/recommender/all_recommendations_manager.py

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
BIGQUERY_RECOMMENDERS,
77
RECOMMENDATION_TYPE_DOCS_URL,
88
UNAVAILABLE_RECOMMENDER_IDS,
9-
RECOMMENDATION_MAP,
109
)
1110
from abc import abstractmethod
1211
from cloudforet.plugin.connector.recommender.recommendation import (
@@ -17,7 +16,8 @@
1716
from bs4 import BeautifulSoup
1817
from cloudforet.plugin.utils.converter import Converter
1918

20-
_LOGGER = logging.getLogger(__name__)
19+
# _LOGGER = logging.getLogger(__name__)
20+
_LOGGER = logging.getLogger("spaceone")
2121

2222

2323
class AllRecommendationsManager(ResourceManager):
@@ -90,6 +90,7 @@ def create_cloud_service(self, options, secret_data, schema):
9090
for rec_parent in self.rec_parent_to_recs:
9191
if not self._is_category(self.rec_parent_to_recs[rec_parent][0]):
9292
continue
93+
9394
recommender_id = rec_parent.split("/")[-1]
9495
product, product_service = recommender_id.split(".")[:2]
9596
product = self.converter.convert_product_or_product_service_name(product)
@@ -206,14 +207,15 @@ def set_recommendation_id_map_by_crawling(self):
206207

207208
for recommender_id in recommender_ids:
208209
_LOGGER.debug(f"category: {category}, recommender_id: {recommender_id}, name: {name}, short_description: {short_description}")
210+
# print(f"recommender_id(key): {recommender_id}, category: {category}, name: {name}, short_description: {short_description}")
209211
self.recommender_map[recommender_id] = {
210212
"category": category,
211213
"name": name,
212214
"shortDescription": short_description,
213215
}
214216
except Exception as e:
215217
_LOGGER.error(f"Error occurred while crawling recommendation type docs: {e}")
216-
self.recommender_map = RECOMMENDATION_MAP
218+
# self.recommender_map = RECOMMENDATION_MAP
217219

218220
def _parse_recommendation(self, rec: dict) -> dict:
219221

@@ -333,26 +335,14 @@ def _create_parents_and_location_map_by_cloud_asset_api(assets):
333335
cloud_service_group, postfix = service.split(".", 1)
334336
cloud_service_type = cloud_service_type.lower()
335337

336-
if cloud_service_group not in parents_and_locations_map:
337-
parents_and_locations_map[cloud_service_group] = {}
338-
else:
339-
if (
340-
cloud_service_type
341-
not in parents_and_locations_map[cloud_service_group]
342-
):
343-
parents_and_locations_map[cloud_service_group][
344-
cloud_service_type
345-
] = [locations]
338+
if cloud_service_group in parents_and_locations_map:
339+
if cloud_service_type in parents_and_locations_map[cloud_service_group]:
340+
if locations not in parents_and_locations_map[cloud_service_group][cloud_service_type]:
341+
parents_and_locations_map[cloud_service_group][cloud_service_type].append(locations)
346342
else:
347-
if (
348-
locations
349-
not in parents_and_locations_map[cloud_service_group][
350-
cloud_service_type
351-
]
352-
):
353-
parents_and_locations_map[cloud_service_group][
354-
cloud_service_type
355-
].append(locations)
343+
parents_and_locations_map[cloud_service_group][cloud_service_type] = [locations]
344+
else:
345+
parents_and_locations_map[cloud_service_group] = {cloud_service_type: [locations]}
356346

357347
for group, cst_and_locations in parents_and_locations_map.items():
358348
all_locations = set()
@@ -367,12 +357,10 @@ def _add_group_and_service_to_recommender_map(self):
367357
recommender_map = self.recommender_map
368358
for key, value in recommender_map.items():
369359
prefix, cloud_service_group, cloud_service_type, *others = key.split(".")
370-
if not (
371-
cloud_service_type.endswith("Commitments")
372-
or cloud_service_type.endswith("Recommender")
373-
):
360+
if not (cloud_service_type.endswith("Commitments") or cloud_service_type.endswith("Recommender")):
374361
if cloud_service_group == "cloudsql":
375362
cloud_service_group = "sqladmin"
363+
376364
recommender_map[key]["cloudServiceGroup"] = cloud_service_group
377365
recommender_map[key]["cloudServiceType"] = cloud_service_type.lower()
378366
else:
@@ -381,46 +369,49 @@ def _add_group_and_service_to_recommender_map(self):
381369

382370
def _add_locations_to_recommender_map(self, parents_and_locations_map):
383371
recommender_map = self.recommender_map
384-
delete_services = []
372+
delete_services = set()
385373
for service, cst in parents_and_locations_map.items():
386374
if not cst:
387-
delete_services.append(service)
375+
_LOGGER.warning(f"parents_and_locations_map: cloud_service_group: {service} has no cloud_service_type")
376+
delete_services.add(service)
388377

389378
for service in delete_services:
390379
del parents_and_locations_map[service]
391380

381+
_LOGGER.debug(f"--------------------------------------------------------")
382+
for group, cst_and_locations in parents_and_locations_map.items():
383+
_LOGGER.debug(f"parents_and_locations_map: key: {group}, value: {cst_and_locations}")
384+
385+
392386
for key, value in self.recommender_map.items():
393-
cloud_service_group = value["cloudServiceGroup"]
394-
cloud_service_type = value["cloudServiceType"]
395-
396-
for service, cst_and_locations in parents_and_locations_map.items():
397-
if cloud_service_group == service:
398-
for service_key, locations in cst_and_locations.items():
399-
if cloud_service_type == service_key:
400-
recommender_map[key]["locations"] = locations
401-
402-
if (
403-
"locations" not in recommender_map[key]
404-
and cloud_service_group == "compute"
405-
):
406-
recommender_map[key]["locations"] = cst_and_locations[
407-
"instance"
408-
]
409-
410-
if cloud_service_type == "commitment":
411-
recommender_map[key]["locations"] = (
412-
self.converter.convert_zone_to_region(
413-
cst_and_locations["instance"]
414-
)
415-
)
416-
417-
if "locations" not in recommender_map[key]:
418-
recommender_map[key]["locations"] = cst_and_locations[
419-
"all_locations"
420-
]
387+
cloud_service_group = value["cloudServiceGroup"] # compute
388+
cloud_service_type = value["cloudServiceType"] # commitment, image, address, disk, instance, None, instancegroupmanager, instance,
389+
390+
cst_and_locations = parents_and_locations_map.get(cloud_service_group, None)
391+
if not cst_and_locations:
392+
_LOGGER.warning(f"No matching cloud_service_group: {cloud_service_group} found in parents_and_locations_map for recommender_id: {key}")
393+
continue
394+
395+
locations = cst_and_locations.get(cloud_service_type, None)
396+
if locations:
397+
recommender_map[key]["locations"] = locations
398+
399+
if ("locations" not in recommender_map[key] and cloud_service_group == "compute"):
400+
if cst_and_locations.get("instance", None):
401+
if cloud_service_type == "commitment":
402+
recommender_map[key]["locations"] = (self.converter.convert_zone_to_region(cst_and_locations["instance"]))
403+
else:
404+
recommender_map[key]["locations"] = cst_and_locations["instance"]
405+
406+
if "locations" not in recommender_map[key]:
407+
recommender_map[key]["locations"] = cst_and_locations["all_locations"]
421408

422409
if "locations" not in recommender_map[key]:
423410
recommender_map[key]["locations"] = ["global"]
424411

425412
if "global" not in recommender_map[key]["locations"]:
426413
recommender_map[key]["locations"].append("global")
414+
415+
_LOGGER.debug(f"--------------------------------------------------------")
416+
for key, value in recommender_map.items():
417+
_LOGGER.debug(f"recommender_map key: {key}, value: {value}")

src/cloudforet/plugin/manager/recommender/iam_management_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from cloudforet.plugin.manager import ResourceManager
1010
from cloudforet.plugin.utils.converter import Converter
1111

12-
_LOGGER = logging.getLogger(__name__)
12+
# _LOGGER = logging.getLogger(__name__)
13+
_LOGGER = logging.getLogger("spaceone")
1314

1415

1516
class IAMManagementRecommendationManager(ResourceManager):

0 commit comments

Comments
 (0)