awxkit cli support

fixes for awx cli
This commit is contained in:
Seth Foster
2023-01-26 01:45:42 -05:00
committed by Elijah DeLee
parent 861ba8a727
commit 34834252ff
7 changed files with 114 additions and 36 deletions

View File

@@ -44,6 +44,10 @@ class CustomAction(metaclass=CustomActionRegistryMeta):
class Launchable(object):
@property
def options_endpoint(self):
return self.page.endpoint + '1/{}/'.format(self.action)
def add_arguments(self, parser, resource_options_parser, with_pk=True):
from .options import pk_or_name
@@ -53,7 +57,7 @@ class Launchable(object):
parser.choices[self.action].add_argument('--action-timeout', type=int, help='If set with --monitor or --wait, time out waiting on job completion.')
parser.choices[self.action].add_argument('--wait', action='store_true', help='If set, waits until the launched job finishes.')
launch_time_options = self.page.connection.options(self.page.endpoint + '1/{}/'.format(self.action))
launch_time_options = self.page.connection.options(self.options_endpoint)
if launch_time_options.ok:
launch_time_options = launch_time_options.json()['actions']['POST']
resource_options_parser.options['LAUNCH'] = launch_time_options
@@ -90,6 +94,48 @@ class JobTemplateLaunch(Launchable, CustomAction):
resource = 'job_templates'
class BulkJobLaunch(Launchable, CustomAction):
action = 'job_launch'
resource = 'bulk'
@property
def options_endpoint(self):
return self.page.endpoint + '{}/'.format(self.action)
def add_arguments(self, parser, resource_options_parser):
Launchable.add_arguments(self, parser, resource_options_parser, with_pk=False)
def perform(self, **kwargs):
monitor_kwargs = {
'monitor': kwargs.pop('monitor', False),
'wait': kwargs.pop('wait', False),
'action_timeout': kwargs.pop('action_timeout', False),
}
response = self.page.get().job_launch.post(kwargs)
self.monitor(response, **monitor_kwargs)
return response
class BulkHostCreate(CustomAction):
action = 'host_create'
resource = 'bulk'
@property
def options_endpoint(self):
return self.page.endpoint + '{}/'.format(self.action)
def add_arguments(self, parser, resource_options_parser):
options = self.page.connection.options(self.options_endpoint)
if options.ok:
options = options.json()['actions']['POST']
resource_options_parser.options['HOSTCREATEPOST'] = options
resource_options_parser.build_query_arguments(self.action, 'HOSTCREATEPOST')
def perform(self, **kwargs):
response = self.page.get().host_create.post(kwargs)
return response
class ProjectUpdate(Launchable, CustomAction):
action = 'update'
resource = 'projects'