mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Merge pull request #1943 from conceptho/state-pecl
Adding pecl state and module
This commit is contained in:
commit
61dcc0d43c
1
AUTHORS
1
AUTHORS
@ -44,6 +44,7 @@ Jeffrey C. Ollie <jeff@ocjtech.us>
|
||||
Jeff Schroeder <jeffschroeder@computer.org>
|
||||
Jonas Buckner <buckner.jonas@gmail.com>
|
||||
Joseph Hall <perlhoser@gmail.com>
|
||||
Josmar Dias <josmarnet@gmail.com>
|
||||
Kent Tenney <ktenney@gmail.com>
|
||||
Marc Abramowitz <marc+github@marc-abramowitz.com>
|
||||
Markus Gattol <markus.gattol@sunoano.org>
|
||||
|
73
salt/modules/pecl.py
Normal file
73
salt/modules/pecl.py
Normal file
@ -0,0 +1,73 @@
|
||||
'''
|
||||
Manage PHP pecl extensions.
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
import re
|
||||
|
||||
|
||||
__opts__ = {}
|
||||
__pillar__ = {}
|
||||
|
||||
def _pecl(command):
|
||||
cmdline = 'pecl {0}'.format(command)
|
||||
|
||||
ret = __salt__['cmd.run_all'](cmdline)
|
||||
|
||||
if ret['retcode'] == 0:
|
||||
return ret['stdout']
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def install(pecls):
|
||||
'''
|
||||
Installs one or several pecl extensions.
|
||||
|
||||
pecls
|
||||
The pecl extensions to install.
|
||||
'''
|
||||
return _pecl('install {0}'.format(pecls))
|
||||
|
||||
|
||||
def uninstall(pecls):
|
||||
'''
|
||||
Uninstall one or several pecl extensions.
|
||||
|
||||
gems
|
||||
The pecl extensions to uninstall.
|
||||
'''
|
||||
return _pecl('uninstall {0}'.format(pecls))
|
||||
|
||||
|
||||
def update(pecls):
|
||||
'''
|
||||
Update one or several pecl exntesions.
|
||||
|
||||
gems
|
||||
The pecl extensions to update.
|
||||
'''
|
||||
return _pecl('install -U {0}'.format(pecls))
|
||||
|
||||
|
||||
def list():
|
||||
'''
|
||||
List installed pecl extensions.
|
||||
'''
|
||||
|
||||
lines = _pecl('list').splitlines()
|
||||
lines.pop(0)
|
||||
lines.pop(0)
|
||||
lines.pop(0)
|
||||
lines.pop(0)
|
||||
|
||||
pecls = {}
|
||||
for line in lines:
|
||||
m = re.match('^([^ ]+)[ ]+([^ ]+)[ ]+([^ ]+)', line)
|
||||
if m:
|
||||
pecls[m.group(1)] = [m.group(2), m.group(3)]
|
||||
|
||||
return pecls
|
||||
|
||||
|
||||
|
64
salt/states/pecl.py
Normal file
64
salt/states/pecl.py
Normal file
@ -0,0 +1,64 @@
|
||||
'''
|
||||
Installation of PHP pecl extensions.
|
||||
==============================================
|
||||
|
||||
A state module to manage php pecl extensions.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
mongo:
|
||||
pecl.installed
|
||||
'''
|
||||
|
||||
|
||||
def installed(name):
|
||||
'''
|
||||
Make sure that a pecl extension is installed.
|
||||
|
||||
name
|
||||
The pecl extension name to install
|
||||
'''
|
||||
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
|
||||
if name in __salt__['pecl.list']():
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'Pecl is already installed.'
|
||||
return ret
|
||||
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'The pecl {0} would have been installed'.format(name)
|
||||
return ret
|
||||
if __salt__['pecl.install'](name):
|
||||
ret['result'] = True
|
||||
ret['changes'][name] = 'Installed'
|
||||
ret['comment'] = 'Pecl was successfully installed'
|
||||
else:
|
||||
ret['result'] = False
|
||||
ret['comment'] = 'Could not install pecl.'
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def removed(name):
|
||||
'''
|
||||
Make sure that a pecl extension is not installed.
|
||||
|
||||
name
|
||||
The pecl exntension name to uninstall
|
||||
'''
|
||||
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
|
||||
if name not in __salt__['pecl.list']():
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'Pecl is not installed.'
|
||||
return ret
|
||||
|
||||
if __opts__['test']:
|
||||
ret['comment'] = 'The pecl {0} would have been removed'.format(name)
|
||||
return ret
|
||||
if __salt__['pecl.uninstall'](name):
|
||||
ret['result'] = True
|
||||
ret['changes'][name] = 'Removed'
|
||||
ret['comment'] = 'Pecl was successfully removed.'
|
||||
else:
|
||||
ret['result'] = False
|
||||
ret['comment'] = 'Could not remove pecl.'
|
||||
return ret
|
Loading…
Reference in New Issue
Block a user