From 8068a6e9415060f917bf489d4998ededb0d655cd Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Apr 2019 19:06:52 +0530 Subject: [PATCH 1/2] enable notifier on org, project and inventory sources --- tower_cli/resources/inventory_source.py | 56 +++++++++++++++++++++++ tower_cli/resources/organization.py | 61 ++++++++++++++++++++++++- tower_cli/resources/project.py | 58 +++++++++++++++++++++++ 3 files changed, 174 insertions(+), 1 deletion(-) diff --git a/tower_cli/resources/inventory_source.py b/tower_cli/resources/inventory_source.py index 2150a6da..2a3cd098 100644 --- a/tower_cli/resources/inventory_source.py +++ b/tower_cli/resources/inventory_source.py @@ -158,3 +158,59 @@ def status(self, pk, detail=False, **kwargs): 'failed': job['failed'], 'status': job['status'], } + + @resources.command(use_fields_as_options=False) + @click.option('--inventory_source', type=types.Related('inventory_source')) + @click.option('--notification-template', + type=types.Related('notification_template')) + @click.option('--status', type=click.Choice(['any', 'error', 'success']), + required=False, default='any', help='Specify job run status' + ' of inventory_sync to relate to.') + def associate_notification_template(self, inventory_source, + notification_template, status): + """Associate a notification template from this inventory source. + + =====API DOCS===== + Associate a notification template from this inventory source. + + :param inventory_source: The inventory source to associate to. + :type inventory_source: str + :param notification_template: The notification template to be associated. + :type notification_template: str + :param status: type of notification this notification template should be associated to. + :type status: str + :returns: Dictionary of only one key "changed", which indicates whether the association succeeded. + :rtype: dict + + =====API DOCS===== + """ + return self._assoc('notification_templates_%s' % status, + inventory_source, notification_template) + + @resources.command(use_fields_as_options=False) + @click.option('--inventory_source', type=types.Related('inventory_source')) + @click.option('--notification-template', + type=types.Related('notification_template')) + @click.option('--status', type=click.Choice(['any', 'error', 'success']), + required=False, default='any', help='Specify job run status' + ' of inventory_sync to relate to.') + def disassociate_notification_template(self, inventory_source, + notification_template, status): + """Disassociate a notification template from this inventory source. + + =====API DOCS===== + Disassociate a notification template from this inventory source. + + :param inventory_source: The inventory source to disassociate from. + :type inventory_source: str + :param notification_template: The notification template to be disassociated. + :type notification_template: str + :param status: type of notification this notification template should be disassociated from. + :type status: str + :returns: Dictionary of only one key "changed", which indicates whether the disassociation succeeded. + :rtype: dict + + =====API DOCS===== + """ + return self._disassoc('notification_templates_%s' % status, + inventory_source, notification_template) diff --git a/tower_cli/resources/organization.py b/tower_cli/resources/organization.py index 73e13fdf..8a464413 100644 --- a/tower_cli/resources/organization.py +++ b/tower_cli/resources/organization.py @@ -13,7 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from tower_cli import models +import click + +from tower_cli import models, resources +from tower_cli.cli import types class Resource(models.Resource): @@ -27,3 +30,59 @@ class Resource(models.Resource): admins = models.ManyToManyField('user', method_name='admin') instance_groups = models.ManyToManyField('instance_group', method_name='ig') custom_virtualenv = models.Field(required=False, display=False) + + @resources.command(use_fields_as_options=False) + @click.option('--organization', type=types.Related('organization')) + @click.option('--notification-template', + type=types.Related('notification_template')) + @click.option('--status', type=click.Choice(['any', 'error', 'success']), + required=False, default='any', help='Specify job run status' + ' of inventory_sync to relate to.') + def associate_notification_template(self, inventory_source, + notification_template, status): + """Associate a notification template from this organization. + + =====API DOCS===== + Associate a notification template from this organization. + + :param organization: The organization to associate to. + :type organization: str + :param notification_template: The notification template to be associated. + :type notification_template: str + :param status: type of notification this notification template should be associated to. + :type status: str + :returns: Dictionary of only one key "changed", which indicates whether the association succeeded. + :rtype: dict + + =====API DOCS===== + """ + return self._assoc('notification_templates_%s' % status, + organization, notification_template) + + @resources.command(use_fields_as_options=False) + @click.option('--organization', type=types.Related('organization')) + @click.option('--notification-template', + type=types.Related('notification_template')) + @click.option('--status', type=click.Choice(['any', 'error', 'success']), + required=False, default='any', help='Specify job run status' + ' of inventory_sync to relate to.') + def disassociate_notification_template(self, inventory_source, + notification_template, status): + """Disassociate a notification template from this organization. + + =====API DOCS===== + Disassociate a notification template from this organization. + + :param organization: The organization to disassociate from. + :type organization: str + :param notification_template: The notification template to be disassociated. + :type notification_template: str + :param status: type of notification this notification template should be disassociated from. + :type status: str + :returns: Dictionary of only one key "changed", which indicates whether the disassociation succeeded. + :rtype: dict + + =====API DOCS===== + """ + return self._disassoc('notification_templates_%s' % status, + organization, notification_template) diff --git a/tower_cli/resources/project.py b/tower_cli/resources/project.py index 0df18ef2..8f23f709 100644 --- a/tower_cli/resources/project.py +++ b/tower_cli/resources/project.py @@ -301,3 +301,61 @@ def status(self, pk=None, detail=False, **kwargs): 'failed': job['failed'], 'status': job['status'], } + + @resources.command(use_fields_as_options=False) + @click.option('--project', type=types.Related('project')) + @click.option('--notification-template', + type=types.Related('notification_template')) + @click.option('--status', type=click.Choice(['any', 'error', 'success']), + required=False, default='any', help='Specify job run status' + ' of all the job templates based on this project' + ' to relate to.') + def associate_notification_template(self, project, + notification_template, status): + """Associate a notification template from this project. + + =====API DOCS===== + Associate a notification template from this project. + + :param project: The project to associate to. + :type project: str + :param notification_template: The notification template to be associated. + :type notification_template: str + :param status: type of notification this notification template should be associated to. + :type status: str + :returns: Dictionary of only one key "changed", which indicates whether the association succeeded. + :rtype: dict + + =====API DOCS===== + """ + return self._assoc('notification_templates_%s' % status, + project, notification_template) + + @resources.command(use_fields_as_options=False) + @click.option('--project', type=types.Related('project')) + @click.option('--notification-template', + type=types.Related('notification_template')) + @click.option('--status', type=click.Choice(['any', 'error', 'success']), + required=False, default='any', help='Specify job run status' + ' of all the job templates based on this project' + ' to relate to.') + def disassociate_notification_template(self, project, + notification_template, status): + """Disassociate a notification template from this project. + + =====API DOCS===== + Disassociate a notification template from this project. + + :param project: The job template to disassociate from. + :type project: str + :param notification_template: The notification template to be disassociated. + :type notification_template: str + :param status: type of notification this notification template should be disassociated from. + :type status: str + :returns: Dictionary of only one key "changed", which indicates whether the disassociation succeeded. + :rtype: dict + + =====API DOCS===== + """ + return self._disassoc('notification_templates_%s' % status, + project, notification_template) From 410edf0698eeb47c6b73e9a3f54b8c087cef6a35 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Apr 2019 19:47:59 +0530 Subject: [PATCH 2/2] remove blank space and correct the parameter --- tower_cli/resources/inventory_source.py | 2 +- tower_cli/resources/organization.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tower_cli/resources/inventory_source.py b/tower_cli/resources/inventory_source.py index 2a3cd098..c8e047e2 100644 --- a/tower_cli/resources/inventory_source.py +++ b/tower_cli/resources/inventory_source.py @@ -158,7 +158,7 @@ def status(self, pk, detail=False, **kwargs): 'failed': job['failed'], 'status': job['status'], } - + @resources.command(use_fields_as_options=False) @click.option('--inventory_source', type=types.Related('inventory_source')) @click.option('--notification-template', diff --git a/tower_cli/resources/organization.py b/tower_cli/resources/organization.py index 8a464413..4c9f2e89 100644 --- a/tower_cli/resources/organization.py +++ b/tower_cli/resources/organization.py @@ -38,7 +38,7 @@ class Resource(models.Resource): @click.option('--status', type=click.Choice(['any', 'error', 'success']), required=False, default='any', help='Specify job run status' ' of inventory_sync to relate to.') - def associate_notification_template(self, inventory_source, + def associate_notification_template(self, organization, notification_template, status): """Associate a notification template from this organization. @@ -66,7 +66,7 @@ def associate_notification_template(self, inventory_source, @click.option('--status', type=click.Choice(['any', 'error', 'success']), required=False, default='any', help='Specify job run status' ' of inventory_sync to relate to.') - def disassociate_notification_template(self, inventory_source, + def disassociate_notification_template(self, organization, notification_template, status): """Disassociate a notification template from this organization.