|
11 | 11 |
|
12 | 12 | from math import ceil |
13 | 13 |
|
14 | | -from attr import evolve |
| 14 | +from attr import evolve, field |
15 | 15 | from attrs import define |
16 | 16 | from boto3.exceptions import Boto3Error |
17 | 17 |
|
|
28 | 28 | Cloud, |
29 | 29 | EdgeType, |
30 | 30 | ModelReference, |
| 31 | + PhantomBaseResource, |
31 | 32 | ) |
32 | 33 | from fixlib.config import Config, current_config |
33 | 34 | from fixlib.core.actions import CoreFeedback, SuppressWithFeedback |
@@ -257,11 +258,15 @@ def called_mutator_apis(cls) -> List[AwsApiSpec]: |
257 | 258 | return [] |
258 | 259 |
|
259 | 260 | def post_process(self, builder: GraphBuilder, source: Json) -> None: |
260 | | - # Default behavior: do nothing |
| 261 | + # Hook method: called after the resource has been created and added to the graph. |
261 | 262 | pass |
262 | 263 |
|
263 | 264 | def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None: |
264 | | - # Default behavior: add resource to the namespace |
| 265 | + # Hook method: called when all resources are collected. |
| 266 | + pass |
| 267 | + |
| 268 | + def complete_graph(self, builder: GraphBuilder, source: Json) -> None: |
| 269 | + # Hook that is called when all resources have been collected and connected. |
265 | 270 | pass |
266 | 271 |
|
267 | 272 | def __str__(self) -> str: |
@@ -368,13 +373,27 @@ class AwsRegion(BaseRegion, AwsResource): |
368 | 373 | } |
369 | 374 | } |
370 | 375 | ctime: Optional[datetime] = default_ctime |
| 376 | + region_in_use: Optional[bool] = field(default=None, metadata={"description": "Indicates if the region is in use."}) |
371 | 377 |
|
372 | 378 | def __attrs_post_init__(self) -> None: |
373 | 379 | super().__attrs_post_init__() |
374 | 380 | self.long_name = cloud_region_data.get("aws", {}).get(self.id, {}).get("long_name") |
375 | 381 | self.latitude = cloud_region_data.get("aws", {}).get(self.id, {}).get("latitude") |
376 | 382 | self.longitude = cloud_region_data.get("aws", {}).get(self.id, {}).get("longitude") |
377 | 383 |
|
| 384 | + def complete_graph(self, builder: GraphBuilder, source: Json) -> None: |
| 385 | + count = 0 |
| 386 | + # A region with less than 10 real resources is considered not in use. |
| 387 | + # AWS is creating a couple of resources in every region automatically. |
| 388 | + # The number 10 is chosen by looking into different empty regions. |
| 389 | + empty_region = 10 |
| 390 | + for succ in builder.graph.descendants(self): |
| 391 | + if not isinstance(succ, PhantomBaseResource): |
| 392 | + count += 1 |
| 393 | + if count > empty_region: |
| 394 | + break |
| 395 | + self.region_in_use = count > empty_region |
| 396 | + |
378 | 397 |
|
379 | 398 | @define(eq=False, slots=False) |
380 | 399 | class AwsEc2VolumeType(AwsResource, BaseVolumeType): |
|
0 commit comments