Merge branch 'develop' of github.com:saltstack/salt into develop

This commit is contained in:
Thomas S Hatch 2012-07-12 21:40:48 -06:00
commit 513442168a
2 changed files with 203 additions and 11 deletions

188
salt/modules/cassandra.py Normal file
View File

@ -0,0 +1,188 @@
'''
Cassandra NoSQL Database Module
REQUIREMENT 1:
The location of the 'nodetool' command, host, and thrift port
needs to be specified via pillar.
cassandra.nodetool: /usr/local/bin/nodetool
cassandra.host: localhost
cassandra.thrift_port: 9160
REQUIREMENT 2:
The python module, 'pycassa', also needs to be installed on the
minion.
'''
import logging
log = logging.getLogger(__name__)
__outputter__ = {
'compactionstats': 'txt',
'tpstats': 'txt',
'netstats': 'txt',
'info': 'txt',
'ring': 'txt',
}
def __virtual__():
global nt
global host
global thrift_port
try:
nt = __pillar__['cassandra.nodetool']
host = __pillar__['cassandra.host']
thrift_port = str(__pillar__['cassandra.thrift_port'])
from pycassa.system_manager import SystemManager
except ImportError:
log.info('Module failed to load: pycassa is not installed')
return False
except KeyError:
log.info('Module failed to load: cassandra.* pillar'
'values are incomplete')
return False
return 'cassandra'
def _nodetool(cmd):
'''
Internal cassandra nodetool wrapper. Some functions are not
available via pycassa so we must rely on nodetool.
'''
return __salt__['cmd.run_stdout'](nt + ' -h ' + host + ' ' + cmd)
def _sys_mgr():
'''
Return a pycassa system manager connection object
'''
from pycassa.system_manager import SystemManager
return SystemManager(host + ':' + thrift_port)
def compactionstats():
'''
Return compactionstats info
CLI Example::
salt '*' cassandra.compactionstats
'''
return _nodetool('compactionstats')
def version():
'''
Return the cassandra version
CLI Example::
salt '*' cassandra.version
'''
return _nodetool('version')
def netstats():
'''
Return netstats info
CLI Example::
salt '*' cassandra.netstats
'''
return _nodetool('netstats')
def tpstats():
'''
Return tpstats info
CLI Example::
salt '*' cassandra.tpstats
'''
return _nodetool('tpstats')
def info():
'''
Return cassandra node info
CLI Example::
salt '*' cassandra.info
'''
return _nodetool('info')
def ring():
'''
Return cassandra ring info
CLI Example::
salt '*' cassandra.ring
'''
return _nodetool('ring')
def keyspaces():
'''
Return existing keyspaces
CLI Example::
salt '*' cassandra.keyspaces
'''
sys = _sys_mgr()
return sys.list_keyspaces()
def column_families(keyspace=None):
'''
Return existing column families for all keyspaces
or just the provided one.
CLI Example::
salt '*' cassandra.column_families
salt '*' cassandra.column_families <keyspace>
'''
sys = _sys_mgr()
ks = sys.list_keyspaces()
if keyspace:
if keyspace in ks:
return sys.get_keyspace_column_families(keyspace).keys()
else:
return None
else:
ret = {}
for k in ks:
ret[k] = sys.get_keyspace_column_families(k).keys()
return ret
def column_family_definition(keyspace=None, column_family=None):
'''
Return a dictionary of column family definitions for the given
keyspace/column_family
CLI Example::
salt '*' cassandra.column_family_definition <keyspace> <column_family>
'''
sys = _sys_mgr()
try:
return vars(sys.get_keyspace_column_families(keyspace)[column_family])
except:
log.debug('Invalid Keyspace/CF combination')
return None

View File

@ -135,7 +135,7 @@ def latest(name,
return ret
def present(name, bare=True, force=False):
def present(name, bare=True, runas=None, force=False):
'''
Make sure the repository is present in the given directory
@ -143,6 +143,10 @@ def present(name, bare=True, force=False):
Name of the directory where the repository is about to be created
bare
Create a bare repository (Default: True)
runas
Name of the user performing repository management operations
force
Force create a new repository into an pre-existing non-git directory (deletes contents)
'''
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
@ -155,26 +159,26 @@ def present(name, bare=True, force=False):
# Directory exists and is not a git repo, if force is set destroy the
# directory and recreate, otherwise throw an error
elif not force:
ret['result'] = False
ret['comment'] = ('Directory which does not contain a git repo '
'is already present at {0}. To delete this '
'directory and create a fresh git repo set '
'force: True').format(name)
return ret
return _fail(ret,
'Directory which does not contain a git repo '
'is already present at {0}. To delete this '
'directory and create a fresh git repo set '
'force: True'.format(name))
# Run test is set
if __opts__['test']:
ret['result'] = None
ret['comment'] = 'New git repo set for creation at {0}'.format(name)
return ret
ret['changes']['new repository'] = name
return _neutral_test(ret, 'New git repo set for creation at {0}'.format(name))
if os.path.isdir(name) and force:
shutil.rmtree(name)
opts = '--bare' if bare else ''
__salt__['git.init'](cwd=name, opts=opts)
__salt__['git.init'](cwd=name, user=runas, opts=opts)
message = 'Initialized repository {0}'.format(name)
log.info(message)
ret['changes']['new repository'] = name
ret['comment'] = message
return ret