1 # -*- coding: utf-8 -*-
3 from typing
import NamedTuple
8 class ClusterCapacity(NamedTuple
):
11 total_used_raw_bytes
: int
13 total_pool_bytes_used
: int
14 average_object_size
: int
25 def __init__(self
, status
=Status
.POST_INSTALLED
.name
):
27 :param status: The status of the cluster. Assume that the cluster
28 is already functional by default.
31 self
.status
= self
.Status
[status
]
34 return {'status': self
.status
.name
}
37 mgr
.set_store('cluster/status', self
.status
.name
)
42 Get the stored cluster status from the configuration key/value store.
43 If the status is not set, assume it is already fully functional.
45 return cls(status
=mgr
.get_store('cluster/status', cls
.Status
.POST_INSTALLED
.name
))
48 def get_capacity(cls
) -> ClusterCapacity
:
50 total_pool_bytes_used
= 0
51 average_object_size
= 0
52 total_data_pool_objects
= 0
53 total_data_pool_bytes_used
= 0
54 rgw_pools_data
= cls
.get_rgw_pools()
56 for pool
in df
['pools']:
57 pool_name
= str(pool
['name'])
58 if pool_name
in rgw_pools_data
:
59 if pool_name
.endswith('.data'):
60 objects
= pool
['stats']['objects']
61 pool_bytes_used
= pool
['stats']['bytes_used']
62 total_pool_bytes_used
+= pool_bytes_used
63 total_data_pool_objects
+= objects
64 replica
= rgw_pools_data
[pool_name
]
65 total_data_pool_bytes_used
+= pool_bytes_used
/ replica
67 average_object_size
= total_data_pool_bytes_used
/ total_data_pool_objects
if total_data_pool_objects
!= 0 else 0 # noqa E501 #pylint: disable=line-too-long
69 return ClusterCapacity(
70 total_avail_bytes
=df
['stats']['total_avail_bytes'],
71 total_bytes
=df
['stats']['total_bytes'],
72 total_used_raw_bytes
=df
['stats']['total_used_raw_bytes'],
73 total_objects
=total_data_pool_objects
,
74 total_pool_bytes_used
=total_pool_bytes_used
,
75 average_object_size
=average_object_size
79 def get_rgw_pools(cls
):
82 osd_map
= mgr
.get('osd_map')
83 for pool
in osd_map
['pools']:
84 if 'rgw' in pool
.get('application_metadata', {}):
85 name
= pool
['pool_name']
86 rgw_pool_size
[name
] = pool
['size']