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

82 行
2.3KB

  1. # -*- coding: utf-8 -*-
  2. '''
  3. Management of Open vSwitch configuration
  4. ========================================
  5. The OVS config can be managed with the ovs_config state module:
  6. .. code-block:: yaml
  7. other_config:dpdk-init:
  8. ovs_config.present:
  9. - value: True
  10. other_config:dpdk-extra:
  11. ovs_config.present:
  12. - value: -n 12 --vhost-owner libvirt-qemu:kvm --vhost-perm 0664
  13. external_ids:
  14. ovs_config.absent
  15. '''
  16. def __virtual__():
  17. '''
  18. Only make these states available if Open vSwitch is installed.
  19. '''
  20. return 'ovs_config.list' in __salt__
  21. def present(name, value, wait=True):
  22. '''
  23. Ensures that the named config exists, eventually creates it.
  24. Args:
  25. name/value: The name/value of the config entry.
  26. wait: Whether wait for ovs-vswitchd to reconfigure itself according to the modified database.
  27. '''
  28. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  29. ovs_config = __salt__['ovs_config.list']()
  30. if name in ovs_config and ovs_config[name] == str(value).lower():
  31. ret['result'] = True
  32. ret['comment'] = '{0} is already set to {1}.'.format(name, value)
  33. else:
  34. config_updated = __salt__['ovs_config.set'](name, value, wait)
  35. if config_updated:
  36. ret['result'] = True
  37. ret['comment'] = '{0} is updated.'.format(name)
  38. ret['changes'] = { name: 'Updated to {0}'.format(value) }
  39. else:
  40. ret['result'] = False
  41. ret['comment'] = 'Unable to update config of {0}.'.format(name)
  42. return ret
  43. def absent(name):
  44. '''
  45. Ensures that the named config does not exist, eventually deletes it.
  46. Args:
  47. name: The name of the config entry.
  48. '''
  49. ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
  50. ovs_config = __salt__['ovs_config.list']()
  51. if ':' in name and name not in ovs_config:
  52. ret['result'] = True
  53. ret['comment'] = '{0} does not exist.'.format(name)
  54. else:
  55. config_removed = __salt__['ovs_config.remove'](name)
  56. if config_removed:
  57. ret['result'] = True
  58. ret['comment'] = '{0} is removed.'.format(name)
  59. ret['changes'] = { name: '{0} removed'.format(name) }
  60. else:
  61. ret['result'] = False
  62. ret['comment'] = 'Unable to delete config of {0}.'.format(name)
  63. return ret