How to use the towerlib.towerlibexceptions.InvalidHost 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
'Test Inventory',
                                                    'host_name',
                                                    'description2',
                                                    '{}')
            with self.assertRaises(InvalidInventory):
                self.tower.create_host_in_inventory('workflow',
                                                    'Test Inventory broken',
                                                    'host_name',
                                                    'description2',
                                                    '{}')
            self.assertTrue(self.tower.delete_inventory_host('workflow', 'Test Inventory', 'host_name'))
            with self.assertRaises(InvalidOrganization):
                self.tower.delete_inventory_host('workflowBroken', 'Test Inventory', 'host_name')
            with self.assertRaises(InvalidInventory):
                self.tower.delete_inventory_host('workflow', 'Test Inventory Broken', 'host_name')
            with self.assertRaises(InvalidHost):
                self.tower.delete_inventory_host('workflow', 'Test Inventory', 'host_name')
github schubergphilis / towerlib / tests / integration / test_towerlib.py View on Github external
def test_host_lifecycle(self):
        with self.recorder:
            host = self.tower.create_host_in_inventory('workflow',
                                                       'Test Inventory',
                                                       'host_name',
                                                       'description',
                                                       '{}')
            self.assertIsInstance(host, Host)
            duplicate_host = self.tower.create_host_in_inventory('workflow',
                                                                 'Test Inventory',
                                                                 'host_name',
                                                                 'description2',
                                                                 '{}')
            self.assertFalse(duplicate_host)
            with self.assertRaises(InvalidHost):
                self.tower.associate_groups_with_inventory_host('workflow',
                                                                'Test Inventory',
                                                                'host_nameBroken',
                                                                'Test Group')
            self.assertTrue(self.tower.associate_groups_with_inventory_host('workflow',
                                                                            'Test Inventory',
                                                                            'host_name',
                                                                            'Test Group'))
            self.assertTrue(self.tower.disassociate_groups_from_inventory_host('workflow',
                                                                               'Test Inventory',
                                                                               'host_name',
                                                                               'Test Group'))
            with self.assertRaises(InvalidHost):
                self.tower.disassociate_groups_from_inventory_host('workflow',
                                                                   'Test Inventory',
                                                                   'host_nameBroken',
github schubergphilis / towerlib / towerlib / towerlib.py View on Github external
Args:
            organization: The name of the organization the inventory belongs to.
            inventory: The inventory to retrieve the host from.
            hostname: The name of the host to add the groups to.
            groups: A string of a single group or a list or tuple of group names to add to host.

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

        Raises:
            InvalidHost: The host provided as argument does not exist.

        """
        host = self.get_inventory_host_by_name(organization, inventory, hostname)
        if not host:
            raise InvalidHost(hostname)
        return host.associate_with_groups(groups)
github schubergphilis / towerlib / towerlib / towerlib.py View on Github external
Args:
            organization: The name of the organization the inventory belongs to.
            inventory: The inventory which contains the host to affect.
            hostname: The name of the host to remove the groups from.
            groups: A string of a single group or a list or tuple of group names to remove from a host.

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

        Raises:
            InvalidHost: The host provided as argument does not exist.

        """
        host = self.get_inventory_host_by_name(organization, inventory, hostname)
        if not host:
            raise InvalidHost(hostname)
        return host.disassociate_with_groups(groups)
github schubergphilis / towerlib / towerlib / entities / group.py View on Github external
def remove_host_by_name(self, name):
        """Removes a host from the group.

        Args:
            name: The name of the host to remove.

        Returns:
            bool: True on success, False otherwise.

        Raises:
            InvalidHost: The host provided as argument does not exist.

        """
        host = self.inventory.get_host_by_name(name)
        if not host:
            raise InvalidHost(name)
        return self._remove_host_by_id(host.id)
github schubergphilis / towerlib / towerlib / __init__.py View on Github external
__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
assert Role
github schubergphilis / towerlib / towerlib / towerlib.py View on Github external
Args:
            organization: The name of the organization the inventory belongs to.
            inventory: The name of the inventory to delete the host from.
            name: The name of the host to delete.

        Returns:
            bool: True on success, False otherwise.

        Raises:
            InvalidHost: The host provided as argument does not exist.

        """
        host = self.get_inventory_host_by_name(organization, inventory, name)
        if not host:
            raise InvalidHost(name)
        return host.delete()
github schubergphilis / towerlib / towerlib / entities / inventory.py View on Github external
def delete_host(self, name):
        """Deletes the host.

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

        Returns:
            bool: True on success, False otherwise.

        Raises:
            InvalidHost: The host provided as argument does not exist.

        """
        host = next(self._tower.hosts.filter({'inventory': self.id, 'name__iexact': name}), None)
        if not host:
            raise InvalidHost(name)
        return host.delete()
github schubergphilis / towerlib / towerlib / entities / group.py View on Github external
def add_host_by_name(self, name):
        """Add a host to the group by name.

        Args:
            name: The name of the host to add to the group.

        Returns:
            bool: True on success, False otherwise.

        Raises:
            InvalidHost: The host provided as argument does not exist.

        """
        host = self.inventory.get_host_by_name(name)
        if not host:
            raise InvalidHost(name)
        return self._add_host_by_id(host.id)