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

Ability to output ls/ps in json format #889

Merged
merged 1 commit into from
Aug 25, 2023
Merged

Conversation

giggsoff
Copy link
Collaborator

@giggsoff giggsoff commented Aug 13, 2023

Let's allow to use --format=json option to display lists in machine-readable format.

$ ./eden volume ls --format=json
[
    {
        "Name": "pedantic_ganguly_0_m_0",
        "UUID": "77a786a5-fc09-4b3d-946c-fbb4d77a72ce",
        "Image": "lfedge/eden-eclient:b1c1de6",
        "VolumeType": "CONTAINER",
        "Size": "82 MB",
        "MaxSize": "-",
        "AdamState": "IN_CONFIG",
        "EveState": "DELIVERED",
        "LastError": "",
        "Ref": "app: pedantic_ganguly",
        "MountPoint": "/",
        "OriginType": "VCOT_DOWNLOAD"
    }
]
$ ./eden network ls --format=json
[
    {
        "Name": "flamboyant_goldstine",
        "UUID": "c7b73fe8-f2eb-4304-b07a-9f8adcca8178",
        "NetworkType": "ZnetInstLocal",
        "CIDR": "10.11.12.0/24",
        "Stats": "rx:{totalPackets:570 totalBytes:54758} tx:{totalPackets:2260 totalBytes:2607824}",
        "AdamState": "IN_CONFIG",
        "EveState": "ACTIVATED",
        "Activated": true
    }
]
$ ./eden pod ps --format=json
[
    {
        "Name": "pedantic_ganguly",
        "UUID": "2877759b-5443-4952-b95e-004f244c87ad",
        "Image": "lfedge/eden-eclient:b1c1de6",
        "AdamState": "IN_CONFIG",
        "EVEState": "RUNNING",
        "InternalIP": [
            "10.11.12.2"
        ],
        "ExternalIP": "127.0.0.1",
        "InternalPort": "22",
        "ExternalPort": "8027",
        "MemoryUsed": 181,
        "MemoryAvail": 896,
        "CPUUsage": 0,
        "Macs": [
            "ce:5b:cd:11:50:0f"
        ],
        "Volumes": {
            "77a786a5-fc09-4b3d-946c-fbb4d77a72ce": 100
        }
    }
]

Copy link
Member

@uncleDecart uncleDecart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor yetus complaints and I didn't understand why we want to use string instead of strict type for some parameters when we can marshal those structures in JSON

infoTime time.Time
MemoryUsed uint32
MemoryAvail uint32
CpuUsage int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some Yetus complaints

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified, thank you

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now yetus is finally happy (with several nolint directives unfortunately)

@@ -17,7 +19,7 @@ import (
type NetInstState struct {
Name string
UUID string
NetworkType config.ZNetworkInstType
NetworkType string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we want to switch to string?

Copy link
Collaborator Author

@giggsoff giggsoff Aug 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my experiments I received value of variable here (some number), not a meaningful text (ZnetInstLocal from my sample). It is quite tricky to format it on-fly in marshaller.

@giggsoff giggsoff force-pushed the json-ps branch 3 times, most recently from d60e982 to 00976ee Compare August 18, 2023 16:30
Let's allow to use --format=json option to display lists
in machine-readable format.

```
$ ./eden volume ls --format=json
[
    {
        "Name": "pedantic_ganguly_0_m_0",
        "UUID": "77a786a5-fc09-4b3d-946c-fbb4d77a72ce",
        "Image": "lfedge/eden-eclient:b1c1de6",
        "VolumeType": "CONTAINER",
        "Size": "82 MB",
        "MaxSize": "-",
        "AdamState": "IN_CONFIG",
        "EveState": "DELIVERED",
        "LastError": "",
        "Ref": "app: pedantic_ganguly",
        "MountPoint": "/",
        "OriginType": "VCOT_DOWNLOAD"
    }
]
```

```
$ ./eden network ls --format=json
[
    {
        "Name": "flamboyant_goldstine",
        "UUID": "c7b73fe8-f2eb-4304-b07a-9f8adcca8178",
        "NetworkType": "ZnetInstLocal",
        "CIDR": "10.11.12.0/24",
        "Stats": "rx:{totalPackets:570 totalBytes:54758} tx:{totalPackets:2260 totalBytes:2607824}",
        "AdamState": "IN_CONFIG",
        "EveState": "ACTIVATED",
        "Activated": true
    }
]
```

```
$ ./eden pod ps --format=json
[
    {
        "Name": "pedantic_ganguly",
        "UUID": "2877759b-5443-4952-b95e-004f244c87ad",
        "Image": "lfedge/eden-eclient:b1c1de6",
        "AdamState": "IN_CONFIG",
        "EVEState": "RUNNING",
        "InternalIP": [
            "10.11.12.2"
        ],
        "ExternalIP": "127.0.0.1",
        "InternalPort": "22",
        "ExternalPort": "8027",
        "MemoryUsed": 181,
        "MemoryAvail": 896,
        "CPUUsage": 0,
        "Macs": [
            "ce:5b:cd:11:50:0f"
        ],
        "Volumes": {
            "77a786a5-fc09-4b3d-946c-fbb4d77a72ce": 100
        }
    }
]
```

Signed-off-by: Petr Fedchenkov <[email protected]>
Copy link
Member

@uncleDecart uncleDecart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@uncleDecart uncleDecart merged commit 4f562e4 into lf-edge:master Aug 25, 2023
6 of 9 checks passed
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.

2 participants