mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #3140 from shadowfax-chc/layman-state
Added state for layman.
This commit is contained in:
commit
ad9f94a770
@ -20,6 +20,7 @@ Full list of builtin state modules
|
||||
hg
|
||||
host
|
||||
kmod
|
||||
layman
|
||||
module
|
||||
mongodb_database
|
||||
mongodb_user
|
||||
|
6
doc/ref/states/all/salt.states.layman.rst
Normal file
6
doc/ref/states/all/salt.states.layman.rst
Normal file
@ -0,0 +1,6 @@
|
||||
==================
|
||||
salt.states.layman
|
||||
==================
|
||||
|
||||
.. automodule:: salt.states.layman
|
||||
:members:
|
81
salt/states/layman.py
Normal file
81
salt/states/layman.py
Normal file
@ -0,0 +1,81 @@
|
||||
'''
|
||||
Mangement of Gentoo Overlays using layman
|
||||
=========================================
|
||||
|
||||
A state module to manage Gentoo package overlays via layman
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
sunrise:
|
||||
layman.present
|
||||
'''
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Only load if the layman module is available in __salt__
|
||||
'''
|
||||
return 'layman' if 'layman.add' in __salt__ else False
|
||||
|
||||
def present(name):
|
||||
'''
|
||||
Verify that the overlay is present
|
||||
|
||||
name
|
||||
The name of the overlay to add
|
||||
'''
|
||||
ret = {'changes': {},
|
||||
'comment': '',
|
||||
'name': name,
|
||||
'result': True}
|
||||
|
||||
# Overlay already present
|
||||
if name in __salt__['layman.list_local']():
|
||||
ret['comment'] = 'Overlay {0} already present'.format(name)
|
||||
elif __opts__['test']:
|
||||
ret['comment'] = 'Overlay {0} is set to be added'.format(name)
|
||||
else:
|
||||
# Attempt to add the overlay
|
||||
changes = __salt__['layman.add'](name)
|
||||
|
||||
# The overlay failed to add
|
||||
if len(changes) < 1:
|
||||
ret['comment'] = 'Overlay {0} failed to add'.format(name)
|
||||
ret['result'] = False
|
||||
# Sucess
|
||||
else:
|
||||
ret['changes']['added'] = changes
|
||||
ret['comment'] = 'Overlay {0} added.'.format(name)
|
||||
|
||||
return ret
|
||||
|
||||
def absent(name):
|
||||
'''
|
||||
Verify that the overlay is absent
|
||||
|
||||
name
|
||||
The name of the overlay to delete
|
||||
'''
|
||||
ret = {'changes': {},
|
||||
'comment': '',
|
||||
'name': name,
|
||||
'result': True}
|
||||
|
||||
# Overlay is already absent
|
||||
if name not in __salt__['layman.list_local']():
|
||||
ret['comment'] = 'Overlay {0} already absent'.format(name)
|
||||
elif __opts__['test']:
|
||||
ret['comment'] = 'Overlay {0} is set to be deleted'.format(name)
|
||||
else:
|
||||
# Attempt to delete the overlay
|
||||
changes = __salt__['layman.delete'](name)
|
||||
|
||||
# The overlay failed to delete
|
||||
if len(changes) < 1:
|
||||
ret['comment'] = 'Overlay {0} failed to delete'.format(name)
|
||||
ret['result'] = False
|
||||
# Sucess
|
||||
else:
|
||||
ret['changes']['deleted'] = changes
|
||||
ret['comment'] = 'Overlay {0} deleted.'.format(name)
|
||||
|
||||
return ret
|
Loading…
Reference in New Issue
Block a user