本文整理汇总了Python中augeas.Augeas.get方法的典型用法代码示例。如果您正苦于以下问题:Python Augeas.get方法的具体用法?Python Augeas.get怎么用?Python Augeas.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类augeas.Augeas
的用法示例。
在下文中一共展示了Augeas.get方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: match
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import get [as 别名]
def match(path, value=''):
'''
Get matches for path expression
CLI Example::
salt '*' augeas.match /files/etc/services/service-name ssh
'''
from augeas import Augeas
aug = Augeas()
ret = {}
try:
matches = aug.match(path)
except RuntimeError:
return ret
for _match in matches:
if value and aug.get(_match) == value:
ret[_match] = value
elif not value:
ret[_match] = aug.get(_match)
return ret
示例2: get
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import get [as 别名]
def get(path, value=''):
'''
Get a value for a specific augeas path
CLI Example:
.. code-block:: bash
salt '*' augeas.get /files/etc/hosts/1/ ipaddr
'''
aug = Augeas()
ret = {}
path = path.rstrip('/')
if value:
path += '/{0}'.format(value.strip('/'))
try:
_match = aug.match(path)
except RuntimeError as err:
return {'error': str(err)}
if _match:
ret[path] = aug.get(path)
else:
ret[path] = '' # node does not exist
return ret
示例3: set
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import get [as 别名]
def set(self,entryPath,param='',pvalue='',hierarchy='/files'):
"""Set/change a value for a config. parameter in a config. file,
with the help of Augeas, a configuration API (cf http://augeas.net)"""
try:
from augeas import Augeas
aug=Augeas()
except Exception, e: return str(e)
path=(hierarchy+entryPath.rstrip('/')+'/'+param).rstrip('/')
try:
aug.set(path,pvalue)
except Exception, e: return str(e)
# Here is a little workaround for a bug in save for augeas.
# In the future this won't be necessary anymore.
try:
aug.save()
except:
pass
# End of workaround
try:
aug.save()
except Exception, e: return str(e)
try:
pvalue=aug.get(path)
#aug.close()
except Exception, e: return str(e)
return { 'path': entryPath, 'parameter': param, 'value': pvalue, 'hierarchy': hierarchy }
示例4: get
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import get [as 别名]
def get(path, value=""):
"""
Get a value for a specific augeas path
CLI Example::
salt '*' augeas.get /files/etc/hosts/1/ ipaddr
"""
from augeas import Augeas
aug = Augeas()
ret = {}
path = path.rstrip("/")
if value:
path += "/{0}".format(value.strip("/"))
try:
_match = aug.match(path)
except RuntimeError as err:
return {"error": str(err)}
if _match:
ret[path] = aug.get(path)
else:
ret[path] = "" # node does not exist
return ret
示例5: get
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import get [as 别名]
def get(self,entryPath,param='',hierarchy='/files'):
"""Get a value for a config. parameter in a config. file,
with the help of Augeas, a configuration API (cf http://augeas.net)"""
try:
from augeas import Augeas
aug=Augeas()
except Exception, e: return str(e)
# yes, entryPath.rstrip('/')+'/' is really needed (i.e. entryPath=/)
path=(hierarchy+entryPath.rstrip('/')+'/'+param).rstrip('/')
try:
matchtest=aug.match(path)
except Exception, e: return str(e)
if matchtest:
try:
pvalue=aug.get(path)
#aug.close()
except Exception, e: return str(e)
else:
# The node doesn't exist
pvalue='(o)'
if not pvalue:
# The node doesn't have a value
pvalue='(none)'
return { 'path': entryPath, 'parameter': param, 'value': pvalue, 'hierarchy': hierarchy }
示例6: get_configured_ifaces
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import get [as 别名]
def get_configured_ifaces():
aug = Augeas(flags=Augeas.NO_MODL_AUTOLOAD)
aug.add_transform('interfaces', '/etc/network/interfaces')
aug.load()
base = '/files/etc/network/interfaces'
for m in aug.match('%s/iface' % base):
yield aug.get(m)
aug.close()
示例7: __disable_mod_ssl_ocsp
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import get [as 别名]
def __disable_mod_ssl_ocsp(self):
aug = Augeas(flags=Augeas.NO_LOAD | Augeas.NO_MODL_AUTOLOAD)
aug.set('/augeas/load/Httpd/lens', 'Httpd.lns')
aug.set('/augeas/load/Httpd/incl', paths.HTTPD_SSL_CONF)
aug.load()
path = '/files{}/VirtualHost'.format(paths.HTTPD_SSL_CONF)
ocsp_path = '{}/directive[.="{}"]'.format(path, OCSP_DIRECTIVE)
ocsp_arg = '{}/arg'.format(ocsp_path)
ocsp_comment = '{}/#comment[.="{}"]'.format(path, OCSP_DIRECTIVE)
ocsp_dir = aug.get(ocsp_path)
# there is SSLOCSPEnable directive in nss.conf file, comment it
# otherwise just do nothing
if ocsp_dir is not None:
ocsp_state = aug.get(ocsp_arg)
aug.remove(ocsp_arg)
aug.rename(ocsp_path, '#comment')
aug.set(ocsp_comment, '{} {}'.format(OCSP_DIRECTIVE, ocsp_state))
aug.save()
示例8: execute
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import get [as 别名]
def execute(*args, **kw):
if conf.timezone == None:
print >> sys.stderr, utils.multiline_message(
_("""
Please supply the timezone PHP should be using.
You have to use a Continent or Country / City locality name
like 'Europe/Berlin', but not just 'CEST'.
""")
)
conf.timezone = utils.ask_question(
_("Timezone ID"),
default="UTC"
)
if not conf.php_ini_path == None:
if not os.path.isfile(conf.php_ini_path):
log.error(_("Cannot configure PHP through %r (No such file or directory)") % (conf.php_ini_path))
return
php_ini = conf.php_ini_path
else:
# Search and destroy
php_ini = "/etc/php.ini"
if not os.path.isfile(php_ini):
php_ini = "/etc/php5/apache2/php.ini"
if not os.path.isfile(php_ini):
log.error(_("Could not find PHP configuration file php.ini"))
return
myaugeas = Augeas()
setting_base = '/files%s/' % (php_ini)
setting = os.path.join(setting_base, 'Date', 'date.timezone')
current_value = myaugeas.get(setting)
if current_value == None:
insert_paths = myaugeas.match('/files%s/Date/*' % (php_ini))
insert_path = insert_paths[(len(insert_paths)-1)]
myaugeas.insert(insert_path, 'date.timezone', False)
log.debug(_("Setting key %r to %r") % ('Date/date.timezone', conf.timezone), level=8)
myaugeas.set(setting, conf.timezone)
myaugeas.save()
示例9: set_api_timeouts
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import get [as 别名]
def set_api_timeouts(self, timeout):
# Determine the file to change
if self.https:
config_file = self.abiquo_ssl_conf
else:
config_file = self.abiquo_conf
logging.info("Setting Proxy timeouts in %s" % config_file)
# Set timeout using Augeas
a = Augeas()
for loc in a.match("/files%s/VirtualHost/*[arg='/api']" % config_file):
proxy_pass = a.match("%s/*[self::directive='ProxyPass']" % loc)
if len(proxy_pass) == 1:
# Proxy timeout already exists
logging.info("ProxyPass found")
arg1 = a.get("%s/arg" % proxy_pass[0])
arg2 = "timeout=%s" % timeout
a.set("%s/arg[1]" % proxy_pass[0], arg1)
a.set("%s/arg[2]" % proxy_pass[0], arg2)
a.save()
a.close()
示例10: ls
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import get [as 别名]
def ls(self,entryPath,hierarchy='/files'):
"""List the direct children of an entry in a config. file,
with the help of Augeas, a configuration API (cf http://augeas.net)"""
try:
from augeas import Augeas
aug=Augeas()
except Exception, e: return str(e)
path=hierarchy+entryPath.rstrip('/')+'/*'
# We can't use a dict here because the same key can appear many times.
nodes=[]
try:
for match in aug.match(path):
pvalue=aug.get(match)
if not pvalue:
pvalue='(none)'
nodes.append([ospath.basename(match),pvalue])
except Exception, e: return str(e)
#try:
# aug.close()
#except Exception, e: return str(e)
return { 'path': entryPath, 'nodes': nodes, 'hierarchy': hierarchy }
示例11: LVMConfig
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import get [as 别名]
class LVMConfig(object):
def __init__(self, path="/etc/lvm/lvm.conf"):
self.path = path
# Augeas loads by default tons of unneeded lenses and configuration
# files. On my test host, it fails to load, trying to read my 500 MiB
# /etc/lvm/archive/.
#
# These are the standard LVM lens includes:
# /augeas/load/LVM/incl[1] /etc/lvm/lvm.conf
# /augeas/load/LVM/incl[2] /etc/lvm/backup/*
# /augeas/load/LVM/incl[3] /etc/lvm/archive/*.vg
#
# We need only the first entry to work with lvm.conf. Using customized
# load setup, as explained in
# https://github.com/hercules-team/augeas/wiki/Loading-specific-files
#
# Removing the archive and backup entries, we can load augeas in 0.7
# seconds on my test vm. Removing all other lenses shorten the time to
# 0.04 seconds.
log.debug("Loading LVM configuration from %r", path)
self.aug = Augeas(flags=Augeas.NO_MODL_AUTOLOAD | Augeas.SAVE_BACKUP)
self.aug.add_transform("lvm.lns", [path])
self.aug.load()
# Context manager interface
def __enter__(self):
return self
def __exit__(self, t, v, tb):
try:
self.close()
except Exception as e:
# Caller succeeded, raise the close error.
if t is None:
raise
# Caller has failed, do not hide the original error.
log.exception("Error closing %s: %s" % (self, e))
# Accessing list of strings
def getlist(self, section, option):
pat = "/files%s/%s/dict/%s/list/*/str" % (self.path, section, option)
matches = self.aug.match(pat)
if not matches:
return None # Cannot store/read empty list
return [self.aug.get(m) for m in matches]
def setlist(self, section, option, value):
log.debug("Setting %s/%s to %s", section, option, value)
opt_path = "/files%s/%s/dict/%s" % (self.path, section, option)
self.aug.remove(opt_path)
item_path = opt_path + "/list/%d/str"
for i, item in enumerate(value, 1):
self.aug.set(item_path % i, item)
# Accessing flat values (int, string)
def getint(self, section, option):
val = self._get_flat(section, option, "int")
return int(val) if val is not None else None
def setint(self, section, option, value):
self._set_flat(section, option, "int", str(value))
def getstr(self, section, option):
return self._get_flat(section, option, "str")
def setstr(self, section, option, value):
self._set_flat(section, option, "str", value)
def _get_flat(self, section, option, opt_type):
path = self._flat_path(section, option, opt_type)
return self.aug.get(path)
def _set_flat(self, section, option, opt_type, value):
log.debug("Setting %s/%s to %r", section, option, value)
path = self._flat_path(section, option, opt_type)
return self.aug.set(path, value)
def _flat_path(self, section, option, opt_type):
return "/files%s/%s/dict/%s/%s" % (
self.path, section, option, opt_type)
# Removing options
def remove(self, section, option):
log.debug("Removing %s/%s", section, option)
path = "/files%s/%s/dict/%s" % (self.path, section, option)
self.aug.remove(path)
# File operations
def save(self):
log.info("Saving new LVM configuration to %r, previous configuration "
"saved to %r",
self.path, self.path + ".augsave")
#.........这里部分代码省略.........
示例12: match
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import get [as 别名]
def match(self,entryPath,param='',pvalue='',hierarchy='/files'):
"""Match a value for a config. parameter in a config. file,
with the help of Augeas, a configuration API (cf http://augeas.net)"""
try:
from augeas import Augeas
aug=Augeas()
except Exception, e: return str(e)
path=(hierarchy+entryPath.rstrip('/')+'/'+param).rstrip('/')
childpath=(hierarchy+entryPath.rstrip('/')+'/*/'+param).rstrip('/')
if pvalue:
try:
matchlist = [ ospath.dirname(lstripstr(item,'/files')) for item in aug.match(path) + aug.match(childpath) if ( aug.get(item) == pvalue ) ]
#aug.close()
except Exception, e: return str(e)
else:
try:
matchlist = [ ospath.dirname(lstripstr(item,'/files')) for item in aug.match(path) + aug.match(childpath) ]
#aug.close()
except Exception, e: return str(e)
return matchlist
示例13: execute
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import get [as 别名]
def execute(*args, **kw):
group_filter = conf.get('ldap','kolab_group_filter')
if group_filter == None:
group_filter = conf.get('ldap','group_filter')
user_filter = conf.get('ldap','kolab_user_filter')
if user_filter == None:
user_filter = conf.get('ldap','user_filter')
resource_filter = conf.get('ldap', 'resource_filter')
sharedfolder_filter = conf.get('ldap', 'sharedfolder_filter')
server_host = utils.parse_ldap_uri(conf.get('ldap', 'ldap_uri'))[1]
files = {
"/etc/postfix/ldap/local_recipient_maps.cf": """
server_host = %(server_host)s
server_port = 389
version = 3
search_base = %(base_dn)s
scope = sub
domain = ldap:/etc/postfix/ldap/mydestination.cf
bind_dn = %(service_bind_dn)s
bind_pw = %(service_bind_pw)s
query_filter = (&(|(mail=%%s)(alias=%%s))(|%(kolab_user_filter)s%(kolab_group_filter)s%(resource_filter)s%(sharedfolder_filter)s))
result_attribute = mail
""" % {
"base_dn": conf.get('ldap', 'base_dn'),
"server_host": server_host,
"service_bind_dn": conf.get('ldap', 'service_bind_dn'),
"service_bind_pw": conf.get('ldap', 'service_bind_pw'),
"kolab_user_filter": user_filter,
"kolab_group_filter": group_filter,
"resource_filter": resource_filter,
"sharedfolder_filter": sharedfolder_filter,
},
"/etc/postfix/ldap/mydestination.cf": """
server_host = %(server_host)s
server_port = 389
version = 3
search_base = %(domain_base_dn)s
scope = sub
bind_dn = %(service_bind_dn)s
bind_pw = %(service_bind_pw)s
query_filter = %(domain_filter)s
result_attribute = %(domain_name_attribute)s
""" % {
"server_host": server_host,
"domain_base_dn": conf.get('ldap', 'domain_base_dn'),
"domain_filter": conf.get('ldap', 'domain_filter').replace('*', '%s'),
"domain_name_attribute": conf.get('ldap', 'domain_name_attribute'),
"service_bind_dn": conf.get('ldap', 'service_bind_dn'),
"service_bind_pw": conf.get('ldap', 'service_bind_pw'),
},
"/etc/postfix/ldap/mailenabled_distgroups.cf": """
server_host = %(server_host)s
server_port = 389
version = 3
search_base = %(group_base_dn)s
scope = sub
domain = ldap:/etc/postfix/ldap/mydestination.cf
bind_dn = %(service_bind_dn)s
bind_pw = %(service_bind_pw)s
# This finds the mail enabled distribution group LDAP entry
query_filter = (&(|(mail=%%s)(alias=%%s))(objectClass=kolabgroupofuniquenames)(objectclass=groupofuniquenames)(!(objectclass=groupofurls)))
# From this type of group, get all uniqueMember DNs
special_result_attribute = uniqueMember
# Only from those DNs, get the mail
result_attribute =
leaf_result_attribute = mail
""" % {
"server_host": server_host,
"group_base_dn": conf.get('ldap', 'group_base_dn'),
"service_bind_dn": conf.get('ldap', 'service_bind_dn'),
"service_bind_pw": conf.get('ldap', 'service_bind_pw'),
},
"/etc/postfix/ldap/mailenabled_dynamic_distgroups.cf": """
server_host = %(server_host)s
server_port = 389
version = 3
search_base = %(group_base_dn)s
scope = sub
domain = ldap:/etc/postfix/ldap/mydestination.cf
bind_dn = %(service_bind_dn)s
bind_pw = %(service_bind_pw)s
# This finds the mail enabled dynamic distribution group LDAP entry
query_filter = (&(|(mail=%%s)(alias=%%s))(objectClass=kolabgroupofuniquenames)(objectClass=groupOfURLs))
#.........这里部分代码省略.........
示例14: execute
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import get [as 别名]
def execute(*args, **kw):
"""
Apply the necessary settings to /etc/imapd.conf
"""
imapd_settings = {
"ldap_servers": conf.get('ldap', 'ldap_uri'),
"ldap_base": conf.get('ldap', 'base_dn'),
"ldap_bind_dn": conf.get('ldap', 'service_bind_dn'),
"ldap_password": conf.get('ldap', 'service_bind_pw'),
"ldap_filter": '(|(&(|(uid=%s)(uid=cyrus-murder))(uid=%%U))(&(|(uid=%%U)(mail=%%[email protected]%%d)(mail=%%[email protected]%%r))(objectclass=kolabinetorgperson)))' % (conf.get('cyrus-imap', 'admin_login')),
"ldap_user_attribute": conf.get('cyrus-sasl', 'result_attribute'),
"ldap_group_base": conf.get('ldap', 'base_dn'),
"ldap_group_filter": "(&(cn=%u)(objectclass=ldapsubentry)(objectclass=nsroledefinition))",
"ldap_group_scope": "one",
"ldap_member_base": conf.get('ldap','user_base_dn'),
"ldap_member_method": "attribute",
"ldap_member_attribute": "nsrole",
"admins": conf.get('cyrus-imap', 'admin_login'),
"postuser": "shared",
}
template_file = None
if os.path.isfile('/etc/kolab/templates/imapd.conf.tpl'):
template_file = '/etc/kolab/templates/imapd.conf.tpl'
elif os.path.isfile('/usr/share/kolab/templates/imapd.conf.tpl'):
template_file = '/usr/share/kolab/templates/imapd.conf.tpl'
elif os.path.isfile(os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'imapd.conf.tpl'))):
template_file = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'imapd.conf.tpl'))
if not template_file == None:
fp = open(template_file, 'r')
template_definition = fp.read()
fp.close()
t = Template(template_definition, searchList=[imapd_settings])
fp = open('/etc/imapd.conf', 'w')
fp.write(t.__str__())
fp.close()
else:
log.error(_("Could not write out Cyrus IMAP configuration file /etc/imapd.conf"))
return
cyrus_settings = {}
template_file = None
if os.path.isfile('/etc/kolab/templates/cyrus.conf.tpl'):
template_file = '/etc/kolab/templates/cyrus.conf.tpl'
elif os.path.isfile('/usr/share/kolab/templates/cyrus.conf.tpl'):
template_file = '/usr/share/kolab/templates/cyrus.conf.tpl'
elif os.path.isfile(os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'cyrus.conf.tpl'))):
template_file = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'cyrus.conf.tpl'))
if not template_file == None:
fp = open(template_file, 'r')
template_definition = fp.read()
fp.close()
t = Template(template_definition, searchList=[cyrus_settings])
fp = open('/etc/cyrus.conf', 'w')
fp.write(t.__str__())
fp.close()
else:
log.error(_("Could not write out Cyrus IMAP configuration file /etc/cyrus.conf"))
return
annotations = [
"/vendor/kolab/activesync,mailbox,string,backend,value.priv,r",
"/vendor/kolab/color,mailbox,string,backend,value.shared value.priv,a",
"/vendor/kolab/displayname,mailbox,string,backend,value.shared value.priv,a",
"/vendor/kolab/folder-test,mailbox,string,backend,value.shared value.priv,a",
"/vendor/kolab/folder-type,mailbox,string,backend,value.shared value.priv,a",
"/vendor/kolab/incidences-for,mailbox,string,backend,value.shared value.priv,a",
"/vendor/kolab/pxfb-readable-for,mailbox,string,backend,value.shared value.priv,a",
"/vendor/kolab/uniqueid,mailbox,string,backend,value.shared value.priv,a",
"/vendor/kolab/h-share-attr-desc,mailbox,string,backend,value.shared value.priv,a",
"/vendor/horde/share-params,mailbox,string,backend,value.shared value.priv,a",
"/vendor/x-toltec/test,mailbox,string,backend,value.shared value.priv,a",
]
fp = open('/etc/imapd.annotations.conf', 'w')
fp.write("\n".join(annotations))
fp.close()
if os.path.isfile('/etc/default/kolab-saslauthd'):
myaugeas = Augeas()
setting = os.path.join('/files/etc/default/kolab-saslauthd','START')
if not myaugeas.get(setting) == 'yes':
myaugeas.set(setting,'yes')
myaugeas.save()
myaugeas.close()
if os.path.isfile('/bin/systemctl'):
subprocess.call(['systemctl', 'stop', 'saslauthd.service'])
#.........这里部分代码省略.........