mirror of
https://github.com/ansible/awx.git
synced 2026-05-10 02:47:36 -02:30
Adjust the list_instances command to show hop nodes
with appropriate attributes removed or added.
This commit is contained in:
@@ -11,13 +11,16 @@ class Ungrouped(object):
|
|||||||
policy_instance_percentage = None
|
policy_instance_percentage = None
|
||||||
policy_instance_minimum = None
|
policy_instance_minimum = None
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.qs = Instance.objects.filter(rampart_groups__isnull=True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def instances(self):
|
def instances(self):
|
||||||
return Instance.objects.filter(rampart_groups__isnull=True).exclude(node_type='hop')
|
return self.qs
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def capacity(self):
|
def capacity(self):
|
||||||
return sum(x.capacity for x in self.instances)
|
return sum(x.capacity for x in self.instances.all())
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
@@ -29,26 +32,29 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
groups = list(InstanceGroup.objects.all())
|
groups = list(InstanceGroup.objects.all())
|
||||||
ungrouped = Ungrouped()
|
ungrouped = Ungrouped()
|
||||||
if len(ungrouped.instances):
|
if len(ungrouped.instances.all()):
|
||||||
groups.append(ungrouped)
|
groups.append(ungrouped)
|
||||||
|
|
||||||
for instance_group in groups:
|
for ig in groups:
|
||||||
fmt = '[{0.name} capacity={0.capacity}'
|
policy = ''
|
||||||
if instance_group.policy_instance_percentage:
|
if ig.policy_instance_percentage:
|
||||||
fmt += ' policy={0.policy_instance_percentage}%'
|
policy = f' policy={ig.policy_instance_percentage}%'
|
||||||
if instance_group.policy_instance_minimum:
|
if ig.policy_instance_minimum:
|
||||||
fmt += ' policy>={0.policy_instance_minimum}'
|
policy = f' policy>={ig.policy_instance_minimum}'
|
||||||
print((fmt + ']').format(instance_group))
|
print(f'[{ig.name} capacity={ig.capacity}{policy}]')
|
||||||
for x in instance_group.instances.all():
|
|
||||||
|
for x in ig.instances.all():
|
||||||
color = '\033[92m'
|
color = '\033[92m'
|
||||||
if x.capacity == 0:
|
if x.capacity == 0 and x.node_type != 'hop':
|
||||||
color = '\033[91m'
|
color = '\033[91m'
|
||||||
if x.enabled is False:
|
if not x.enabled:
|
||||||
color = '\033[90m[DISABLED] '
|
color = '\033[90m[DISABLED] '
|
||||||
if no_color:
|
if no_color:
|
||||||
color = ''
|
color = ''
|
||||||
fmt = '\t' + color + '{0.hostname} capacity={0.capacity} node_type={0.node_type} version={1}'
|
|
||||||
if x.capacity:
|
capacity = f' capacity={x.capacity}' if x.node_type != 'hop' else ''
|
||||||
fmt += ' heartbeat="{0.modified:%Y-%m-%d %H:%M:%S}"'
|
version = f" version={x.version or '?'}" if x.node_type != 'hop' else ''
|
||||||
print((fmt + '\033[0m').format(x, x.version or '?'))
|
heartbeat = f' heartbeat="{x.modified:%Y-%m-%d %H:%M:%S}"' if x.capacity or x.node_type == 'hop' else ''
|
||||||
print('')
|
print(f'\t{color}{x.hostname}{capacity} node_type={x.node_type}{version}{heartbeat}\033[0m')
|
||||||
|
|
||||||
|
print()
|
||||||
|
|||||||
Reference in New Issue
Block a user