Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #700 from jainnikhil30/master
Browse files Browse the repository at this point in the history
enable notifier on org, project and inventory sources
  • Loading branch information
AlanCoding authored Jul 9, 2019
2 parents 5363e79 + 410edf0 commit 8a020e8
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 1 deletion.
56 changes: 56 additions & 0 deletions tower_cli/resources/inventory_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
61 changes: 60 additions & 1 deletion tower_cli/resources/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
58 changes: 58 additions & 0 deletions tower_cli/resources/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 8a020e8

Please sign in to comment.