Git Product home page Git Product logo

Comments (6)

kapaggar avatar kapaggar commented on September 6, 2024 1

Lists both public and private IP list of all your DO droplets

doctl compute droplet list -o json |jq -r '.[]| "\(.id)\t\(.name)\t\(.networks.v4[].ip_address)"'

List them in single line

doctl compute droplet list -o json |jq -r '.[]| "\(.id)\t\(.name)\t\(.networks.v4[]|select(.type=="public")|.ip_address)\t\(.networks.v4[]|select(.type=="private")|.ip_address)"'

from doctl.

vsviridov avatar vsviridov commented on September 6, 2024

MacGyver solution combinding doctl access credentials, APIv2, and jq

curl -s -X GET \
    -H "Content-Type: text/plain" \
    -H "Authorization: Bearer $(awk '{print $2}' < ~/.doctlcfg)" \
    "https://api.digitalocean.com/v2/droplets/${machine_id}" | \
        jq -r '.droplet.networks.v4[] | select(.type=="private") | .ip_address'

from doctl.

bryanl avatar bryanl commented on September 6, 2024

Yes, only the public IPv4 address is easily accessible, but there is still a way:

 doctl compute droplet get <dropletID> -o json \
  | jq -c '.[].networks.v4[] | select(.type=="private").ip_address'

You don't need curl. The key points here is that every command has JSON output than you can mangle with jq

from doctl.

vsviridov avatar vsviridov commented on September 6, 2024

Right, missed the fact that doctl provides json output (see my temporary solution above).
Still, would be nice to just have that and not depend on external dependency like jq

from doctl.

bryanl avatar bryanl commented on September 6, 2024

I think ultimately we shouldn't hardcode every single thing in, but if doctl provided a a way to get at the raw JSON a bit easier, it wouldn't be too bad. Perhaps the easy way would be allow go template, and JSON path support, so you could do something like

doctl compute droplet get <dropletID> --go-template="whatever" or
doctl compute droplet get <dropletID> --jsonpath="whatever"

from doctl.

bryanl avatar bryanl commented on September 6, 2024

Created new issues to add these two features in #95 and #96.

from doctl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.