diff options
Diffstat (limited to 'ceilometer/utils.py')
-rw-r--r-- | ceilometer/utils.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/ceilometer/utils.py b/ceilometer/utils.py index 5f05c3a0..c703521b 100644 --- a/ceilometer/utils.py +++ b/ceilometer/utils.py @@ -27,11 +27,32 @@ import hashlib import multiprocessing import struct +from ceilometer.openstack.common import processutils +from oslo.config import cfg from oslo.utils import timeutils from oslo.utils import units import six +rootwrap_conf = cfg.StrOpt('rootwrap_config', + default="/etc/ceilometer/rootwrap.conf", + help='Path to the rootwrap configuration file to' + 'use for running commands as root') +CONF = cfg.CONF +CONF.register_opt(rootwrap_conf) + + +def _get_root_helper(): + return 'sudo ceilometer-rootwrap %s' % CONF.rootwrap_config + + +def execute(*cmd, **kwargs): + """Convenience wrapper around oslo's execute() method.""" + if 'run_as_root' in kwargs and 'root_helper' not in kwargs: + kwargs['root_helper'] = _get_root_helper() + return processutils.execute(*cmd, **kwargs) + + def recursive_keypairs(d, separator=':'): """Generator that produces sequence of keypairs for nested dictionaries.""" for name, value in sorted(six.iteritems(d)): |