Retrieve database usage
This commit is contained in:
parent
85fc900b6a
commit
7ebe3b61c0
|
@ -153,16 +153,37 @@ class DatabaseService(OrchestraModel):
|
|||
if 'users' in data:
|
||||
users = [DatabaseUser.new_from_json(user_data) for user_data in data['users']]
|
||||
|
||||
# TODO(@slamora) retrieve database usage
|
||||
usage = {
|
||||
'usage': 250,
|
||||
'total': 500,
|
||||
'unit': 'MB',
|
||||
'percent': 50,
|
||||
}
|
||||
usage = cls.get_usage(data)
|
||||
|
||||
return super().new_from_json(data=data, users=users, usage=usage)
|
||||
|
||||
@classmethod
|
||||
def get_usage(self, data):
|
||||
try:
|
||||
resources = data['resources']
|
||||
resource_disk = {}
|
||||
for r in resources:
|
||||
if r['name'] == 'disk':
|
||||
resource_disk = r
|
||||
break
|
||||
|
||||
details = {
|
||||
'usage': float(resource_disk['used']),
|
||||
'total': resource_disk['allocated'],
|
||||
'unit': resource_disk['unit'],
|
||||
}
|
||||
except (IndexError, KeyError):
|
||||
return {}
|
||||
|
||||
|
||||
percent = get_bootstraped_percent(
|
||||
details['usage'],
|
||||
details['total']
|
||||
)
|
||||
details['percent'] = percent
|
||||
|
||||
return details
|
||||
|
||||
|
||||
class Domain(OrchestraModel):
|
||||
api_name = 'domain'
|
||||
|
|
Loading…
Reference in New Issue