DEFAULT_OUTPUT_DIR = "{}/../output".format(__path__[0])
RE_BASE = re.compile(r"(^base$)|(^base_)|(_base_)|(_base$)")
+INTRINSIC_FUNCTIONS = [
+ "get_resource",
+ "get_attr",
+ "str_replace",
+ "get_param",
+ "list_join",
+ "get_file",
+ "resource_facade",
+ "Fn::Select",
+ "repeat",
+ "digest",
+ "str_split",
+ "yaql",
+ "map_replace",
+ "map_merge",
+]
+
def is_base_module(template_path):
basename = os.path.basename(template_path).lower()
return decorator
-def categories(*categories):
+def categories(*all_of, any_of=None):
+ any_of = set(any_of) if any_of else set()
+ all_of = set(all_of) if all_of else set()
+
def decorator(func):
@funcutils.wraps(func)
def wrapper(*args, **kw):
return func(*args, **kw)
- wrapper.categories = categories
+ wrapper.all_categories = all_of
+ wrapper.any_categories = any_of
return wrapper
- decorator.categories = categories
+ decorator.all_categories = all_of
+ decorator.any_categories = any_of
return decorator
traverse(value, search_key, func, curr_path)
elif value == search_key:
func(curr_path, value)
+ elif search_key == data:
+ curr_path = path + [data]
+ func(curr_path, data)
def check_indices(pattern, values, value_type):
def prop_iterator(resource, *props):
- terminators = ["get_resource", "get_attr", "str_replace", "get_param"]
if "properties" in resource:
resource = resource.get("properties")
props = list(props)
- if isinstance(resource, dict) and any(x for x in terminators if x in resource):
+ if isinstance(resource, dict) and any(
+ x for x in INTRINSIC_FUNCTIONS if x in resource
+ ):
yield resource
else:
prop = resource.get(props.pop(0))
:param zip_path: path to valid zip file
:param target_dir: directory to unzip zip_path
"""
- check(zipfile.is_zipfile(zip_path), "{} is not a valid zipfile or does not exist".format(zip_path))
+ check(
+ zipfile.is_zipfile(zip_path),
+ "{} is not a valid zipfile or does not exist".format(zip_path),
+ )
archive = zipfile.ZipFile(zip_path)
if not os.path.exists(target_dir):
os.makedirs(target_dir, exist_ok=True)
"""
checks resource is a nova server
"""
- return isinstance(resource, dict) and "type" in resource and "properties" in resource and resource.get("type") == "OS::Nova::Server"
-
+ return (
+ isinstance(resource, dict)
+ and "type" in resource
+ and "properties" in resource
+ and resource.get("type") == "OS::Nova::Server"
+ )