Returns an ancestor of this group given a generation (up to the DC).

        :param generation: Determines how far up the path to go. Example: 0 = self, 1 = parent, 2 = grandparent ...
        :type generation: int

def ancestor(self, generation):
        """ Returns an ancestor of this group given a generation (up to the DC).

        :param generation: Determines how far up the path to go. Example: 0 = self, 1 = parent, 2 = grandparent ...
        :type generation: int

        """

        # Don't go below the current generation and don't go above the DC
        if generation < 1:
            return self
        else:
            ancestor_dn = self.group_dn

            for _index in range(generation):
                if ''.join(ancestor_dn.split("DC")[0].split()) == '':
                    break
                else:
                    ancestor_dn = ancestor_dn.split(",", 1).pop()

            return ADGroup(
                group_dn=ancestor_dn, server_uri=self.server_uri, base_dn=self.base_dn,
                user_lookup_attr=self.user_lookup_attr, group_lookup_attr=self.group_lookup_attr,
                attr_list=self.attr_list, bind_dn=self.bind_dn, bind_password=self.bind_password,
                user_search_base_dn=self.user_search_base_dn, group_search_base_dn=self.user_search_base_dn
            )