本文整理汇总了Python中aquilon.config.Config.get方法的典型用法代码示例。如果您正苦于以下问题:Python Config.get方法的具体用法?Python Config.get怎么用?Python Config.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aquilon.config.Config
的用法示例。
在下文中一共展示了Config.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sync_domain
# 需要导入模块: from aquilon.config import Config [as 别名]
# 或者: from aquilon.config.Config import get [as 别名]
def sync_domain(dbdomain, logger=LOGGER, locked=False):
"""Update templates on disk to match contents of branch in template-king.
If this domain is tracking another, first update the branch in
template-king with the latest from the tracking branch. Also save
the current (previous) commit as a potential rollback point.
"""
config = Config()
kingdir = config.get("broker", "kingdir")
domaindir = os.path.join(config.get("broker", "domainsdir"), dbdomain.name)
git_env = {"PATH": "%s:%s" % (config.get("broker", "git_path"),
os.environ.get("PATH", ""))}
if dbdomain.tracked_branch:
# Might need to revisit if using this helper from rollback...
run_command(["git", "push", ".",
"%s:%s" % (dbdomain.tracked_branch.name, dbdomain.name)],
path=kingdir, env=git_env, logger=logger)
run_command(["git", "fetch", "--prune"], path=domaindir, env=git_env, logger=logger)
if dbdomain.tracked_branch:
out = run_command(["git", "rev-list", "-n", "1", "HEAD"],
path=domaindir, env=git_env, logger=logger)
rollback_commit = out.strip()
try:
if not locked:
key = CompileKey(domain=dbdomain.name, logger=logger)
lock_queue.acquire(key)
run_command(["git", "reset", "--hard", "origin/%s" % dbdomain.name],
path=domaindir, env=git_env, logger=logger)
finally:
if not locked:
lock_queue.release(key)
if dbdomain.tracked_branch:
dbdomain.rollback_commit = rollback_commit
示例2: run_git
# 需要导入模块: from aquilon.config import Config [as 别名]
# 或者: from aquilon.config.Config import get [as 别名]
def run_git(args, env=None, path=".",
logger=LOGGER, loglevel=logging.INFO, filterre=None):
config = Config()
if env:
git_env = env.copy()
else:
git_env = {}
env_path = git_env.get("PATH", os.environ.get("PATH", ""))
git_env["PATH"] = "%s:%s" % (config.get("broker", "git_path"), env_path)
for name in ["git_author_name", "git_author_email",
"git_committer_name", "git_committer_email"]:
if not config.has_option("broker", name):
continue
value = config.get("broker", name)
git_env[name.upper()] = value
if isinstance(args, list):
git_args = args[:]
if git_args[0] != "git":
git_args.insert(0, "git")
else:
git_args = ["git", args]
return run_command(git_args, env=git_env, path=path,
logger=logger, loglevel=loglevel, filterre=filterre)
示例3: outputdirs
# 需要导入模块: from aquilon.config import Config [as 别名]
# 或者: from aquilon.config.Config import get [as 别名]
def outputdirs(self):
"""Returns a list of directories that should exist before compiling"""
config = Config()
dirs = []
dirs.append(config.get("broker", "profilesdir"))
# The regression tests occasionally have issues with panc
# auto-creating this directory - not sure why.
if self.domain.clusters:
dirs.append(os.path.join(config.get("broker", "quattordir"), "build", "xml", self.domain.name, "clusters"))
return dirs
示例4: directories
# 需要导入模块: from aquilon.config import Config [as 别名]
# 或者: from aquilon.config.Config import get [as 别名]
def directories(self):
"""Return a list of directories required for compiling this domain"""
config = Config()
dirs = []
if self.domain.branch_type == "domain":
dirs.append(os.path.join(config.get("broker", "domainsdir"), self.domain.name))
dirs.append(os.path.join(config.get("broker", "quattordir"), "cfg", "domains", self.domain.name))
dirs.append(os.path.join(config.get("broker", "quattordir"), "build", "xml", self.domain.name))
return dirs
示例5: testclonetemplateking
# 需要导入模块: from aquilon.config import Config [as 别名]
# 或者: from aquilon.config.Config import get [as 别名]
def testclonetemplateking(self):
config = Config()
source = config.get("unittest", "template_base")
dest = config.get("broker", "kingdir")
p = Popen(("/bin/rm", "-rf", dest), stdout=1, stderr=2)
rc = p.wait()
self.assertEqual(rc, 0,
"Failed to clear old template-king directory '%s'" %
dest)
env = {}
env["PATH"] = "%s:%s" % (config.get("broker", "git_path"),
os.environ.get("PATH", ""))
p = Popen(("git", "clone", "--bare", source, dest),
env=env, stdout=PIPE, stderr=PIPE)
(out, err) = p.communicate()
# Ignore out/err unless we get a non-zero return code, then log it.
self.assertEqual(p.returncode, 0,
"Non-zero return code for clone of template-king, "
"STDOUT:\[email protected]@@\n'%s'\[email protected]@@\nSTDERR:\[email protected]@@\n'%s'\[email protected]@@\n"
% (out, err))
# This value can be used to test against a different branch/commit
# than the current 'prod'.
new_prod = None
if config.has_option("unittest", "template_alternate_prod"):
new_prod = config.get("unittest", "template_alternate_prod")
if new_prod:
for domain in ['prod', 'ny-prod']:
p = Popen(("git", "push", ".", '+%s:%s' % (new_prod, domain)),
env=env, cwd=dest, stdout=PIPE, stderr=PIPE)
(out, err) = p.communicate()
# Ignore out/err unless we get a non-zero return code, then log it.
self.assertEqual(p.returncode, 0,
"Non-zero return code while setting alternate "
"'%s' branch locally to '%s':"
"\nSTDOUT:\[email protected]@@\n'%s'\[email protected]@@\n"
"\nSTDERR:\[email protected]@@\n'%s'\[email protected]@@\n"
% (domain, new_prod, out, err))
# Set the default branch
p = Popen(("git", "symbolic-ref", "HEAD", "refs/heads/prod"),
env=env, cwd=dest, stdout=PIPE, stderr=PIPE)
(out, err) = p.communicate()
self.assertEqual(p.returncode, 0,
"Non-zero return code while setting HEAD "
"to refs/heads/prod:"
"\nSTDOUT:\[email protected]@@\n'%s'\[email protected]@@\n"
"\nSTDERR:\[email protected]@@\n'%s'\[email protected]@@\n"
% (out, err))
return
示例6: discover_network_types
# 需要导入模块: from aquilon.config import Config [as 别名]
# 或者: from aquilon.config.Config import get [as 别名]
def discover_network_types(dbapi_con, connection_record): # pylint: disable=W0613
config = Config()
if not config.has_option("broker", "default_network_type"): # pragma: no cover
raise InternalError("The default_network_type option is missing from "
"the [broker] section in the configuration.")
default_type = config.get("broker", "default_network_type")
default_section = "network_" + default_type
if not config.has_section(default_section): # pragma: no cover
raise InternalError("The default network type is %s, but there's no "
"section named [%s] in the configuration." %
(default_type, default_section))
nettypes = {}
# This function should be called only once, but you never know...
if Network.network_type_map:
return
for section in config.sections():
if not section.startswith("network_"):
continue
name = section[8:]
nettypes[name] = NetworkProperties(config, name)
LOGGER.info("Configured network type %s", name)
Network.network_type_map = nettypes
Network.default_network_props = nettypes[default_type]
示例7: config_proto
# 需要导入模块: from aquilon.config import Config [as 别名]
# 或者: from aquilon.config.Config import get [as 别名]
def config_proto(self, node, command):
desc_node = node.find("message_class")
if desc_node is None or "name" not in desc_node.attrib or \
"module" not in desc_node.attrib:
raise ProtocolError("Invalid protobuf definition for %s." % command)
module = desc_node.attrib["module"]
msgclass = desc_node.attrib["name"]
if module in self.loaded_protocols and \
self.loaded_protocols[module] == False:
raise ProtocolError("Protocol %s: previous import attempt was "
"unsuccessful" % module)
if module not in self.loaded_protocols:
config = Config()
protodir = config.get("protocols", "directory")
# Modifying sys.path here is ugly. We could try playing with
# find_module()/load_module(), but there are dependencies between
# the protocols, that could fail if sys.path is not set up and the
# protocols are loaded in the wrong order.
if protodir not in sys.path:
sys.path.append(protodir)
try:
self.loaded_protocols[module] = __import__(module)
except ImportError, err: # pragma: no cover
self.loaded_protocols[module] = False
raise ProtocolError("Protocol %s: %s" % (module, err))
示例8: __init__
# 需要导入模块: from aquilon.config import Config [as 别名]
# 或者: from aquilon.config.Config import get [as 别名]
def __init__(self, logger=LOGGER):
config = Config()
self.logger = logger
self.dsdb = config.get("broker", "dsdb")
self.dsdb_use_testdb = config.getboolean("broker", "dsdb_use_testdb")
self.location_sync = config.getboolean("broker", "dsdb_location_sync")
self.actions = []
self.rollback_list = []
示例9: compile
# 需要导入模块: from aquilon.config import Config [as 别名]
# 或者: from aquilon.config.Config import get [as 别名]
def compile(
self, session, only=None, locked=False, panc_debug_include=None, panc_debug_exclude=None, cleandeps=False
):
"""The build directories are checked and constructed
if necessary, so no prior setup is required. The compile may
take some time (current rate is 10 hosts per second, with a
couple of seconds of constant overhead), and the possibility
of blocking on the compile lock.
If the 'only' parameter is provided, then it should be a
list or set containing the profiles that need to be compiled.
May raise ArgumentError exception, else returns the standard
output (as a string) of the compile
"""
config = Config()
if self.domain.branch_type == "sandbox":
if not self.author:
raise InternalError("Missing required author to compile " "sandbox %s" % self.domain.name)
sandboxdir = os.path.join(config.get("broker", "templatesdir"), self.author.name, self.domain.name)
if not os.path.exists(sandboxdir):
raise ArgumentError("Sandbox directory '%s' does not exist." % sandboxdir)
if not self.sandbox_has_latest(config, sandboxdir):
self.logger.warn(
"Sandbox %s/%s does not contain the "
"latest changes from the prod domain. If "
"there are failures try "
"`git fetch && git merge origin/prod`" % (self.author.name, self.domain.name)
)
self.logger.info("preparing domain %s for compile" % self.domain.name)
# Ensure that the compile directory is in a good state.
outputdir = config.get("broker", "profilesdir")
for d in self.directories() + self.outputdirs():
if not os.path.exists(d):
try:
self.logger.info("creating %s" % d)
os.makedirs(d)
except OSError, e:
raise ArgumentError("Failed to mkdir %s: %s" % (d, e))
示例10: cache_storage_data
# 需要导入模块: from aquilon.config import Config [as 别名]
# 或者: from aquilon.config.Config import get [as 别名]
def cache_storage_data(only=None):
"""
Scan a storeng-style data file, checking each line as we go
Storeng-style data files are blocks of data. Each block starts
with a comment describing the fields for all subsequent lines. A
block can start at any time. Fields are separated by '|'.
This function will invoke the function after parsing every data
line. The function will be called with a dict of the fields. If the
function returns True, then we stop scanning the file, else we continue
on until there is nothing left to parse.
dbshare can be a Share
"""
config = Config()
sharedata = {}
found_header = False
header_idx = {}
with open(config.get("broker", "sharedata")) as datafile:
for line in datafile:
if line[0] == '#':
# A header line
found_header = True
hdr = line[1:].rstrip().split('|')
header_idx = {}
for idx, name in enumerate(hdr):
header_idx[name] = idx
# Silently discard lines that don't have all the required info
for k in ["objtype", "pshare", "server", "dg"]:
if k not in header_idx:
found_header = False
elif not found_header:
# We haven't found the right header line
continue
else:
fields = line.rstrip().split('|')
if len(fields) != len(header_idx): # Silently ignore invalid lines
continue
if fields[header_idx["objtype"]] != "pshare":
continue
sharedata[fields[header_idx["pshare"]]] = ShareInfo(
server=fields[header_idx["server"]],
mount="/vol/%s/%s" % (fields[header_idx["dg"]],
fields[header_idx["pshare"]])
)
# Take a shortcut if we need just a single entry
if only and only == fields[header_idx["pshare"]]:
break
return sharedata
示例11: _snapshot_db
# 需要导入模块: from aquilon.config import Config [as 别名]
# 或者: from aquilon.config.Config import get [as 别名]
def _snapshot_db(self, test):
# If there was an error, and we're using SQLite, create a snapshot
# TODO: create a git-managed snapshot of the plenaries/profiles as well
config = Config()
dsn = config.get("database", "dsn")
if dsn.startswith("sqlite:///"):
dbfile = dsn[10:]
target = dbfile + ".%s:%s" % (test.__class__.__name__,
test._testMethodName)
call(["/bin/cp", "-a", dbfile, target])
示例12: directories
# 需要导入模块: from aquilon.config import Config [as 别名]
# 或者: from aquilon.config.Config import get [as 别名]
def directories(self):
"""Return a list of directories required for compiling this domain"""
config = Config()
dirs = []
if self.domain.branch_type == 'domain':
dirs.append(os.path.join(config.get("broker", "domainsdir"),
self.domain.name))
dirs.append(os.path.join(config.get("broker", "cfgdir"),
"domains", self.domain.name))
# This is a bit redundant. When creating the directories, the "clusters"
# subdir would be enough; when removing them, the base dir would be
# enough. Having both does not hurt and does not need such extra logic.
dirs.append(os.path.join(config.get("broker", "quattordir"),
"build", self.domain.name))
dirs.append(os.path.join(config.get("broker", "quattordir"),
"build", self.domain.name, "clusters"))
return dirs
示例13: testcloneswrep
# 需要导入模块: from aquilon.config import Config [as 别名]
# 或者: from aquilon.config.Config import get [as 别名]
def testcloneswrep(self):
config = Config()
source = config.get("unittest", "swrep_repository")
dest = os.path.join(config.get("broker", "swrepdir"), "repository")
p = Popen(("/bin/rm", "-rf", dest), stdout=1, stderr=2)
rc = p.wait()
self.assertEqual(rc, 0,
"Failed to clear old swrep directory '%s'" %
dest)
env = {}
env["PATH"] = "%s:%s" % (config.get("broker", "git_path"),
os.environ.get("PATH", ""))
p = Popen(("git", "clone", source, dest),
env=env, stdout=PIPE, stderr=PIPE)
(out, err) = p.communicate()
# Ignore out/err unless we get a non-zero return code, then log it.
self.assertEqual(p.returncode, 0,
"Non-zero return code for clone of swrep, "
"STDOUT:\[email protected]@@\n'%s'\[email protected]@@\nSTDERR:\[email protected]@@\n'%s'\[email protected]@@\n"
% (out, err))
return
示例14: main
# 需要导入模块: from aquilon.config import Config [as 别名]
# 或者: from aquilon.config.Config import get [as 别名]
def main():
parser = argparse.ArgumentParser(description="Send out broker notifications")
parser.add_argument("-c", "--config", dest="config",
help="location of the broker configuration file")
parser.add_argument("--one_shot", action="store_true",
help="do just a single run and then exit")
parser.add_argument("--debug", action="store_true",
help="turn on debug logs on stderr")
opts = parser.parse_args()
config = Config(configfile=opts.config)
# These modules must be imported after the configuration has been
# initialized
from aquilon.aqdb.db_factory import DbFactory
db = DbFactory()
if opts.debug:
level = logging.DEBUG
logging.basicConfig(level=level, stream=sys.stderr,
format='%(asctime)s [%(levelname)s] %(message)s')
else:
level = logging.INFO
logfile = os.path.join(config.get("broker", "logdir"), "aq_notifyd.log")
handler = WatchedFileHandler(logfile)
handler.setLevel(level)
formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')
handler.setFormatter(formatter)
rootlog = logging.getLogger()
rootlog.addHandler(handler)
rootlog.setLevel(level)
# Apply configured log settings
for logname, level in config.items("logging"):
if level not in logging._levelNames:
continue
logging.getLogger(logname).setLevel(logging._levelNames[level])
logger = logging.getLogger("aq_notifyd")
if opts.one_shot:
update_index_and_notify(config, logger, db)
else:
signal.signal(signal.SIGTERM, exit_handler)
signal.signal(signal.SIGINT, exit_handler)
run_loop(config, logger, db)
示例15: testdisabletemplatetests
# 需要导入模块: from aquilon.config import Config [as 别名]
# 或者: from aquilon.config.Config import get [as 别名]
def testdisabletemplatetests(self):
config = Config()
kingdir = config.get("broker", "kingdir")
rundir = config.get("broker", "rundir")
env = {}
env["PATH"] = "%s:%s" % (config.get("broker", "git_path"),
os.environ.get("PATH", ""))
tempdir = mkdtemp(prefix="fixup", dir=rundir)
p = Popen(("git", "clone", "--shared", kingdir, "template-king",
"--branch", "prod"),
cwd=tempdir, env=env, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
self.assertEqual(p.returncode, 0, "Failed to clone template-king")
repodir = os.path.join(tempdir, "template-king")
makefile = os.path.join(repodir, "Makefile")
if os.path.exists(os.path.join(repodir, "t", "Makefile")):
p = Popen(("git", "rm", "-f", os.path.join("t", "Makefile")),
cwd=repodir, env=env, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
self.assertEqual(p.returncode, 0, "Failed to remove t/Makefile")
p = Popen(("git", "commit", "-m", "Removed t/Makefile"),
cwd=repodir, env=env, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
self.assertEqual(p.returncode, 0, "Failed to commit removal of t/Makefile")
for branch in ['prod', 'ny-prod']:
p = Popen(("git", "push", "origin", "prod:%s" % branch),
cwd=repodir, env=env, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
self.assertEqual(p.returncode, 0,
"Failed to push to %s, "
"STDOUT:\[email protected]@@\n'%s'\[email protected]@@\nSTDERR:\[email protected]@@\n'%s'\[email protected]@@\n"
% (branch, out, err))
p = Popen(("rm", "-rf", tempdir))
p.communicate()