mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 01:17:37 -02:30
handle user corner cases related to instance group commands
This commit is contained in:
@@ -5,11 +5,15 @@ import sys
|
|||||||
from awx.main.models import Instance, InstanceGroup
|
from awx.main.models import Instance, InstanceGroup
|
||||||
|
|
||||||
from optparse import make_option
|
from optparse import make_option
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
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 + (
|
option_list = BaseCommand.option_list + (
|
||||||
make_option('--queuename', dest='queuename', type='string',
|
make_option('--queuename', dest='queuename', type='string',
|
||||||
help='Queue to be removed from'),
|
help='Queue to be removed from'),
|
||||||
@@ -18,12 +22,14 @@ class Command(BaseCommand):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def handle(self, **options):
|
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'))
|
ig = InstanceGroup.objects.filter(name=options.get('queuename'))
|
||||||
if not ig.exists():
|
if not ig.exists():
|
||||||
print("Queue doesn't exist")
|
print("Queue doesn't exist")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
ig = ig.first()
|
ig = ig.first()
|
||||||
i = Instance.objects.filter(name=options.get("hostname"))
|
i = Instance.objects.filter(hostname=options.get("hostname"))
|
||||||
if not i.exists():
|
if not i.exists():
|
||||||
print("Host doesn't exist")
|
print("Host doesn't exist")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
@@ -26,7 +26,10 @@ class Command(BaseCommand):
|
|||||||
print("Creating instance group {}".format(options.get('queuename')))
|
print("Creating instance group {}".format(options.get('queuename')))
|
||||||
ig = InstanceGroup(name=options.get('queuename'))
|
ig = InstanceGroup(name=options.get('queuename'))
|
||||||
ig.save()
|
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:
|
for inst_name in instance_list:
|
||||||
instance = Instance.objects.filter(hostname=inst_name)
|
instance = Instance.objects.filter(hostname=inst_name)
|
||||||
if instance.exists() and instance not in ig.instances.all():
|
if instance.exists() and instance not in ig.instances.all():
|
||||||
|
|||||||
@@ -5,17 +5,24 @@ import sys
|
|||||||
from awx.main.models import InstanceGroup
|
from awx.main.models import InstanceGroup
|
||||||
|
|
||||||
from optparse import make_option
|
from optparse import make_option
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
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 + (
|
option_list = BaseCommand.option_list + (
|
||||||
make_option('--queuename', dest='queuename', type='string',
|
make_option('--queuename', dest='queuename', type='string',
|
||||||
help='Queue to create/update'),
|
help='Queue to create/update'),
|
||||||
)
|
)
|
||||||
|
|
||||||
def handle(self, **options):
|
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'))
|
ig = InstanceGroup.objects.filter(name=options.get('queuename'))
|
||||||
if not ig.exists():
|
if not ig.exists():
|
||||||
print("Instance group doesn't exist")
|
print("Instance group doesn't exist")
|
||||||
|
|||||||
Reference in New Issue
Block a user