@@ -25,45 +25,46 @@ class DataTransferGenerator(AWSGenerator):
25
25
"""Generator for Data Transfer data."""
26
26
27
27
DATA_TRANSFER = (
28
- ("{}-{}-AWS-In-Bytes" , "PublicIP-In" , "InterRegion Inbound" ),
29
- ("{}-{}-AWS-Out-Bytes" , "PublicIP-Out" , "InterRegion Outbound" ),
28
+ # (usage type, operation, transfer type)
29
+ ("{region1}-{region2}-AWS-{direction}-Bytes" , "PublicIP-{direction}" , "InterRegion {direction}bound" ),
30
+ ("DataTransfer-{direction}-Bytes" , "RunInstances" , "" ),
31
+ ("{region1}-DataTransfer-Regional-Bytes" , "PublicIP-{direction}" , "" ),
32
+ ("{region1}-DataTransfer-Regional-Bytes" , "InterZone-{direction}" , "" ),
30
33
)
34
+ DATA_TRANSFER_DIRECTIONS = ("in" , "out" )
31
35
32
36
def __init__ (self , start_date , end_date , currency , payer_account , usage_accounts , attributes = None , tag_cols = None ):
33
37
"""Initialize the data transfer generator."""
34
38
super ().__init__ (start_date , end_date , currency , payer_account , usage_accounts , attributes , tag_cols )
35
- self ._amount = None
36
- self ._rate = None
37
- self ._saving = None
38
- self ._product_sku = None
39
- self ._resource_id = None
40
- self ._product_code = "AmazonEC2"
41
- self ._product_name = "Amazon Elastic Compute Cloud"
42
- if attributes :
43
- if attributes .get ("product_code" ):
44
- self ._product_code = attributes .get ("product_code" )
45
- if attributes .get ("product_name" ):
46
- self ._product_name = attributes .get ("product_name" )
47
- if attributes .get ("resource_id" ):
48
- self ._resource_id = attributes .get ("resource_id" )
49
- if attributes .get ("amount" ):
50
- self ._amount = float (attributes .get ("amount" ))
51
- if attributes .get ("rate" ):
52
- self ._rate = float (attributes .get ("rate" ))
53
- if attributes .get ("product_sku" ):
54
- self ._product_sku = attributes .get ("product_sku" )
55
- if attributes .get ("tags" ):
56
- self ._tags = attributes .get ("tags" )
57
- if attributes .get ("saving" ):
58
- self ._saving = float (attributes .get ("saving" ))
39
+
40
+ self ._amount = float (self .attributes .get ("amount" , 0 )) or None
41
+ self ._data_direction = self .attributes .get ("data_direction" )
42
+ self ._product_code = self .attributes .get ("product_code" , "AmazonEC2" )
43
+ self ._product_name = self .attributes .get ("product_name" , "Amazon Elastic Compute Cloud" )
44
+ self ._product_sku = self .attributes .get ("product_sku" )
45
+ self ._rate = float (self .attributes .get ("rate" , 0 )) or None
46
+ self ._resource_id = f"i-{ self .attributes .get ('resource_id' , self .fake .ean8 ())} "
47
+ self ._saving = float (self .attributes .get ("saving" , 0 )) or None
48
+ self ._tags = self .attributes .get ("tags" , self ._tags )
49
+
50
+ @property
51
+ def data_direction (self ):
52
+ if self ._data_direction is not None :
53
+ return self ._data_direction .capitalize ()
54
+
55
+ # Purposefully not caching this value so a different value is returned on each call
56
+ return choice (self .DATA_TRANSFER_DIRECTIONS ).capitalize ()
59
57
60
58
def _get_data_transfer (self , rate ):
61
59
"""Get data transfer info."""
62
60
location1 , aws_region , _ , storage_region1 = self ._get_location ()
63
61
location2 , _ , _ , storage_region2 = self ._get_location ()
64
62
trans_desc , operation , trans_type = choice (self .DATA_TRANSFER )
65
- trans_desc = trans_desc .format (storage_region1 , storage_region2 )
63
+ trans_desc = trans_desc .format (region1 = storage_region1 , region2 = storage_region2 , direction = self .data_direction )
64
+ operation = operation .format (direction = self .data_direction )
65
+ trans_type = trans_type .format (direction = self .data_direction )
66
66
description = f"${ rate } per GB - { location1 } data transfer to { location2 } "
67
+
67
68
return trans_desc , operation , description , location1 , location2 , trans_type , aws_region
68
69
69
70
def _get_product_sku (self ):
0 commit comments