mirror of
https://github.com/ansible/awx.git
synced 2026-03-10 14:09:28 -02:30
Update management commands
This commit is contained in:
@@ -2,12 +2,12 @@
|
|||||||
# All Rights Reserved
|
# All Rights Reserved
|
||||||
|
|
||||||
from awx.main.utils import get_licenser
|
from awx.main.utils import get_licenser
|
||||||
from django.core.management.base import NoArgsCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
|
||||||
class Command(NoArgsCommand):
|
class Command(BaseCommand):
|
||||||
"""Returns license type, e.g., 'enterprise', 'open', 'none'"""
|
"""Returns license type, e.g., 'enterprise', 'open', 'none'"""
|
||||||
|
|
||||||
def handle(self, **options):
|
def handle(self, *args, **options):
|
||||||
super(Command, self).__init__()
|
super(Command, self).__init__()
|
||||||
return get_licenser().validate().get('license_type', 'none')
|
return get_licenser().validate().get('license_type', 'none')
|
||||||
|
|||||||
@@ -4,29 +4,28 @@
|
|||||||
# Python
|
# Python
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
from optparse import make_option
|
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.core.management.base import NoArgsCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.main.models import ActivityStream
|
from awx.main.models import ActivityStream
|
||||||
|
|
||||||
|
|
||||||
class Command(NoArgsCommand):
|
class Command(BaseCommand):
|
||||||
'''
|
'''
|
||||||
Management command to purge old activity stream events.
|
Management command to purge old activity stream events.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
help = 'Remove old activity stream events from the database'
|
help = 'Remove old activity stream events from the database'
|
||||||
|
|
||||||
option_list = NoArgsCommand.option_list + (
|
def add_arguments(self, parser):
|
||||||
make_option('--days', dest='days', type='int', default=90, metavar='N',
|
parser.add_argument('--days', dest='days', type='int', default=90, metavar='N',
|
||||||
help='Remove activity stream events more than N days old'),
|
help='Remove activity stream events more than N days old')
|
||||||
make_option('--dry-run', dest='dry_run', action='store_true',
|
parser.add_argument('--dry-run', dest='dry_run', action='store_true',
|
||||||
default=False, help='Dry run mode (show items that would '
|
default=False, help='Dry run mode (show items that would '
|
||||||
'be removed)'),)
|
'be removed)')
|
||||||
|
|
||||||
def init_logging(self):
|
def init_logging(self):
|
||||||
log_levels = dict(enumerate([logging.ERROR, logging.INFO,
|
log_levels = dict(enumerate([logging.ERROR, logging.INFO,
|
||||||
@@ -61,7 +60,7 @@ class Command(NoArgsCommand):
|
|||||||
n_deleted_items += len(pks_to_delete)
|
n_deleted_items += len(pks_to_delete)
|
||||||
self.logger.log(99, "Removed %d items", n_deleted_items)
|
self.logger.log(99, "Removed %d items", n_deleted_items)
|
||||||
|
|
||||||
def handle_noargs(self, **options):
|
def handle(self, *args, **options):
|
||||||
self.verbosity = int(options.get('verbosity', 1))
|
self.verbosity = int(options.get('verbosity', 1))
|
||||||
self.init_logging()
|
self.init_logging()
|
||||||
self.days = int(options.get('days', 30))
|
self.days = int(options.get('days', 30))
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
# Python
|
# Python
|
||||||
import re
|
import re
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from optparse import make_option
|
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
@@ -93,19 +92,20 @@ class CleanupFacts(object):
|
|||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = 'Cleanup facts. For each host older than the value specified, keep one fact scan for each time window (granularity).'
|
help = 'Cleanup facts. For each host older than the value specified, keep one fact scan for each time window (granularity).'
|
||||||
option_list = BaseCommand.option_list + (
|
|
||||||
make_option('--older_than',
|
def add_arguments(self, parser):
|
||||||
dest='older_than',
|
parser.add_argument('--older_than',
|
||||||
default='30d',
|
dest='older_than',
|
||||||
help='Specify the relative time to consider facts older than (w)eek (d)ay or (y)ear (i.e. 5d, 2w, 1y). Defaults to 30d.'),
|
default='30d',
|
||||||
make_option('--granularity',
|
help='Specify the relative time to consider facts older than (w)eek (d)ay or (y)ear (i.e. 5d, 2w, 1y). Defaults to 30d.')
|
||||||
dest='granularity',
|
parser.add_argument('--granularity',
|
||||||
default='1w',
|
dest='granularity',
|
||||||
help='Window duration to group same hosts by for deletion (w)eek (d)ay or (y)ear (i.e. 5d, 2w, 1y). Defaults to 1w.'),
|
default='1w',
|
||||||
make_option('--module',
|
help='Window duration to group same hosts by for deletion (w)eek (d)ay or (y)ear (i.e. 5d, 2w, 1y). Defaults to 1w.')
|
||||||
dest='module',
|
parser.add_argument('--module',
|
||||||
default=None,
|
dest='module',
|
||||||
help='Limit cleanup to a particular module.'),)
|
default=None,
|
||||||
|
help='Limit cleanup to a particular module.')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(Command, self).__init__()
|
super(Command, self).__init__()
|
||||||
|
|||||||
@@ -4,10 +4,9 @@
|
|||||||
# Python
|
# Python
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
from optparse import make_option
|
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.core.management.base import NoArgsCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
|
|
||||||
@@ -25,41 +24,40 @@ from awx.main.signals import ( # noqa
|
|||||||
from django.db.models.signals import post_save, post_delete, m2m_changed # noqa
|
from django.db.models.signals import post_save, post_delete, m2m_changed # noqa
|
||||||
|
|
||||||
|
|
||||||
class Command(NoArgsCommand):
|
class Command(BaseCommand):
|
||||||
'''
|
'''
|
||||||
Management command to cleanup old jobs and project updates.
|
Management command to cleanup old jobs and project updates.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
help = 'Remove old jobs, project and inventory updates from the database.'
|
help = 'Remove old jobs, project and inventory updates from the database.'
|
||||||
|
|
||||||
option_list = NoArgsCommand.option_list + (
|
def add_arguments(self, parser):
|
||||||
make_option('--days', dest='days', type='int', default=90, metavar='N',
|
parser.add_argument('--days', dest='days', type='int', default=90, metavar='N',
|
||||||
help='Remove jobs/updates executed more than N days ago. Defaults to 90.'),
|
help='Remove jobs/updates executed more than N days ago. Defaults to 90.')
|
||||||
make_option('--dry-run', dest='dry_run', action='store_true',
|
parser.add_argument('--dry-run', dest='dry_run', action='store_true',
|
||||||
default=False, help='Dry run mode (show items that would '
|
default=False, help='Dry run mode (show items that would '
|
||||||
'be removed)'),
|
'be removed)')
|
||||||
make_option('--jobs', dest='only_jobs', action='store_true',
|
parser.add_argument('--jobs', dest='only_jobs', action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help='Remove jobs'),
|
help='Remove jobs')
|
||||||
make_option('--ad-hoc-commands', dest='only_ad_hoc_commands',
|
parser.add_argument('--ad-hoc-commands', dest='only_ad_hoc_commands',
|
||||||
action='store_true', default=False,
|
action='store_true', default=False,
|
||||||
help='Remove ad hoc commands'),
|
help='Remove ad hoc commands')
|
||||||
make_option('--project-updates', dest='only_project_updates',
|
parser.add_argument('--project-updates', dest='only_project_updates',
|
||||||
action='store_true', default=False,
|
action='store_true', default=False,
|
||||||
help='Remove project updates'),
|
help='Remove project updates')
|
||||||
make_option('--inventory-updates', dest='only_inventory_updates',
|
parser.add_argument('--inventory-updates', dest='only_inventory_updates',
|
||||||
action='store_true', default=False,
|
action='store_true', default=False,
|
||||||
help='Remove inventory updates'),
|
help='Remove inventory updates')
|
||||||
make_option('--management-jobs', default=False,
|
parser.add_argument('--management-jobs', default=False,
|
||||||
action='store_true', dest='only_management_jobs',
|
action='store_true', dest='only_management_jobs',
|
||||||
help='Remove management jobs'),
|
help='Remove management jobs')
|
||||||
make_option('--notifications', dest='only_notifications',
|
parser.add_argument('--notifications', dest='only_notifications',
|
||||||
action='store_true', default=False,
|
action='store_true', default=False,
|
||||||
help='Remove notifications'),
|
help='Remove notifications')
|
||||||
make_option('--workflow-jobs', default=False,
|
parser.add_argument('--workflow-jobs', default=False,
|
||||||
action='store_true', dest='only_workflow_jobs',
|
action='store_true', dest='only_workflow_jobs',
|
||||||
help='Remove workflow jobs')
|
help='Remove workflow jobs')
|
||||||
)
|
|
||||||
|
|
||||||
def cleanup_jobs(self):
|
def cleanup_jobs(self):
|
||||||
#jobs_qs = Job.objects.exclude(status__in=('pending', 'running'))
|
#jobs_qs = Job.objects.exclude(status__in=('pending', 'running'))
|
||||||
@@ -223,7 +221,7 @@ class Command(NoArgsCommand):
|
|||||||
return skipped, deleted
|
return skipped, deleted
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def handle_noargs(self, **options):
|
def handle(self, *args, **options):
|
||||||
self.verbosity = int(options.get('verbosity', 1))
|
self.verbosity = int(options.get('verbosity', 1))
|
||||||
self.init_logging()
|
self.init_logging()
|
||||||
self.days = int(options.get('days', 90))
|
self.days = int(options.get('days', 90))
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
# Copyright (c) 2016 Ansible, Inc.
|
# Copyright (c) 2016 Ansible, Inc.
|
||||||
# All Rights Reserved
|
# All Rights Reserved
|
||||||
|
|
||||||
from optparse import make_option
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
@@ -22,12 +21,11 @@ class Command(BaseCommand):
|
|||||||
'Specify `--hostname` to use this command.'
|
'Specify `--hostname` to use this command.'
|
||||||
)
|
)
|
||||||
|
|
||||||
option_list = BaseCommand.option_list + (
|
def add_arguments(self, parser):
|
||||||
make_option('--hostname', dest='hostname', type='string',
|
parser.add_argument('--hostname', dest='hostname', type=str,
|
||||||
help='Hostname used during provisioning'),
|
help='Hostname used during provisioning')
|
||||||
make_option('--name', dest='name', type='string',
|
parser.add_argument('--name', dest='name', type=str,
|
||||||
help='(PENDING DEPRECIATION) Hostname used during provisioning'),
|
help='(PENDING DEPRECIATION) Hostname used during provisioning')
|
||||||
)
|
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
# Python
|
# Python
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from optparse import make_option
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -15,7 +14,7 @@ import shutil
|
|||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.management.base import NoArgsCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.db import connection, transaction
|
from django.db import connection, transaction
|
||||||
from django.utils.encoding import smart_text
|
from django.utils.encoding import smart_text
|
||||||
@@ -251,7 +250,7 @@ def load_inventory_source(source, group_filter_re=None,
|
|||||||
return inventory.all_group
|
return inventory.all_group
|
||||||
|
|
||||||
|
|
||||||
class Command(NoArgsCommand):
|
class Command(BaseCommand):
|
||||||
'''
|
'''
|
||||||
Management command to import inventory from a directory, ini file, or
|
Management command to import inventory from a directory, ini file, or
|
||||||
dynamic inventory script.
|
dynamic inventory script.
|
||||||
@@ -259,50 +258,49 @@ class Command(NoArgsCommand):
|
|||||||
|
|
||||||
help = 'Import or sync external inventory sources'
|
help = 'Import or sync external inventory sources'
|
||||||
|
|
||||||
option_list = NoArgsCommand.option_list + (
|
def add_arguments(self, parser):
|
||||||
make_option('--inventory-name', dest='inventory_name', type='str',
|
parser.add_argument('--inventory-name', dest='inventory_name',
|
||||||
default=None, metavar='n',
|
type='str', default=None, metavar='n',
|
||||||
help='name of inventory to sync'),
|
help='name of inventory to sync')
|
||||||
make_option('--inventory-id', dest='inventory_id', type='int',
|
parser.add_argument('--inventory-id', dest='inventory_id', type='int',
|
||||||
default=None, metavar='i', help='id of inventory to sync'),
|
default=None, metavar='i',
|
||||||
make_option('--overwrite', dest='overwrite', action='store_true',
|
help='id of inventory to sync')
|
||||||
metavar="o", default=False,
|
parser.add_argument('--overwrite', dest='overwrite', action='store_true',
|
||||||
help='overwrite the destination hosts and groups'),
|
metavar="o", default=False,
|
||||||
make_option('--overwrite-vars', dest='overwrite_vars',
|
help='overwrite the destination hosts and groups')
|
||||||
action='store_true', metavar="V", default=False,
|
parser.add_argument('--overwrite-vars', dest='overwrite_vars',
|
||||||
help='overwrite (rather than merge) variables'),
|
action='store_true', metavar="V", default=False,
|
||||||
make_option('--keep-vars', dest='keep_vars', action='store_true',
|
help='overwrite (rather than merge) variables')
|
||||||
metavar="k", default=False,
|
parser.add_argument('--keep-vars', dest='keep_vars', action='store_true',
|
||||||
help='use database variables if set'),
|
metavar="k", default=False,
|
||||||
make_option('--custom', dest='custom', action='store_true',
|
help='use database variables if set')
|
||||||
metavar="c", default=False,
|
parser.add_argument('--custom', dest='custom', action='store_true',
|
||||||
help='this is a custom inventory script'),
|
metavar="c", default=False,
|
||||||
make_option('--source', dest='source', type='str', default=None,
|
help='this is a custom inventory script')
|
||||||
metavar='s', help='inventory directory, file, or script '
|
parser.add_argument('--source', dest='source', type='str', default=None,
|
||||||
'to load'),
|
metavar='s', help='inventory directory, file, or script to load')
|
||||||
make_option('--enabled-var', dest='enabled_var', type='str',
|
parser.add_argument('--enabled-var', dest='enabled_var', type='str',
|
||||||
default=None, metavar='v', help='host variable used to '
|
default=None, metavar='v', help='host variable used to '
|
||||||
'set/clear enabled flag when host is online/offline, may '
|
'set/clear enabled flag when host is online/offline, may '
|
||||||
'be specified as "foo.bar" to traverse nested dicts.'),
|
'be specified as "foo.bar" to traverse nested dicts.')
|
||||||
make_option('--enabled-value', dest='enabled_value', type='str',
|
parser.add_argument('--enabled-value', dest='enabled_value', type='str',
|
||||||
default=None, metavar='v', help='value of host variable '
|
default=None, metavar='v', help='value of host variable '
|
||||||
'specified by --enabled-var that indicates host is '
|
'specified by --enabled-var that indicates host is '
|
||||||
'enabled/online.'),
|
'enabled/online.')
|
||||||
make_option('--group-filter', dest='group_filter', type='str',
|
parser.add_argument('--group-filter', dest='group_filter', type='str',
|
||||||
default=None, metavar='regex', help='regular expression '
|
default=None, metavar='regex', help='regular expression '
|
||||||
'to filter group name(s); only matches are imported.'),
|
'to filter group name(s); only matches are imported.')
|
||||||
make_option('--host-filter', dest='host_filter', type='str',
|
parser.add_argument('--host-filter', dest='host_filter', type='str',
|
||||||
default=None, metavar='regex', help='regular expression '
|
default=None, metavar='regex', help='regular expression '
|
||||||
'to filter host name(s); only matches are imported.'),
|
'to filter host name(s); only matches are imported.')
|
||||||
make_option('--exclude-empty-groups', dest='exclude_empty_groups',
|
parser.add_argument('--exclude-empty-groups', dest='exclude_empty_groups',
|
||||||
action='store_true', default=False, help='when set, '
|
action='store_true', default=False, help='when set, '
|
||||||
'exclude all groups that have no child groups, hosts, or '
|
'exclude all groups that have no child groups, hosts, or '
|
||||||
'variables.'),
|
'variables.')
|
||||||
make_option('--instance-id-var', dest='instance_id_var', type='str',
|
parser.add_argument('--instance-id-var', dest='instance_id_var', type='str',
|
||||||
default=None, metavar='v', help='host variable that '
|
default=None, metavar='v', help='host variable that '
|
||||||
'specifies the unique, immutable instance ID, may be '
|
'specifies the unique, immutable instance ID, may be '
|
||||||
'specified as "foo.bar" to traverse nested dicts.'),
|
'specified as "foo.bar" to traverse nested dicts.')
|
||||||
)
|
|
||||||
|
|
||||||
def set_logging_level(self):
|
def set_logging_level(self):
|
||||||
log_levels = dict(enumerate([logging.WARNING, logging.INFO,
|
log_levels = dict(enumerate([logging.WARNING, logging.INFO,
|
||||||
@@ -927,7 +925,7 @@ class Command(NoArgsCommand):
|
|||||||
self.inventory_update.license_error = True
|
self.inventory_update.license_error = True
|
||||||
self.inventory_update.save(update_fields=['license_error'])
|
self.inventory_update.save(update_fields=['license_error'])
|
||||||
|
|
||||||
def handle_noargs(self, **options):
|
def handle(self, *args, **options):
|
||||||
self.verbosity = int(options.get('verbosity', 1))
|
self.verbosity = int(options.get('verbosity', 1))
|
||||||
self.set_logging_level()
|
self.set_logging_level()
|
||||||
self.inventory_name = options.get('inventory_name', None)
|
self.inventory_name = options.get('inventory_name', None)
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
# All Rights Reserved
|
# All Rights Reserved
|
||||||
|
|
||||||
from awx.main.models import Instance, InstanceGroup
|
from awx.main.models import Instance, InstanceGroup
|
||||||
from django.core.management.base import NoArgsCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
|
||||||
class Command(NoArgsCommand):
|
class Command(BaseCommand):
|
||||||
"""List instances from the Tower database
|
"""List instances from the Tower database
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def handle(self, **options):
|
def handle(self, *args, **options):
|
||||||
super(Command, self).__init__()
|
super(Command, self).__init__()
|
||||||
|
|
||||||
for instance in Instance.objects.all():
|
for instance in Instance.objects.all():
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ from awx.main.models import Instance
|
|||||||
from awx.main.utils.pglock import advisory_lock
|
from awx.main.utils.pglock import advisory_lock
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from optparse import make_option
|
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
|
||||||
@@ -21,10 +20,9 @@ class Command(BaseCommand):
|
|||||||
'Specify `--hostname` to use this command.'
|
'Specify `--hostname` to use this command.'
|
||||||
)
|
)
|
||||||
|
|
||||||
option_list = BaseCommand.option_list + (
|
def add_arguments(self, parser):
|
||||||
make_option('--hostname', dest='hostname', type='string',
|
parser.add_argument('--hostname', dest='hostname', type=str,
|
||||||
help='Hostname used during provisioning'),
|
help='Hostname used during provisioning')
|
||||||
)
|
|
||||||
|
|
||||||
def _register_hostname(self, hostname):
|
def _register_hostname(self, hostname):
|
||||||
if not hostname:
|
if not hostname:
|
||||||
|
|||||||
@@ -5,20 +5,18 @@ import sys
|
|||||||
from awx.main.utils.pglock import advisory_lock
|
from awx.main.utils.pglock import advisory_lock
|
||||||
from awx.main.models import Instance, InstanceGroup
|
from awx.main.models import Instance, InstanceGroup
|
||||||
|
|
||||||
from optparse import make_option
|
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
|
||||||
option_list = BaseCommand.option_list + (
|
def add_arguments(self, parser):
|
||||||
make_option('--queuename', dest='queuename', type='string',
|
parser.add_argument('--queuename', dest='queuename', type=str,
|
||||||
help='Queue to create/update'),
|
help='Queue to create/update')
|
||||||
make_option('--hostnames', dest='hostnames', type='string',
|
parser.add_argument('--hostnames', dest='hostnames', type=str,
|
||||||
help='Comma-Delimited Hosts to add to the Queue'),
|
help='Comma-Delimited Hosts to add to the Queue')
|
||||||
make_option('--controller', dest='controller', type='string', default='',
|
parser.add_argument('--controller', dest='controller', type=str,
|
||||||
help='The controlling group (makes this an isolated group)'),
|
default='', help='The controlling group (makes this an isolated group)')
|
||||||
)
|
|
||||||
|
|
||||||
def handle(self, **options):
|
def handle(self, **options):
|
||||||
queuename = options.get('queuename')
|
queuename = options.get('queuename')
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from awx.main.models import Instance, InstanceGroup
|
from awx.main.models import Instance, InstanceGroup
|
||||||
|
|
||||||
from optparse import make_option
|
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
|
||||||
|
|
||||||
@@ -14,14 +12,13 @@ class Command(BaseCommand):
|
|||||||
"Remove an instance (specified by --hostname) from the specified queue (instance group).\n"
|
"Remove an instance (specified by --hostname) from the specified queue (instance group).\n"
|
||||||
"In order remove the queue, use the `unregister_queue` command.")
|
"In order remove the queue, use the `unregister_queue` command.")
|
||||||
|
|
||||||
option_list = BaseCommand.option_list + (
|
def add_arguments(self, parser):
|
||||||
make_option('--queuename', dest='queuename', type='string',
|
parser.add_argument('--queuename', dest='queuename', type=str,
|
||||||
help='Queue to be removed from'),
|
help='Queue to be removed from')
|
||||||
make_option('--hostname', dest='hostname', type='string',
|
parser.add_argument('--hostname', dest='hostname', type=str,
|
||||||
help='Host to remove from queue'),
|
help='Host to remove from queue')
|
||||||
)
|
|
||||||
|
|
||||||
def handle(self, **options):
|
def handle(self, *arg, **options):
|
||||||
if not options.get('queuename'):
|
if not options.get('queuename'):
|
||||||
raise CommandError('Must specify `--queuename` in order to use command.')
|
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'))
|
||||||
@@ -36,4 +33,3 @@ class Command(BaseCommand):
|
|||||||
i = i.first()
|
i = i.first()
|
||||||
ig.instances.remove(i)
|
ig.instances.remove(i)
|
||||||
print("Instance removed from instance group")
|
print("Instance removed from instance group")
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,9 @@
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
from optparse import make_option
|
|
||||||
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.core.management.base import NoArgsCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
from awx.main.models import (
|
from awx.main.models import (
|
||||||
UnifiedJob,
|
UnifiedJob,
|
||||||
@@ -162,18 +161,17 @@ class ReplayJobEvents():
|
|||||||
print(json.dumps(stats, indent=4, sort_keys=True))
|
print(json.dumps(stats, indent=4, sort_keys=True))
|
||||||
|
|
||||||
|
|
||||||
class Command(NoArgsCommand):
|
class Command(BaseCommand):
|
||||||
|
|
||||||
help = 'Replay job events over websockets ordered by created on date.'
|
help = 'Replay job events over websockets ordered by created on date.'
|
||||||
|
|
||||||
option_list = NoArgsCommand.option_list + (
|
def add_arguments(self, parser):
|
||||||
make_option('--job_id', dest='job_id', type='int', metavar='j',
|
parser.add_argument('--job_id', dest='job_id', type='int', metavar='j',
|
||||||
help='Id of the job to replay (job or adhoc)'),
|
help='Id of the job to replay (job or adhoc)')
|
||||||
make_option('--speed', dest='speed', type='int', metavar='s',
|
parser.add_argument('--speed', dest='speed', type='int', metavar='s',
|
||||||
help='Speedup factor.'),
|
help='Speedup factor.')
|
||||||
)
|
|
||||||
|
|
||||||
def handle_noargs(self, **options):
|
def handle(self, *args, **options):
|
||||||
job_id = options.get('job_id')
|
job_id = options.get('job_id')
|
||||||
speed = options.get('speed') or 1
|
speed = options.get('speed') or 1
|
||||||
verbosity = options.get('verbosity') or 0
|
verbosity = options.get('verbosity') or 0
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ from kombu.mixins import ConsumerMixin
|
|||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.management.base import NoArgsCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.db import connection as django_connection
|
from django.db import connection as django_connection
|
||||||
from django.db import DatabaseError
|
from django.db import DatabaseError
|
||||||
from django.core.cache import cache as django_cache
|
from django.core.cache import cache as django_cache
|
||||||
@@ -147,7 +147,7 @@ class CallbackBrokerWorker(ConsumerMixin):
|
|||||||
logger.error('Detail: {}'.format(tb))
|
logger.error('Detail: {}'.format(tb))
|
||||||
|
|
||||||
|
|
||||||
class Command(NoArgsCommand):
|
class Command(BaseCommand):
|
||||||
'''
|
'''
|
||||||
Save Job Callback receiver (see awx.plugins.callbacks.job_event_callback)
|
Save Job Callback receiver (see awx.plugins.callbacks.job_event_callback)
|
||||||
Runs as a management command and receives job save events. It then hands
|
Runs as a management command and receives job save events. It then hands
|
||||||
@@ -155,8 +155,8 @@ class Command(NoArgsCommand):
|
|||||||
'''
|
'''
|
||||||
help = 'Launch the job callback receiver'
|
help = 'Launch the job callback receiver'
|
||||||
|
|
||||||
def handle_noargs(self, **options):
|
def handle(self, *arg, **options):
|
||||||
with Connection(settings.BROKER_URL) as conn:
|
with Connection(settings.CELERY_BROKER_URL) as conn:
|
||||||
try:
|
try:
|
||||||
worker = CallbackBrokerWorker(conn)
|
worker = CallbackBrokerWorker(conn)
|
||||||
worker.run()
|
worker.run()
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
# Copyright (c) 2015 Ansible, Inc.
|
# Copyright (c) 2015 Ansible, Inc.
|
||||||
# All Rights Reserved
|
# All Rights Reserved
|
||||||
|
|
||||||
from optparse import make_option
|
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.main.models import * # noqa
|
from awx.main.models import UnifiedJob
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
@@ -17,14 +15,13 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
help = 'Display some simple statistics'
|
help = 'Display some simple statistics'
|
||||||
|
|
||||||
option_list = BaseCommand.option_list + (
|
def add_arguments(self, parser):
|
||||||
make_option('--stat',
|
parser.add_argument('--stat',
|
||||||
action='store',
|
action='store',
|
||||||
dest='stat',
|
dest='stat',
|
||||||
type="string",
|
type="string",
|
||||||
default="jobs_running",
|
default="jobs_running",
|
||||||
help='Select which stat to get information for'),
|
help='Select which stat to get information for')
|
||||||
)
|
|
||||||
|
|
||||||
def job_stats(self, state):
|
def job_stats(self, state):
|
||||||
return UnifiedJob.objects.filter(status=state).count()
|
return UnifiedJob.objects.filter(status=state).count()
|
||||||
@@ -34,5 +31,3 @@ class Command(BaseCommand):
|
|||||||
self.stdout.write(str(self.job_stats(options['stat'][5:])))
|
self.stdout.write(str(self.job_stats(options['stat'][5:])))
|
||||||
else:
|
else:
|
||||||
self.stdout.write("Supported stats: jobs_{state}")
|
self.stdout.write("Supported stats: jobs_{state}")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import sys
|
|||||||
from awx.main.utils.pglock import advisory_lock
|
from awx.main.utils.pglock import advisory_lock
|
||||||
from awx.main.models import InstanceGroup
|
from awx.main.models import InstanceGroup
|
||||||
|
|
||||||
from optparse import make_option
|
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
|
||||||
@@ -17,13 +16,12 @@ class Command(BaseCommand):
|
|||||||
"Instances inside of queue will continue to exist, \n"
|
"Instances inside of queue will continue to exist, \n"
|
||||||
"but jobs will no longer be processed by queue.")
|
"but jobs will no longer be processed by queue.")
|
||||||
|
|
||||||
option_list = BaseCommand.option_list + (
|
def add_arguments(self, parser):
|
||||||
make_option('--queuename', dest='queuename', type='string',
|
parser.add_argument('--queuename', dest='queuename', type=str,
|
||||||
help='Queue to create/update'),
|
help='Queue to create/update')
|
||||||
)
|
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def handle(self, **options):
|
def handle(self, *args, **options):
|
||||||
queuename = options.get('queuename')
|
queuename = options.get('queuename')
|
||||||
if not queuename:
|
if not queuename:
|
||||||
raise CommandError('Must specify `--queuename` in order to use command.')
|
raise CommandError('Must specify `--queuename` in order to use command.')
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
# Copyright (c) 2016 Ansible, Inc.
|
# Copyright (c) 2016 Ansible, Inc.
|
||||||
# All Rights Reserved
|
# All Rights Reserved
|
||||||
|
|
||||||
# Python
|
|
||||||
from optparse import make_option
|
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.core.management.base import CommandError
|
from django.core.management.base import CommandError
|
||||||
@@ -25,12 +22,11 @@ class UpdatePassword(object):
|
|||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
option_list = BaseCommand.option_list + (
|
def add_arguments(self, parser):
|
||||||
make_option('--username', dest='username', action='store', type='string', default=None,
|
parser.add_argument('--username', dest='username', action='store', type=str, default=None,
|
||||||
help='username to change the password for'),
|
help='username to change the password for')
|
||||||
make_option('--password', dest='password', action='store', type='string', default=None,
|
parser.add_argument('--password', dest='password', action='store', type=str, default=None,
|
||||||
help='new password for user'),
|
help='new password for user')
|
||||||
)
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
if not options['username']:
|
if not options['username']:
|
||||||
@@ -43,5 +39,3 @@ class Command(BaseCommand):
|
|||||||
if res:
|
if res:
|
||||||
return "Password updated"
|
return "Password updated"
|
||||||
return "Password not updated"
|
return "Password not updated"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user