예제 #1
0
    def test_04_group_add(self):
        """Check group addition
        """

        inventory = AnsibleInventory(INV_FILENAME, excl=True)
        inventory.group_add('newgroup')
        self.assertIn('newgroup', inventory.groups)
예제 #2
0
    def test_08_host_add(self):
        """add a host to an existent group
        """
        inventory = AnsibleInventory(INV_FILENAME, excl=True)
        inventory.group_add('mygroup')
        self.assertIn('mygroup', inventory.groups)

        # two write operations not supported..
        # Needed another AnsibleInventary Object
        inventory = AnsibleInventory(INV_FILENAME, excl=True)
        inventory.host_add('mygroup', 'myhost')
        self.assertIn('myhost', inventory.group_show('mygroup'))
예제 #3
0
    def test_05_group_remove(self):
        """Check remove a group that exists
        """

        inventory = AnsibleInventory(INV_FILENAME, excl=True)
        inventory.group_add('newgroup')
        self.assertIn('newgroup', inventory.groups)

        # two write operations not supported..
        # Needed another AnsibleInventary Object
        inventory = AnsibleInventory(INV_FILENAME, excl=True)
        inventory.group_remove('newgroup')
        self.assertNotIn('newgroup', inventory.groups)
예제 #4
0
def add_group(group_name):
    r = APIResponse()
    inventory = AnsibleInventory(excl=True)
    if inventory.loaded:
        try:
            inventory.group_add(group_name)
        except InventoryGroupExists:
            r.status, r.msg = 'OK', 'Group already exists'
        else:
            r.status, r.msg = 'OK', 'Group {} added'.format(group_name)

        return r
    else:
        r.status, r.msg = 'LOCKED', 'Unable to lock the inventory file'
        return r
예제 #5
0
    def test_11_remove_nonempty(self):
        """remove a group with hosts
        """

        inventory = AnsibleInventory(INV_FILENAME, excl=True)
        inventory.group_add('mygroup')
        self.assertIn('mygroup', inventory.groups)

        # two write operations not supported..
        # Needed another AnsibleInventary Object
        inventory = AnsibleInventory(INV_FILENAME, excl=True)
        inventory.host_add('mygroup', 'myhost')
        self.assertIn('myhost', inventory.group_show('mygroup'))

        # two write operations not supported..
        # Needed another AnsibleInventary Object
        inventory = AnsibleInventory(INV_FILENAME, excl=True)
        inventory.group_remove('mygroup')
        self.assertNotIn('mygroup', inventory.groups)
예제 #6
0
def add_group(group_name):
    r = APIResponse()

    reserved_group_names = ['all']
    if group_name in reserved_group_names:
        r.status, r.msg = "INVALID", \
                          "Group name '{}' is a reserved/system group " \
                          "name".format(group_name)
        return r

    inventory = AnsibleInventory(excl=True)
    if inventory.loaded:
        try:
            inventory.group_add(group_name)
        except InventoryGroupExists:
            r.status, r.msg = 'OK', 'Group already exists'
        else:
            r.status, r.msg = 'OK', 'Group {} added'.format(group_name)

        return r
    else:
        r.status, r.msg = 'LOCKED', 'Unable to lock the inventory file'
        return r