Exit logic fixes for instance group tools

This commit is contained in:
Matthew Jones 2017-05-11 13:56:30 -04:00
parent 47f4e5358b
commit 2c2e0d20a7
3 changed files with 8 additions and 2 deletions

View File

@ -1,5 +1,7 @@
# Copyright (c) 2017 Ansible Tower by Red Hat
# All Rights Reserved.
import sys
from awx.main.models import Instance, InstanceGroup
from optparse import make_option
@ -19,10 +21,12 @@ class Command(BaseCommand):
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"))
if not i.exists():
print("Host doesn't exist")
sys.exit(1)
i = i.first()
ig.instances.remove(i)
print("Instance removed from instance group")

View File

@ -14,7 +14,7 @@ class Command(BaseCommand):
make_option('--queuename', dest='queuename', type='string',
help='Queue to create/update'),
make_option('--hostnames', dest='hostnames', type='string',
help='List of hosts to add to the queue'),
help='Comma-Delimited Hosts to add to the Queue'),
)
def handle(self, **options):

View File

@ -1,5 +1,7 @@
# Copyright (c) 2017 Ansible Tower by Red Hat
# All Rights Reserved.
import sys
from awx.main.models import InstanceGroup
from optparse import make_option
@ -17,7 +19,7 @@ class Command(BaseCommand):
ig = InstanceGroup.objects.filter(name=options.get('queuename'))
if not ig.exists():
print("Instance group doesn't exist")
return
sys.exit(1)
ig = ig.first()
ig.delete()
print("Instance Group Removed")