oci-utils icon indicating copy to clipboard operation
oci-utils copied to clipboard

oci-public-ip -j doesn't print valid json, -g has extra text

Open cpoczatek opened this issue 2 years ago • 3 comments

In some situations, it looks like warning messages are getting sent to stdout when they should maybe get sent to stderr. I don't know why this warning appears either, as it's a vanilla instance in IAD with 1 vnic. Actual ip obfuscated.

sudo dnf list installed | grep utils | grep oci
oci-utils.noarch                         0.14.0-2.el8                                @ol8_oci_included 

oci-public-ip -j
No public ip addresses found from OCI, falling back to the stun servers.
The stun servers do not provide details on the vNIC and might find only the primary IP address.

[{"IP Address": "XXX"}]

oci-public-ip -j 2>/dev/null
No public ip addresses found from OCI, falling back to the stun servers.
The stun servers do not provide details on the vNIC and might find only the primary IP address.

[{"IP Address": "XXX"}]

oci-public-ip -j 2>/dev/null | jq .
parse error: Invalid numeric literal at line 1, column 3

oci-public-ip -g
No public ip addresses found from OCI, falling back to the stun servers.
The stun servers do not provide details on the vNIC and might find only the primary IP address.

   XXX

oci-public-ip -g 2>/dev/null
No public ip addresses found from OCI, falling back to the stun servers.
The stun servers do not provide details on the vNIC and might find only the primary IP address.

   XXX

cpoczatek avatar Feb 17 '23 20:02 cpoczatek

The message on using the stun servers is not warning, it is informational, in situations where you cannot get the public ip data from OCI, it falls back to scanning, which does not guarantee all data is found. the -j and -g options (which are both deprecated) work fine on the test env, oci-utils 0.14.0-2 `# oci-public-ip --help usage: oci-public-ip [--output-mode {parsable,table,json,text}] [-d] [-s SOURCEIP] [-S STUN_SERVER] [-L] [--instance-id OCID] [--help]

Utility for displaying the public IP address of the current OCI instance.

optional arguments: --output-mode {parsable,table,json,text} Set output mode -d, --details display details information -s SOURCEIP, --sourceip SOURCEIP Specify the source IP address to use -S STUN_SERVER, --stun-server STUN_SERVER Specify the STUN server to use -L, --list-servers Print a list of known STUN servers and exit --instance-id OCID Display the public IP address of the given instance instead of the current one. Requires the OCI Python SDK to be installed and configured `

guidotijskens avatar Feb 20 '23 08:02 guidotijskens

Ok, it's informational but it should still go to stderr imo. If -j/-g are deprecated, there's no warning that they are on use.

Am I correct in assuming the ability to get public ip data "from OCI" means there's an instance principal (or similar) to allow API calls? I would say the base case of just having created an instance is the simpler situation and should give valid json even if it's not guaranteed.

oci-public-ip --output-mode json | jq .
parse error: Invalid numeric literal at line 1, column 3
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
BrokenPipeError: [Errno 32] Broken pipe

cpoczatek avatar Feb 22 '23 17:02 cpoczatek

I agree it the information should go to stderr; . the public ip is not in the metadata, if you do not have instance principal nor direct authentication set up, the only way is using stun servers. I cannot reproduce your output...

oci-public-ip -S stun.stunprotocol.org --output-mode json|jq

[ { "IP Address": "www.xxx.yyy.zzz" } ] please file a ticket at oracle

guidotijskens avatar Feb 23 '23 15:02 guidotijskens