1
1
import datetime
2
- import time
3
2
import logging
3
+ import time
4
+
4
5
from spaceone .inventory .libs .manager import AzureManager
5
6
from spaceone .inventory .libs .schema .base import ReferenceModel
6
7
from spaceone .inventory .connector .storage_accounts import StorageAccountsConnector
9
10
from spaceone .inventory .model .storage_accounts .cloud_service_type import CLOUD_SERVICE_TYPES
10
11
from spaceone .inventory .model .storage_accounts .data import *
11
12
12
-
13
13
_LOGGER = logging .getLogger (__name__ )
14
14
15
15
@@ -58,11 +58,11 @@ def collect_cloud_service(self, params):
58
58
})
59
59
60
60
if storage_account_dict .get ('name' ) is not None :
61
- container_item = self .list_blob_containers (storage_account_conn , resource_group , storage_account_dict [ 'name' ])
62
- storage_account_dict . update ({
63
- 'container_item' : container_item ,
64
- 'container_count_display' : len ( container_item )
65
- } )
61
+ container_count = self .get_blob_containers_count (storage_account_conn , resource_group ,
62
+ storage_account_dict [ 'name' ])
63
+
64
+ storage_account_dict . update ({ 'container_count_display' : container_count } )
65
+ _LOGGER . debug ( f'[collect_cloud_service] { storage_account_id } container count : { container_count } ' )
66
66
67
67
if storage_account_dict .get ('routing_preference' ) is not None :
68
68
storage_account_dict .update ({
@@ -93,9 +93,9 @@ def collect_cloud_service(self, params):
93
93
'instance_type' : storage_account_data .sku .tier
94
94
})
95
95
96
+
96
97
# Must set_region_code method for region collection
97
98
self .set_region_code (storage_account_data ['location' ])
98
- # _LOGGER.debug(f'[STORAGE ACCOUNT INFO] {storage_account_resource.to_primitive()}')
99
99
storage_account_responses .append (StorageAccountResponse ({'resource' : storage_account_resource }))
100
100
101
101
except Exception as e :
@@ -120,7 +120,8 @@ def get_network_rule_set(self, network_rule_dict):
120
120
'virtual_networks' : self .get_virtual_network_names (network_rule_dict ['virtual_network_rules' ]),
121
121
'is_public_access_allowed' : False
122
122
})
123
- if not network_rule_dict .get ('virtual_network_rules' ): # if virtual_network_rules are empty, this SA is public allowable
123
+ if not network_rule_dict .get (
124
+ 'virtual_network_rules' ): # if virtual_network_rules are empty, this SA is public allowable
124
125
network_rule_dict .update ({
125
126
'is_public_access_allowed' : True
126
127
})
@@ -258,3 +259,9 @@ def _get_timespan_from_now(hours):
258
259
time_now = datetime .datetime .utcnow () - datetime .timedelta (hours = 1 )
259
260
time_now_hours_ago = time_now - datetime .timedelta (hours = hours )
260
261
return "{}/{}" .format (time_now_hours_ago , time_now )
262
+
263
+ @staticmethod
264
+ def get_blob_containers_count (storage_conn , rg_name , account_name ):
265
+ blob_containers_obj = storage_conn .list_blob_containers (rg_name = rg_name , account_name = account_name )
266
+ return len (list (blob_containers_obj ))
267
+
0 commit comments