Fix: namespace loading and error messages
This commit is contained in:
parent
53f7584877
commit
e1c09e0c88
@ -228,6 +228,7 @@ class Kheops(GenericInstance):
|
|||||||
raise Exception("Need a valid config")
|
raise Exception("Need a valid config")
|
||||||
|
|
||||||
self.ns_name = namespace
|
self.ns_name = namespace
|
||||||
|
self.namespaces = {}
|
||||||
self.raw_config = self.parse_conf(config)
|
self.raw_config = self.parse_conf(config)
|
||||||
|
|
||||||
def parse_conf(self, config="kheops.yml"):
|
def parse_conf(self, config="kheops.yml"):
|
||||||
@ -264,6 +265,9 @@ class Kheops(GenericInstance):
|
|||||||
"""
|
"""
|
||||||
Lookup a key in hierarchy
|
Lookup a key in hierarchy
|
||||||
|
|
||||||
|
For a given lookup:
|
||||||
|
* keys= [<namespace>:<key>]
|
||||||
|
|
||||||
:param keys: List of keys to query.
|
:param keys: List of keys to query.
|
||||||
:type keys: list[str]
|
:type keys: list[str]
|
||||||
|
|
||||||
@ -271,6 +275,8 @@ class Kheops(GenericInstance):
|
|||||||
:type scope: dict
|
:type scope: dict
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ret = {}
|
ret = {}
|
||||||
# Loop over keys
|
# Loop over keys
|
||||||
for key_def in keys:
|
for key_def in keys:
|
||||||
@ -278,7 +284,7 @@ class Kheops(GenericInstance):
|
|||||||
key_def = key_def or ""
|
key_def = key_def or ""
|
||||||
|
|
||||||
# Identify namespace and key
|
# Identify namespace and key
|
||||||
parts = key_def.split(":")
|
parts = key_def.split("/")
|
||||||
ns_name = namespace or self.ns_name
|
ns_name = namespace or self.ns_name
|
||||||
if len(parts) > 1:
|
if len(parts) > 1:
|
||||||
ns_name = parts[0]
|
ns_name = parts[0]
|
||||||
@ -287,7 +293,15 @@ class Kheops(GenericInstance):
|
|||||||
key_name = parts[0]
|
key_name = parts[0]
|
||||||
|
|
||||||
# Load namespace
|
# Load namespace
|
||||||
ns_config = self.raw_config[ns_name]
|
if ns_name in self.namespaces:
|
||||||
|
ns_config = self.namespaces[ns_name]
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
ns_config = self.raw_config[ns_name]
|
||||||
|
except KeyError as err:
|
||||||
|
raise Exception(f"Unknown kheops namespace: {ns_name}")
|
||||||
|
|
||||||
|
print ("CREATE", ns_name, ns_config)
|
||||||
ns = KheopsNamespace(self, ns_name, ns_config)
|
ns = KheopsNamespace(self, ns_name, ns_config)
|
||||||
|
|
||||||
# Get result
|
# Get result
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user