How to use the towerlib.towerlibexceptions.InvalidGroup function in towerlib

To help you get started, we’ve selected a few towerlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github schubergphilis / towerlib / tests / integration / test_towerlib.py View on Github external
with self.assertRaises(InvalidOrganization):
                self.tower.create_inventory_group('DefaultBroken',
                                                  'Demo Inventory',
                                                  'group_name',
                                                  'description')
            with self.assertRaises(InvalidInventory):
                self.tower.create_inventory_group('Default',
                                                  'Demo Inventory Broken',
                                                  'group_name',
                                                  'description')
            self.assertTrue(self.tower.delete_inventory_group('Default', 'Demo Inventory', 'group_name'))
            with self.assertRaises(InvalidOrganization):
                self.tower.delete_inventory_group('DefaultBroken', 'Demo Inventory', 'group_name')
            with self.assertRaises(InvalidInventory):
                self.tower.delete_inventory_group('Default', 'Demo Inventory Broken', 'group_name')
            with self.assertRaises(InvalidGroup):
                self.tower.delete_inventory_group('Default', 'Demo Inventory', 'group_name_broken')
github schubergphilis / towerlib / towerlib / entities / inventory.py View on Github external
def delete_group(self, name):
        """Deletes the group.

        Args:
            name: The name of the group to delete.

        Returns:
            bool: True on success, False otherwise.

        Raises:
            InvalidGroup: The group provided as argument does not exist.

        """
        group = next(self._tower.groups.filter({'inventory': self.id, 'name__iexact': name}), None)
        if not group:
            raise InvalidGroup(name)
        return group.delete()
github schubergphilis / towerlib / towerlib / __init__.py View on Github external
__email__ = ''''''
__status__ = '''Development'''  # "Prototype", "Development", "Production".

# This is to 'use' the module(s), so lint doesn't complain
assert __version__

# assert exceptions
assert AuthFailed
assert InvalidUserLevel
assert InvalidOrganization
assert InvalidVariables
assert InvalidInventory
assert InvalidUser
assert InvalidTeam
assert InvalidCredential
assert InvalidGroup
assert InvalidHost
assert InvalidProject
assert InvalidCredentialType
assert InvalidPlaybook
assert InvalidInstanceGroup
assert InvalidJobType
assert InvalidVerbosity
assert InvalidJobTemplate
assert PermissionNotFound
assert InvalidValue
assert InvalidRole

# assert objects
assert Tower
assert Organization
assert User
github schubergphilis / towerlib / towerlib / towerlib.py View on Github external
Args:
            organization: The organization the inventory belongs to.
            inventory: The name of the inventory to retrieve the group from.
            name: The name of the group to delete.

        Returns:
            bool: True on success, False otherwise.

        Raises:
            InvalidGroup: The group provided as argument does not exist.

        """
        group = self.get_inventory_group_by_name(organization, inventory, name)
        if not group:
            raise InvalidGroup(name)
        return group.delete()
github schubergphilis / towerlib / towerlib / entities / group.py View on Github external
def associate_group_by_name(self, name):
        """Associate a group to the group by name.

        Args:
            name: The name of the group to associate with the group.

        Returns:
            bool: True on success, False otherwise.

        Raises:
            InvalidGroup: The group provided as argument does not exist.

        """
        group = self.inventory.get_group_by_name(name)
        if not group:
            raise InvalidGroup(name)
        return self._associate_group_by_id(group.id)
github schubergphilis / towerlib / towerlib / entities / host.py View on Github external
Returns:
            bool: True on complete success, False otherwise.

        Raises:
            InvalidGroup: The group provided as argument does not exist.

        """
        if not isinstance(groups, (list, tuple)):
            groups = [groups]
        inventory_groups = [group for group in self.inventory.groups]
        lower_inventory_group_names = [
            group.name.lower() for group in inventory_groups]
        missing_groups = [group_name for group_name in groups
                          if group_name.lower() not in lower_inventory_group_names]
        if missing_groups:
            raise InvalidGroup(missing_groups)
        lower_group_names = [name.lower() for name in groups]
        final_groups = [group for group in inventory_groups
                        if group.name.lower() in lower_group_names]
        return all([group._add_host_by_id(self.id)  # pylint: disable=protected-access
                    for group in final_groups])
github schubergphilis / towerlib / towerlib / entities / group.py View on Github external
def disassociate_group_by_name(self, name):
        """Disassociate a group from the group.

        Args:
            name: The name of the group to disassociate.

        Returns:
            bool: True on success, False otherwise.

        Raises:
            InvalidGroup: The group provided as argument does not exist.

        """
        group = self.inventory.get_group_by_name(name)
        if not group:
            raise InvalidGroup(name)
        return self._disassociate_group_by_id(group.id)
github schubergphilis / towerlib / towerlib / entities / host.py View on Github external
groups: The group name(s) to disassociate the host from.
            Accepts a single group string or a list or tuple of groups.

        Returns:
            bool: True on complete success, False otherwise.

        Raises:
            InvalidGroup: The group provided as argument does not exist.

        """
        if not isinstance(groups, (list, tuple)):
            groups = [groups]
        missing_groups = [group_name for group_name in groups
                          if group_name not in self.groups]
        if missing_groups:
            raise InvalidGroup(missing_groups)
        lower_group_names = [name.lower() for name in groups]
        inventory_groups = [group for group in self.inventory.groups
                            if group.name.lower() in lower_group_names]
        return all([group._remove_host_by_id(self.id)  # pylint: disable=protected-access
                    for group in inventory_groups])