diff --git a/awx/main/management/commands/instance_group_remove.py b/awx/main/management/commands/instance_group_remove.py index ca87cb8101..332ab2072f 100644 --- a/awx/main/management/commands/instance_group_remove.py +++ b/awx/main/management/commands/instance_group_remove.py @@ -5,11 +5,15 @@ import sys from awx.main.models import Instance, InstanceGroup from optparse import make_option -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandError class Command(BaseCommand): + help = ( + "Remove specified instances (specified by hostnames) from the specified queue (instance group).\n" + "In order remove the queue, use the `unregister_queue` command.") + option_list = BaseCommand.option_list + ( make_option('--queuename', dest='queuename', type='string', help='Queue to be removed from'), @@ -18,12 +22,14 @@ class Command(BaseCommand): ) def handle(self, **options): + if not options.get('queuename'): + raise CommandError('Must specify `--queuename` in order to use command.') ig = InstanceGroup.objects.filter(name=options.get('queuename')) if not ig.exists(): print("Queue doesn't exist") sys.exit(1) ig = ig.first() - i = Instance.objects.filter(name=options.get("hostname")) + i = Instance.objects.filter(hostname=options.get("hostname")) if not i.exists(): print("Host doesn't exist") sys.exit(1) diff --git a/awx/main/management/commands/register_queue.py b/awx/main/management/commands/register_queue.py index 37df320cd3..7eae1e1d97 100644 --- a/awx/main/management/commands/register_queue.py +++ b/awx/main/management/commands/register_queue.py @@ -26,7 +26,10 @@ class Command(BaseCommand): print("Creating instance group {}".format(options.get('queuename'))) ig = InstanceGroup(name=options.get('queuename')) ig.save() - instance_list = [x.strip() for x in options.get('hostnames').split(",")] + hostname_list = [] + if options.get('hostnames'): + hostname_list = options.get('hostnames').split(",") + instance_list = [x.strip() for x in hostname_list] for inst_name in instance_list: instance = Instance.objects.filter(hostname=inst_name) if instance.exists() and instance not in ig.instances.all(): diff --git a/awx/main/management/commands/unregister_queue.py b/awx/main/management/commands/unregister_queue.py index 827cee3dd6..388a8f0588 100644 --- a/awx/main/management/commands/unregister_queue.py +++ b/awx/main/management/commands/unregister_queue.py @@ -5,17 +5,24 @@ import sys from awx.main.models import InstanceGroup from optparse import make_option -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandError class Command(BaseCommand): + help = ( + "Remove specified queue (instance group) from database.\n" + "Instances inside of queue will continue to exist, \n" + "but jobs will no longer be processed by queue.") + option_list = BaseCommand.option_list + ( make_option('--queuename', dest='queuename', type='string', help='Queue to create/update'), ) def handle(self, **options): + if not options.get('queuename'): + raise CommandError('Must specify `--queuename` in order to use command.') ig = InstanceGroup.objects.filter(name=options.get('queuename')) if not ig.exists(): print("Instance group doesn't exist")