Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json output for exec command #465

Merged
merged 7 commits into from
Jun 25, 2021
Merged

json output for exec command #465

merged 7 commits into from
Jun 25, 2021

Conversation

steiler
Copy link
Collaborator

@steiler steiler commented Jun 21, 2021

./containerlab exec -t lab-examples/clos02/clos02.clab.yml -j sr_cli "show interface mgmt0 brief | as json"

will provide. This is with no label selector applied, Hence you will get errors with the client containers.

Shall we also add the return code? in view that might also make sense.

root@ubuntu:/home/ubuntu/containerlab# ./containerlab exec -t lab-examples/clos02/clos02.clab.yml -j sr_cli "show interface mgmt0 brief | as json" | jq
{
  "/clab-clos02-client1": {
    "stderr": "",
    "stdout": "OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: \"sr_cli\": executable file not found in $PATH: unknown\r\n"
  },
  "/clab-clos02-client2": {
    "stderr": "",
    "stdout": "OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: \"sr_cli\": executable file not found in $PATH: unknown\r\n"
  },
  "/clab-clos02-client3": {
    "stderr": "",
    "stdout": "OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: \"sr_cli\": executable file not found in $PATH: unknown\r\n"
  },
  "/clab-clos02-client4": {
    "stderr": "",
    "stdout": "OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: \"sr_cli\": executable file not found in $PATH: unknown\r\n"
  },
  "/clab-clos02-leaf1": {
    "stderr": "",
    "stdout": {
      "IfBrief": [
        {
          "Admin State": "enable",
          "Oper State": "up",
          "Port": "mgmt0",
          "Speed": "1G"
        }
      ]
    }
  },
  "/clab-clos02-leaf2": {
    "stderr": "",
    "stdout": {
      "IfBrief": [
        {
          "Admin State": "enable",
          "Oper State": "up",
          "Port": "mgmt0",
          "Speed": "1G"
        }
      ]
    }
  },
  "/clab-clos02-leaf3": {
    "stderr": "",
    "stdout": {
      "IfBrief": [
        {
          "Admin State": "enable",
          "Oper State": "up",
          "Port": "mgmt0",
          "Speed": "1G"
        }
      ]
    }
  },
  "/clab-clos02-leaf4": {
    "stderr": "",
    "stdout": {
      "IfBrief": [
        {
          "Admin State": "enable",
          "Oper State": "up",
          "Port": "mgmt0",
          "Speed": "1G"
        }
      ]
    }
  },
  "/clab-clos02-spine1": {
    "stderr": "",
    "stdout": {
      "IfBrief": [
        {
          "Admin State": "enable",
          "Oper State": "up",
          "Port": "mgmt0",
          "Speed": "1G"
        }
      ]
    }
  },
  "/clab-clos02-spine2": {
    "stderr": "",
    "stdout": {
      "IfBrief": [
        {
          "Admin State": "enable",
          "Oper State": "up",
          "Port": "mgmt0",
          "Speed": "1G"
        }
      ]
    }
  },
  "/clab-clos02-spine3": {
    "stderr": "",
    "stdout": {
      "IfBrief": [
        {
          "Admin State": "enable",
          "Oper State": "up",
          "Port": "mgmt0",
          "Speed": "1G"
        }
      ]
    }
  },
  "/clab-clos02-spine4": {
    "stderr": "",
    "stdout": {
      "IfBrief": [
        {
          "Admin State": "enable",
          "Oper State": "up",
          "Port": "mgmt0",
          "Speed": "1G"
        }
      ]
    }
  },
  "/clab-clos02-superspine1": {
    "stderr": "",
    "stdout": {
      "IfBrief": [
        {
          "Admin State": "enable",
          "Oper State": "up",
          "Port": "mgmt0",
          "Speed": "1G"
        }
      ]
    }
  },
  "/clab-clos02-superspine2": {
    "stderr": "",
    "stdout": {
      "IfBrief": [
        {
          "Admin State": "enable",
          "Oper State": "up",
          "Port": "mgmt0",
          "Speed": "1G"
        }
      ]
    }
  }
}

@steiler
Copy link
Collaborator Author

steiler commented Jun 21, 2021

implementation of #463.
If the returned string can not be parsed as json, it is returned as a string field.
just stdout is tried to parse, stderr is always a string field.

Do we need a specific field indicating of under stdout we have a string or a json struct?

@hellt
Copy link
Member

hellt commented Jun 21, 2021 via email

@steiler
Copy link
Collaborator Author

steiler commented Jun 22, 2021

@hellt changed it to -f / --format [plain, json]

@hellt hellt changed the title -j/--json flag added to exec command json output for exec command Jun 23, 2021
@hellt
Copy link
Member

hellt commented Jun 23, 2021

I think it is safe to rebase this request on top of #469 to incorporate the changes Karim made

@hellt
Copy link
Member

hellt commented Jun 24, 2021

I've made a --cmd flag to be in line with all the rest of commands, and merged the current master
also added a doc entry

it looks ok to me at this moment, @steiler you can check this and if it is all ok, feel free to merge

@hellt hellt merged commit 828c564 into master Jun 25, 2021
@hellt hellt deleted the execjson branch June 29, 2022 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants