ebsarr / packet

packet, a CLI tool to manage packet.net services
Other
40 stars 14 forks source link

Add usage example for querying #11

Closed alexellis closed 7 years ago

alexellis commented 7 years ago

How can I query public IPs from list-devices?

ebsarr commented 7 years ago

To my knowledge, there is no API to query public IPs by device id. The tool itself doesn't also provide this capability . You can however pipe the output to jq to filter the IPs assigned to the device:

IPv4

$ packet baremetal list-devices |jq '.[].ip_addresses[0]'
{
  "address_family": 4,
  "cidr": 31,
  "address": "147.75.203.139",
  "gateway": "147.75.203.138",
  "public": true,
  "network": "147.75.203.138",
  "netmask": "255.255.255.254"
}

IPv6

$ packet baremetal list-devices |jq '.[].ip_addresses[1]'
{
  "address_family": 6,
  "cidr": 127,
  "address": "2604:1380:1000:2300::1",
  "gateway": "2604:1380:1000:2300::",
  "public": true,
  "network": "2604:1380:1000:2300::",
  "netmask": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe"
}

They always come in the same order...

To view all IPs reserved for the project, you can use the network service:

$ packet network list-ip-reservations
[
    {
        "id": "d6a8c95b-090e-47ed-9b12-b59e7c6b0909",
        "network": "2604:1380:1:da00::",
        "address": "",
        "address_family": 6,
        "netmask": "ffff:ffff:ffff:ff00:0000:0000:0000:0000",
        "public": true,
        "cidr": 56,
        "management": false,
        "manageable": true,
        "addon": false,
        "bill": false,
        "assignments": [],
        "href": "/ips/d6a8c95b-090e-47ed-9b12-b59e7c6b0909"
    },
...