1. fabric-cli does not produce valid JSON

fabric-cli does not produce valid JSON

Home Forums FABRIC General Questions and Discussion fabric-cli does not produce valid JSON

Tagged: 

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #3080
    Timothy Middelkoop
    Participant

      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.

      #3111
      Ilya Baldin
      Participant

        Timothy,

        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?

        #3125
        Timothy Middelkoop
        Participant

          I 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.

           

          #3126
          Ilya Baldin
          Participant

            Absolutely! We would love to get community contributions to the code.

            #3142
            Timothy Middelkoop
            Participant
              #3149

              This 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. 🙂

              #3150
              Timothy Middelkoop
              Participant

                I 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 😀

                 

                #3246
                Komal Thareja
                Participant

                  Thank 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.

                  #3270
                  Komal Thareja
                  Participant

                    JupyterHub has been updated with the CLI containing the fixes for JSON outputs.

                  Viewing 9 posts - 1 through 9 (of 9 total)
                  • You must be logged in to reply to this topic.