diff --git a/tower_cli/resources/inventory_source.py b/tower_cli/resources/inventory_source.py index 2150a6da..c8e047e2 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..4c9f2e89 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, organization, + 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, organization, + 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)