Skip to content

Commit

Permalink
Merge pull request cloudforet-io#82 from ImMin5/feature-fix-collect-s…
Browse files Browse the repository at this point in the history
…torage-account-size-too-big

Feature fix collect storage account size too big
  • Loading branch information
ImMin5 committed Sep 26, 2023
2 parents b79ce0c + c964dde commit 7ff5289
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.6.15
v1.6.16
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import time
import logging
import time

from spaceone.inventory.libs.manager import AzureManager
from spaceone.inventory.libs.schema.base import ReferenceModel
from spaceone.inventory.connector.storage_accounts import StorageAccountsConnector
Expand All @@ -9,7 +10,6 @@
from spaceone.inventory.model.storage_accounts.cloud_service_type import CLOUD_SERVICE_TYPES
from spaceone.inventory.model.storage_accounts.data import *


_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -58,11 +58,11 @@ def collect_cloud_service(self, params):
})

if storage_account_dict.get('name') is not None:
container_item = self.list_blob_containers(storage_account_conn, resource_group, storage_account_dict['name'])
storage_account_dict.update({
'container_item': container_item,
'container_count_display': len(container_item)
})
container_count = self.get_blob_containers_count(storage_account_conn, resource_group,
storage_account_dict['name'])

storage_account_dict.update({'container_count_display': container_count})
_LOGGER.debug(f'[collect_cloud_service] {storage_account_id} container count : {container_count}')

if storage_account_dict.get('routing_preference') is not None:
storage_account_dict.update({
Expand Down Expand Up @@ -93,9 +93,9 @@ def collect_cloud_service(self, params):
'instance_type': storage_account_data.sku.tier
})


# Must set_region_code method for region collection
self.set_region_code(storage_account_data['location'])
# _LOGGER.debug(f'[STORAGE ACCOUNT INFO] {storage_account_resource.to_primitive()}')
storage_account_responses.append(StorageAccountResponse({'resource': storage_account_resource}))

except Exception as e:
Expand All @@ -120,7 +120,8 @@ def get_network_rule_set(self, network_rule_dict):
'virtual_networks': self.get_virtual_network_names(network_rule_dict['virtual_network_rules']),
'is_public_access_allowed': False
})
if not network_rule_dict.get('virtual_network_rules'): # if virtual_network_rules are empty, this SA is public allowable
if not network_rule_dict.get(
'virtual_network_rules'): # if virtual_network_rules are empty, this SA is public allowable
network_rule_dict.update({
'is_public_access_allowed': True
})
Expand Down Expand Up @@ -258,3 +259,9 @@ def _get_timespan_from_now(hours):
time_now = datetime.datetime.utcnow() - datetime.timedelta(hours=1)
time_now_hours_ago = time_now - datetime.timedelta(hours=hours)
return "{}/{}".format(time_now_hours_ago, time_now)

@staticmethod
def get_blob_containers_count(storage_conn, rg_name, account_name):
blob_containers_obj = storage_conn.list_blob_containers(rg_name=rg_name, account_name=account_name)
return len(list(blob_containers_obj))

17 changes: 2 additions & 15 deletions src/spaceone/inventory/model/storage_accounts/cloud_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,6 @@
TextDyField.data_source('Internet Endpoints', 'data.routing_preference.publish_internet_endpoints')
])

# TAB - Containers
storage_account_containers = TableDynamicLayout.set_fields('Containers', 'data.container_item', fields=[
TextDyField.data_source('Name', 'name'),
TextDyField.data_source('Public Access Level', 'public_access'),
DateTimeDyField.data_source('Last Modified', 'last_modified_time'),
TextDyField.data_source('ETAG', 'etag'),
TextDyField.data_source('Lease Status', 'lease_status'),
TextDyField.data_source('Lease State', 'lease_state'),
TextDyField.data_source('Lease Duration', 'lease_duration'),
TextDyField.data_source('Encryption Score', 'default_encryption_scope')

])

# TAB - Encryption
storage_account_encryption = ItemDynamicLayout.set_fields('Encryption', 'data.encryption', fields=[
TextDyField.data_source('Key Source', 'key_source'),
Expand All @@ -89,8 +76,8 @@
])

storage_account_meta = CloudServiceMeta.set_layouts(
[storage_account_info_meta, storage_group_networking, storage_account_primary_endpoints, storage_account_containers,
storage_account_encryption, storage_account_geo_replication])
[storage_account_info_meta, storage_group_networking, storage_account_primary_endpoints, storage_account_encryption,
storage_account_geo_replication])


class StorageResource(CloudServiceResource):
Expand Down

0 comments on commit 7ff5289

Please sign in to comment.