mirror of
https://github.com/ansible/awx.git
synced 2026-01-16 04:10:44 -03:30
handle user corner cases related to instance group commands
This commit is contained in:
parent
22249b2625
commit
198b3f0a94
@ -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)
|
||||
|
||||
@ -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():
|
||||
|
||||
@ -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")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user