mirror of
https://github.com/ansible/awx.git
synced 2026-03-21 10:57:36 -02:30
In python3, we can use the built-in suppress from contextlib https://docs.python.org/3/library/contextlib.html#contextlib.suppress
18 lines
614 B
Python
18 lines
614 B
Python
from contextlib import suppress
|
|
|
|
import awxkit.exceptions as exc
|
|
|
|
|
|
class HasInstanceGroups(object):
|
|
def add_instance_group(self, instance_group):
|
|
with suppress(exc.NoContent):
|
|
self.related['instance_groups'].post(dict(id=instance_group.id))
|
|
|
|
def remove_instance_group(self, instance_group):
|
|
with suppress(exc.NoContent):
|
|
self.related['instance_groups'].post(dict(id=instance_group.id, disassociate=instance_group.id))
|
|
|
|
def remove_all_instance_groups(self):
|
|
for ig in self.related.instance_groups.get().results:
|
|
self.remove_instance_group(ig)
|