Saltstack Official Linux Formula
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

31 行
707B

  1. # -*- coding: utf-8 -*-
  2. '''
  3. Module for defining new filter for sorting
  4. host names/alias by FQDN first and alphabetically
  5. '''
  6. from jinja2 import Undefined
  7. def __virtual__():
  8. return 'linux_hosts'
  9. def fqdn_sort_fn(n1, n2):
  10. l1 = n1.split('.')
  11. l2 = n2.split('.')
  12. if len(l1) > len(l2):
  13. return -1
  14. if len(l1) < len(l2):
  15. return 1
  16. for i1, i2 in zip(l1, l2):
  17. if i1 < i2:
  18. return -1
  19. if i1 > i2:
  20. return 1
  21. return 0
  22. def fqdn_sort_filter(iterable):
  23. if iterable is None or isinstance(iterable, Undefined):
  24. return iterable
  25. # Do effective custom sorting of iterable here
  26. return sorted(set(iterable), cmp=fqdn_sort_fn)