def lookup()

in geneve/stack/__init__.py [0:0]


def lookup(stack_ref):
    """Return the stack referred by stack_ref

    If stack_ref is a number, the stack is searched among the configured ones
    If it's a single letter, it's searched among the discovered ones
    If it's a string, its name is searched in the configured stacks first, then in the discovered ones
    """

    import string

    if isinstance(stack_ref, int) and stack_ref >= 0:
        return load_from_config(configurations()[stack_ref])
    if isinstance(stack_ref, str) and len(stack_ref) == 1:
        pos = string.ascii_letters.find(stack_ref)
        if pos >= 0:
            return discover()[pos]
    if isinstance(stack_ref, str) and len(stack_ref) > 1:
        for config in configurations():
            if config["name"] == stack_ref:
                return load_from_config(config)
        for stack in discover():
            if stack.name == stack_ref:
                return stack
    raise ValueError(f"Invalid stack reference: {stack_ref}")