fixed tree command

This commit is contained in:
Adolfo Gómez García 2022-09-19 14:23:44 +02:00
parent 9c6c4078b1
commit aa677353ad
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23

View File

@ -109,6 +109,14 @@ class Command(BaseCommand):
default=False, default=False,
help='Shows ALL user services, not just the ones with errors', help='Shows ALL user services, not just the ones with errors',
) )
# Maximum items allowed for groups and user services
parser.add_argument(
'--max-items',
action='store',
dest='maxitems',
default=100,
help='Maximum elements exported for groups and user services',
)
def handle(self, *args, **options): def handle(self, *args, **options):
logger.debug("Show Tree") logger.debug("Show Tree")
@ -120,24 +128,28 @@ class Command(BaseCommand):
cntr += 1 cntr += 1
return f'{cntr:02d}.-{s}' return f'{cntr:02d}.-{s}'
max_items = int(options['maxitems'])
tree = {} tree = {}
try: try:
providers = {} providers = {}
for provider in models.Provider.objects.all(): for provider in models.Provider.objects.all():
services = {} services = {}
numberOfServices = 0 totalServices = 0
numberOfServicePools = 0 totalServicePools = 0
numberOfUserServices = 0 totalUserServices = 0
for service in provider.services.all(): for service in provider.services.all():
servicePools = {} servicePools = {}
numberOfServicePools = 0
numberOfUserServices = 0
for servicePool in service.deployedServices.all(): for servicePool in service.deployedServices.all():
# get assigned user services with ERROR status # get assigned user services with ERROR status
userServices = {} userServices = {}
fltr = servicePool.userServices.all() fltr = servicePool.userServices.all()
if not options['alluserservices']: if not options['alluserservices']:
fltr = fltr.filter(state=State.ERROR) fltr = fltr.filter(state=State.ERROR)
for item in fltr[:10]: # at most 100 items for item in fltr[:max_items]: # at most max_items items
logs = [ logs = [
'{}: {} [{}] - {}'.format( '{}: {} [{}] - {}'.format(
l['date'], l['date'],
@ -150,7 +162,6 @@ class Command(BaseCommand):
userServices[item.friendly_name] = { userServices[item.friendly_name] = {
'_': { '_': {
'id': item.uuid, 'id': item.uuid,
'id_deployed_service': item.deployed_service.uuid,
'unique_id': item.unique_id, 'unique_id': item.unique_id,
'friendly_name': item.friendly_name, 'friendly_name': item.friendly_name,
'state': State.toString(item.state), 'state': State.toString(item.state),
@ -169,7 +180,8 @@ class Command(BaseCommand):
'logs': logs, 'logs': logs,
} }
numberOfUserServices += len(userServices) numberOfUserServices = len(userServices)
totalUserServices += numberOfUserServices
# get publications # get publications
publications = {} publications = {}
@ -218,7 +230,7 @@ class Command(BaseCommand):
): ):
calendarAccess[ca.calendar.name] = ca.access calendarAccess[ca.calendar.name] = ca.access
servicePools[servicePool.name] = { servicePools[f'{servicePool.name} ({numberOfUserServices})'] = {
'_': getSerializedFromModel(servicePool), '_': getSerializedFromModel(servicePool),
'userServices': userServices, 'userServices': userServices,
'calendarAccess': calendarAccess, 'calendarAccess': calendarAccess,
@ -227,16 +239,17 @@ class Command(BaseCommand):
'publications': publications, 'publications': publications,
} }
numberOfServicePools += len(servicePools) numberOfServicePools = len(servicePools)
totalServicePools += numberOfServicePools
services[service.name] = { services[f'{service.name} ({numberOfServicePools}, {numberOfUserServices})'] = {
'_': getSerializedFromManagedObject(service), '_': getSerializedFromManagedObject(service),
'servicePools': servicePools, 'servicePools': servicePools,
} }
numberOfServices += len(services) totalServices += len(services)
providers[ providers[
f'{provider.name} ({numberOfServices}, {numberOfServicePools}, {numberOfUserServices})' f'{provider.name} ({totalServices}, {totalServicePools}, {totalUserServices})'
] = { ] = {
'_': getSerializedFromManagedObject(provider), '_': getSerializedFromManagedObject(provider),
'services': services, 'services': services,
@ -248,12 +261,12 @@ class Command(BaseCommand):
authenticators = {} authenticators = {}
for authenticator in models.Authenticator.objects.all(): for authenticator in models.Authenticator.objects.all():
# Groups # Groups
# groups = {} groups = {}
# for group in authenticator.groups.all(): for group in authenticator.groups.all()[:max_items]: # at most max_items items
# groups[group.name] = getSerializedFromModel(group) groups[group.name] = getSerializedFromModel(group, ['manager_id', 'name'])
authenticators[authenticator.name] = { authenticators[authenticator.name] = {
'_': getSerializedFromManagedObject(authenticator), '_': getSerializedFromManagedObject(authenticator),
# 'groups': groups, 'groups': groups,
} }
tree[counter('AUTHENTICATORS')] = authenticators tree[counter('AUTHENTICATORS')] = authenticators