Home › Forums › FABRIC General Questions and Discussion › fabric-cli does not produce valid JSON
Tagged: cli
- This topic has 8 replies, 4 voices, and was last updated 2 years, 2 months ago by Komal Thareja.
-
AuthorPosts
-
September 16, 2022 at 1:30 pm #3080
The fabric-cli does not produce correct JSON. JSON key/value delimitors should be ” not ‘ (https://json.org)
(.venv) tmiddelkoop@tmiddelkoopsMBP fabric % fabric-cli slices query --state=StableOK [{'graph_id': 'bfe827e3-d0cd-4288-b281-799c40c8104e', 'lease_end_time': '2022-09-17 18:12:05 +0000', 'lease_start_time': '2022-09-16 18:12:06 +0000', 'model': None, 'name': 'oneslice', 'project_id': 'bf572b3b-1ea7-4a27-b9b7-11b62a9eaeaa', 'slice_id': '40874ad4-8bde-4d56-b4fc-878de35f0f6d', 'state': 'StableOK'}]
Installed on a MacBook (Intel) w/ brew via
python3.9 -m venv .venv # bugs w/ 3.10 . .venv/bin/activate python3 -m pip install --upgrade pip python3 -m pip install git+https://github.com/fabric-testbed/fabric-cli.git python3 -m pip install git+https://github.com/fabric-testbed/fabrictestbed-extensions.git
I did not easily find the installation instructions for the cli. I think there were instructions that included using specific branches/tags for the tools.
September 18, 2022 at 2:44 pm #3111Timothy,
I don’t think this is supposed to produce JSON – this just prints out Python data structures.
fabric_cli is a very low level tool – are you sure you want to be using it instead of FABlib and the notebooks?
September 19, 2022 at 8:26 am #3125I use Python directly most of the time but sometimes it’s nice to have a simple script to grab the IP of a slice/node from the command line. This is what I would do in the past to grab the management IP to then kick off some ssh based tools as follows (yes, I could write this in python but bash/jq is my hammer of choice):
SLICEID=$(fabric-cli slices query --state=StableOK | jq -r '.[0].slice_id') ; echo $SLICEID IP=$(fabric-cli slivers query --sliceid=$SLICEID | jq -r '.[0].sliver' | jq -r '.MgmtIp') ; echo $IP
Would you consider a pull request that did a json.dumps() to format the output?
Thanks.
September 19, 2022 at 9:10 am #3126Absolutely! We would love to get community contributions to the code.
September 20, 2022 at 6:55 pm #3142September 22, 2022 at 3:02 pm #3149This morning I too was wishing for JSON output from fabric-cli, for the same reasons stated above, and was pleased to find the PR. From the little quick test I did, output from the PR branch works quite well with jq.
I’ve left some comments on the PR. I would like to see the feature merged, but since I am not really familiar with the code, I probably shouldn’t be the one to approve the PR. That job is better left to more competent people. 🙂
September 22, 2022 at 4:29 pm #3150I just pushed an update to the PR
Thanks for the comments. I think I address most of the issues (I did not get mypy to work in the time I had allocated for this) but I added some conditions that should make a static checker happy and some other fixes.
I also just fixed
fabric-cli slices delete
– I did not test yesterday due to the workshop 😀October 2, 2022 at 2:50 pm #3246Thank you Timothy and Sajith for your contributions! Appreciate it! I have approved the PR and merged to the master branch. Will create a new release and push to Jupyter Hub.
October 6, 2022 at 3:04 pm #3270JupyterHub has been updated with the CLI containing the fixes for JSON outputs.
-
AuthorPosts
- You must be logged in to reply to this topic.