mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 18:07:36 -02:30
Fix some issues with management commands for clustering
This commit is contained in:
27
awx/main/management/commands/deprovision_node.py
Normal file
27
awx/main/management/commands/deprovision_node.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Copyright (c) 2016 Ansible, Inc.
|
||||||
|
# All Rights Reserved
|
||||||
|
|
||||||
|
from django.core.management.base import CommandError, BaseCommand
|
||||||
|
from optparse import make_option
|
||||||
|
from awx.main.models import Instance
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
"""
|
||||||
|
Deprovision a Tower cluster node
|
||||||
|
"""
|
||||||
|
|
||||||
|
option_list = BaseCommand.option_list + (
|
||||||
|
make_option('--name', dest='name', type='string',
|
||||||
|
help='Hostname used during provisioning'),
|
||||||
|
)
|
||||||
|
|
||||||
|
def handle(self, **options):
|
||||||
|
# Get the instance.
|
||||||
|
instance = Instance.objects.filter(hostname=options.get('name'))
|
||||||
|
if instance.exists():
|
||||||
|
instance.delete()
|
||||||
|
print('Successfully removed')
|
||||||
|
else:
|
||||||
|
print('No instance found matching name {}'.format(options.get('name')))
|
||||||
|
|
||||||
@@ -4,27 +4,26 @@
|
|||||||
from awx.main.models import Instance
|
from awx.main.models import Instance
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from django.core.management.base import CommandError, NoArgsCommand
|
from optparse import make_option
|
||||||
|
from django.core.management.base import CommandError, BaseCommand
|
||||||
|
|
||||||
class Command(NoArgsCommand):
|
class Command(BaseCommand):
|
||||||
"""
|
"""
|
||||||
Internal tower command.
|
Internal tower command.
|
||||||
Regsiter this instance with the database for HA tracking.
|
Regsiter this instance with the database for HA tracking.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
option_list = NoArgsCommand.option_list + (
|
option_list = BaseCommand.option_list + (
|
||||||
make_option('--hostname', dest='hostname', type='string',
|
make_option('--hostname', dest='hostname', type='string',
|
||||||
help='Hostname used during provisioning')
|
help='Hostname used during provisioning'),
|
||||||
)
|
)
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, **options):
|
||||||
super(Command, self).handle(**options)
|
|
||||||
uuid = settings.SYSTEM_UUID
|
uuid = settings.SYSTEM_UUID
|
||||||
|
|
||||||
instance = Instance.objects.filter(hostname=options.get('hostname'))
|
instance = Instance.objects.filter(hostname=options.get('hostname'))
|
||||||
if instance.exists():
|
if instance.exists():
|
||||||
print("Instance already registered %s" % instance_str(instance[0]))
|
print("Instance already registered {}".format(instance[0]))
|
||||||
return
|
return
|
||||||
instance = Instance(uuid=uuid, hostname=options.get('hostname'))
|
instance = Instance(uuid=uuid, hostname=options.get('hostname'))
|
||||||
instance.save()
|
instance.save()
|
||||||
print('Successfully registered instance %s.' % instance_str(instance))
|
print('Successfully registered instance {}'.format(instance))
|
||||||
|
|||||||
Reference in New Issue
Block a user