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