Skip to content

Commit

Permalink
Pass in existing __utils__ instead of making a new one
Browse files Browse the repository at this point in the history
  • Loading branch information
techhat committed Feb 7, 2017
1 parent 94a6055 commit 87fd95d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
6 changes: 3 additions & 3 deletions salt/modules/sdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get(uri):
salt '*' sdb.get sdb://mymemcached/foo
'''
return salt.utils.sdb.sdb_get(uri, __opts__)
return salt.utils.sdb.sdb_get(uri, __opts__, __utils__)


def set_(uri, value):
Expand All @@ -40,7 +40,7 @@ def set_(uri, value):
salt '*' sdb.set sdb://mymemcached/foo bar
'''
return salt.utils.sdb.sdb_set(uri, value, __opts__)
return salt.utils.sdb.sdb_set(uri, value, __opts__, __utils__)


def delete(uri):
Expand All @@ -55,4 +55,4 @@ def delete(uri):
salt '*' sdb.delete sdb://mymemcached/foo
'''
return salt.utils.sdb.sdb_delete(uri, __opts__)
return salt.utils.sdb.sdb_delete(uri, __opts__, __utils__)
6 changes: 3 additions & 3 deletions salt/runners/sdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get(uri):
salt '*' sdb.get sdb://mymemcached/foo
'''
return salt.utils.sdb.sdb_get(uri, __opts__)
return salt.utils.sdb.sdb_get(uri, __opts__, __utils__)


def set_(uri, value):
Expand All @@ -39,7 +39,7 @@ def set_(uri, value):
salt '*' sdb.set sdb://mymemcached/foo bar
'''
return salt.utils.sdb.sdb_set(uri, value, __opts__)
return salt.utils.sdb.sdb_set(uri, value, __opts__, __utils__)


def delete(uri):
Expand All @@ -54,4 +54,4 @@ def delete(uri):
salt '*' sdb.delete sdb://mymemcached/foo
'''
return salt.utils.sdb.sdb_delete(uri, __opts__)
return salt.utils.sdb.sdb_delete(uri, __opts__, __utils__)
19 changes: 12 additions & 7 deletions salt/utils/sdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
modules.
'''
from __future__ import absolute_import
import salt.loader
from salt.ext.six import string_types


def sdb_get(uri, opts):
def sdb_get(uri, opts, utils=None):
'''
Get a value from a db, using a uri in the form of ``sdb://<profile>/<key>``. If
the uri provided does not start with ``sdb://``, then it will be returned as-is.
Expand All @@ -21,6 +20,9 @@ def sdb_get(uri, opts):
if not uri.startswith('sdb://'):
return uri

if utils is None:
utils = {}

sdlen = len('sdb://')
indx = uri.find('/', sdlen)

Expand All @@ -36,12 +38,11 @@ def sdb_get(uri, opts):
fun = '{0}.get'.format(profile['driver'])
query = uri[indx+1:]

utils = salt.loader.utils(opts)
loaded_db = salt.loader.sdb(opts, fun, utils=utils)
return loaded_db[fun](query, profile=profile)


def sdb_set(uri, value, opts):
def sdb_set(uri, value, opts, utils=None):
'''
Set a value in a db, using a uri in the form of ``sdb://<profile>/<key>``.
If the uri provided does not start with ``sdb://`` or the value is not
Expand All @@ -53,6 +54,9 @@ def sdb_set(uri, value, opts):
if not uri.startswith('sdb://'):
return False

if utils is None:
utils = {}

sdlen = len('sdb://')
indx = uri.find('/', sdlen)

Expand All @@ -68,12 +72,11 @@ def sdb_set(uri, value, opts):
fun = '{0}.set'.format(profile['driver'])
query = uri[indx+1:]

utils = salt.loader.utils(opts)
loaded_db = salt.loader.sdb(opts, fun, utils=utils)
return loaded_db[fun](query, value, profile=profile)


def sdb_delete(uri, opts):
def sdb_delete(uri, opts, utils=None):
'''
Delete a value from a db, using a uri in the form of ``sdb://<profile>/<key>``. If
the uri provided does not start with ``sdb://`` or the value is not successfully
Expand All @@ -85,6 +88,9 @@ def sdb_delete(uri, opts):
if not uri.startswith('sdb://'):
return False

if utils is None:
utils = {}

sdlen = len('sdb://')
indx = uri.find('/', sdlen)

Expand All @@ -100,6 +106,5 @@ def sdb_delete(uri, opts):
fun = '{0}.delete'.format(profile['driver'])
query = uri[indx+1:]

utils = salt.loader.utils(opts)
loaded_db = salt.loader.sdb(opts, fun, utils=utils)
return loaded_db[fun](query, profile=profile)

0 comments on commit 87fd95d

Please sign in to comment.