mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 01:17:37 -02:30
make awx-manage instance_list easier to read and more useful
This commit is contained in:
@@ -6,6 +6,22 @@ from django.core.management.base import BaseCommand
|
|||||||
import six
|
import six
|
||||||
|
|
||||||
|
|
||||||
|
class Ungrouped(object):
|
||||||
|
|
||||||
|
name = 'ungrouped'
|
||||||
|
policy_instance_percentage = None
|
||||||
|
policy_instance_minimum = None
|
||||||
|
controller = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def instances(self):
|
||||||
|
return Instance.objects.filter(rampart_groups__isnull=True)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def capacity(self):
|
||||||
|
return sum([x.capacity for x in self.instances])
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
"""List instances from the Tower database
|
"""List instances from the Tower database
|
||||||
"""
|
"""
|
||||||
@@ -13,12 +29,28 @@ class Command(BaseCommand):
|
|||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
super(Command, self).__init__()
|
super(Command, self).__init__()
|
||||||
|
|
||||||
for instance in Instance.objects.all():
|
groups = list(InstanceGroup.objects.all())
|
||||||
print(six.text_type(
|
ungrouped = Ungrouped()
|
||||||
"hostname: {0.hostname}; created: {0.created}; "
|
if len(ungrouped.instances):
|
||||||
"heartbeat: {0.modified}; capacity: {0.capacity}").format(instance))
|
groups.append(ungrouped)
|
||||||
for instance_group in InstanceGroup.objects.all():
|
|
||||||
print(six.text_type(
|
for instance_group in groups:
|
||||||
"Instance Group: {0.name}; created: {0.created}; "
|
fmt = '[{0.name} capacity={0.capacity}'
|
||||||
"capacity: {0.capacity}; members: {1}").format(instance_group,
|
if instance_group.policy_instance_percentage:
|
||||||
[x.hostname for x in instance_group.instances.all()]))
|
fmt += ' policy={0.policy_instance_percentage}%'
|
||||||
|
if instance_group.policy_instance_minimum:
|
||||||
|
fmt += ' policy>={0.policy_instance_minimum}'
|
||||||
|
if instance_group.controller:
|
||||||
|
fmt += ' controller={0.controller.name}'
|
||||||
|
print(six.text_type(fmt + ']').format(instance_group))
|
||||||
|
for x in instance_group.instances.all():
|
||||||
|
color = '\033[92m'
|
||||||
|
if x.capacity == 0 or x.enabled is False:
|
||||||
|
color = '\033[91m'
|
||||||
|
fmt = '\t' + color + '{0.hostname} capacity={0.capacity} version={1}'
|
||||||
|
if x.last_isolated_check:
|
||||||
|
fmt += ' last_isolated_check="{0.last_isolated_check:%Y-%m-%d %H:%M:%S}"'
|
||||||
|
if x.capacity:
|
||||||
|
fmt += ' heartbeat="{0.modified:%Y-%m-%d %H:%M:%S}"'
|
||||||
|
print(six.text_type(fmt + '\033[0m').format(x, x.version or '?'))
|
||||||
|
print('')
|
||||||
|
|||||||
Reference in New Issue
Block a user