How to use the towerlib.towerlibexceptions.InvalidInventory 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_team.py View on Github external
with self.assertRaises(InvalidInventory):
                self.team.add_inventory_permission_admin(inventory_broken)
            self.assertTrue(self.team.add_inventory_permission_admin(inventory))
            with self.assertRaises(InvalidInventory):
                self.team.remove_inventory_permission_admin(inventory_broken)
            self.assertTrue(self.team.remove_inventory_permission_admin(inventory))
            with self.assertRaises(InvalidInventory):
                self.team.add_inventory_permission_use(inventory_broken)
            self.assertTrue(self.team.add_inventory_permission_use(inventory))
            with self.assertRaises(InvalidInventory):
                self.team.remove_inventory_permission_use(inventory_broken)
            self.assertTrue(self.team.remove_inventory_permission_use(inventory))
            with self.assertRaises(InvalidInventory):
                self.team.add_inventory_permission_update(inventory_broken)
            self.assertTrue(self.team.add_inventory_permission_update(inventory))
            with self.assertRaises(InvalidInventory):
                self.team.remove_inventory_permission_update(inventory_broken)
            self.assertTrue(self.team.remove_inventory_permission_update(inventory))
            with self.assertRaises(InvalidInventory):
                self.team.add_inventory_permission_ad_hoc(inventory_broken)
            self.assertTrue(self.team.add_inventory_permission_ad_hoc(inventory))
            with self.assertRaises(InvalidInventory):
                self.team.remove_inventory_permission_ad_hoc(inventory_broken)
            self.assertTrue(self.team.remove_inventory_permission_ad_hoc(inventory))
github schubergphilis / towerlib / tests / integration / test_team.py View on Github external
def test_mutating_inventory(self):
        with self.recorder:
            inventory = 'Test Inventory'
            inventory_broken = 'Test InventoryBroken'
            with self.assertRaises(InvalidInventory):
                self.team.add_inventory_permission_admin(inventory_broken)
            self.assertTrue(self.team.add_inventory_permission_admin(inventory))
            with self.assertRaises(InvalidInventory):
                self.team.remove_inventory_permission_admin(inventory_broken)
            self.assertTrue(self.team.remove_inventory_permission_admin(inventory))
            with self.assertRaises(InvalidInventory):
                self.team.add_inventory_permission_use(inventory_broken)
            self.assertTrue(self.team.add_inventory_permission_use(inventory))
            with self.assertRaises(InvalidInventory):
                self.team.remove_inventory_permission_use(inventory_broken)
            self.assertTrue(self.team.remove_inventory_permission_use(inventory))
            with self.assertRaises(InvalidInventory):
                self.team.add_inventory_permission_update(inventory_broken)
            self.assertTrue(self.team.add_inventory_permission_update(inventory))
            with self.assertRaises(InvalidInventory):
                self.team.remove_inventory_permission_update(inventory_broken)
github schubergphilis / towerlib / tests / integration / test_towerlib.py View on Github external
group = self.tower.create_inventory_group('Default',
                                                      'Demo Inventory',
                                                      'group_name',
                                                      'description')
            self.assertIsInstance(group, Group)
            duplicate_group = self.tower.create_inventory_group('Default',
                                                                'Demo Inventory',
                                                                'group_name',
                                                                'description2')
            self.assertFalse(duplicate_group)
            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 / tests / integration / test_towerlib.py View on Github external
use_fact_cache=False,
                         ask_diff_mode_on_launch=False,
                         ask_variables_on_launch=False,
                         ask_limit_on_launch=False,
                         ask_tags_on_launch=False,
                         ask_skip_tags_on_launch=False,
                         ask_job_type_on_launch=False,
                         ask_verbosity_on_launch=False,
                         ask_inventory_on_launch=False,
                         ask_credential_on_launch=False,
                         survey_enabled=False,
                         become_enabled=False,
                         diff_mode=False,
                         allow_simultaneous=False)
        with self.recorder:
            with self.assertRaises(InvalidInventory):
                args = copy.deepcopy(arguments)
                args['inventory'] = 'Broken'
                _ = self.tower.create_job_template(**args)
            with self.assertRaises(InvalidProject):
                args = copy.deepcopy(arguments)
                args['project'] = 'Broken'
                _ = self.tower.create_job_template(**args)
            with self.assertRaises(InvalidPlaybook):
                args = copy.deepcopy(arguments)
                args['playbook'] = 'Broken'
                _ = self.tower.create_job_template(**args)
            with self.assertRaises(InvalidCredential):
                args = copy.deepcopy(arguments)
                args['credential'] = 'Broken'
                _ = self.tower.create_job_template(**args)
            with self.assertRaises(InvalidInstanceGroup):
github schubergphilis / towerlib / towerlib / towerlib.py View on Github external
def get_inventory_host_by_name(self, organization, inventory, name):
        """Retrieves a host by name from an inventory.

        Args:
            organization: The name of the organization the inventory belongs to.
            inventory: The name of the inventory to search for a host.
            name: The name of the host to retrieve.

        Returns:
            Host: The host if a match is found else None.

        """
        inventory_ = self.get_organization_inventory_by_name(organization, inventory)
        if not inventory_:
            raise InvalidInventory(inventory)
        return inventory_.get_host_by_name(name)
github schubergphilis / towerlib / towerlib / towerlib.py View on Github external
"""Deletes an inventory from tower.

        Args:
            organization: The organization the inventory is a member of.
            name: The name of the inventory to delete.

        Returns:
            bool: True on success, False otherwise.

        Raises:
            InvalidInventory: The inventory provided as argument does not exist.

        """
        inventory = self.get_organization_inventory_by_name(organization, name)
        if not inventory:
            raise InvalidInventory(name)
        return inventory.delete()
github schubergphilis / towerlib / towerlib / towerlib.py View on Github external
name: The name of the group to retrieve.

        Returns:
            Group: The group if a match is found else None.

        Raises:
            InvalidOrganization: The organisation provided as an argument does not exist.
            InvalidInventory: The inventory name provided as an argument does not exist.

        """
        organization_ = self.get_organization_by_name(organization)
        if not organization_:
            raise InvalidOrganization(organization_)
        inventory_ = organization_.get_inventory_by_name(inventory)
        if not inventory_:
            raise InvalidInventory(inventory_)
        return inventory_.get_group_by_name(name)
github schubergphilis / towerlib / towerlib / towerlib.py View on Github external
organization: The name of the organization the inventory belongs to.
            inventory: The name of the inventory to create the host under.
            name: The name of the host.
            description: The description of the host.
            variables: A json of the variables to be set on the host.

        Returns:
            Host: The created host on success, None otherwise.

        Raises:
            InvalidInventory: The inventory provided as argument does not exist.

        """
        inventory_ = self.get_organization_inventory_by_name(organization, inventory)
        if not inventory_:
            raise InvalidInventory(inventory)
        return inventory_.create_host(name, description, variables)
github schubergphilis / towerlib / towerlib / entities / team.py View on Github external
def _post_inventory_permission(self, inventory_name, permission_name, remove=False):
        inventory = self.organization.get_inventory_by_name(inventory_name)
        if not inventory:
            raise InvalidInventory(inventory_name)
        return self._post_permission(inventory.object_roles, permission_name, remove)