Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

How to use Go template to fetch data from ignite inspect output? #587

Closed
zhuangh7 opened this issue Apr 19, 2020 · 4 comments
Closed

How to use Go template to fetch data from ignite inspect output? #587

zhuangh7 opened this issue Apr 19, 2020 · 4 comments

Comments

@zhuangh7
Copy link

Hi there, I'm not familar with Go template and I try to use '-t' of ignite inspect command.
I used to use Go template in docker inspect, and I can use command like:
docker inspect --format {{.NetworkSettings.Networks.bridge.IPAddress}} 1564bdd87437
to get the ip of the container

But when I use command like:
sudo ignite inspect -t '{{.status.ipAddresses}}' vm 24
it just response with an error:
FATA[0000] failed rendering template: template: :1:9: executing "" at <.status.ipAddresses>: can't evaluate field status in type *ignite.VM

Could you please give me some idea about how to use Go timeplate here?
Thank you!

@darkowlzz
Copy link
Contributor

Hi, thanks for opening an issue for this. It may be a good idea to add some examples in the command help, similar to the example usage in ignite ps command for using filters.

Ignite APIs are based on k8s api machinery. The API definition can be found here. Based on that, since it's go template, you can do something like:

# ignite run weaveworks/ignite-ubuntu --ssh --name=my-vm
...

# ignite inspect vm my-vm -t {{.Status.IPAddresses}}
10.61.0.114

# ignite inspect vm my-vm -t {{.ObjectMeta.Name}}
my-vm

# ignite inspect vm my-vm -t {{.Spec.Image.OCI}}
weaveworks/ignite-ubuntu:latest

Hope this helps.

@zhuangh7
Copy link
Author

Thanks for your help, the command works well. It is amazing that it can not work correctly if I just put the '-t' before specific the vm I want to inspect.
After all, thank you.

@stealthybox
Copy link
Contributor

@zhuangh7 We're going to open a bug and patch the command to add some examples in the command help text.

Thanks for opening this up and asking :)

(Yes, the flag ordering thing with cobra style CLI's and positional args can be funky to use. I struggle with this when editing commands with docker and kubectl as well which have the same usage)

@zhuangh7
Copy link
Author

@zhuangh7 We're going to open a bug and patch the command to add some examples in the command help text.

Thanks for opening this up and asking :)

(Yes, the flag ordering thing with cobra style CLI's and positional args can be funky to use. I struggle with this when editing commands with docker and kubectl as well which have the same usage)

Thanks for your contribution, it can be really helpful :>

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants