Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/xr1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: eoscommand-1
spec:
endpoint: ceos01.default.svc.cluster.local
removeContainer: false
removeSection: false
cmds:
no spanning-tree vlan-id 4093-4094: {}
ip prefix-list PL-Loopback0:
Expand Down
2 changes: 1 addition & 1 deletion example/xr2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: eoscommand-2
spec:
endpoint: ceos01.default.svc.cluster.local
removeContainer: true
removeSection: true
cmds:
no spanning-tree vlan-id 4093-4094: {}
ip prefix-list PL-Loopback0:
Expand Down
10 changes: 5 additions & 5 deletions function/fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def RunFunction(
observed_xr_namespace = observed_xr.get("metadata").get("namespace")
fqdn = observed_xr["spec"].get("endpoint")
cmds = observed_xr["spec"].get("cmds")
remove_container = observed_xr["spec"].get("removeContainer")
remove_section = observed_xr["spec"].get("removeSection")

environment = resource.struct_to_dict(
req.context["apiextensions.crossplane.io/environment"]
Expand Down Expand Up @@ -98,7 +98,7 @@ async def RunFunction(
"cmds": [
"enable",
"configure",
*build_remove_path(path, remove_container=remove_container),
*build_remove_path(path, remove_section=remove_section),
],
}
jsonrpc_remove = request_json("runCmds", params=jsonrpc_remove_params)
Expand Down Expand Up @@ -138,12 +138,12 @@ def toggle_no(cmd: str) -> str:
return cmd.removeprefix("no ") if cmd.startswith("no ") else f"no {cmd}"


def build_remove_path(path: list[str], *, remove_container: bool = False) -> list[str]:
def build_remove_path(path: list[str], *, remove_section: bool = False) -> list[str]:
"""Create cmd for remove op."""
head, *tail = path

# remove the container
if remove_container and tail:
# remove the whole enclosing section, not just the setting inside it
if remove_section and tail:
return [f"no {head}"]

# remove nested items
Expand Down