最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

google cloud platform - gcloud command formatting - selecting values from a list - Stack Overflow

programmeradmin4浏览0评论

I'm trying to select some values, from the status of the cloud routers to show the bgp peerings, however while I can return the ASN number correctly, trying to get any other value from the same output is failing, and I don't know why.

My command: gcloud compute routers get-status router-2 --region northamerica-northeast1 --project my-project --format="value[separator=' → '](result.bestRoutes.asPaths.asLists,result.bestRoutes.asPaths.destRange,result.bestRoutes.asPaths.nextHopIp,result.bestRoutes.asPaths.priority)"

Results in the following, showing the correct ASN, but then the other values I'm expecting returned are missing. Also, the way the values are listed isn't really what I'm looking for. I want to get the 'ASN -> destRange -> nextHopIP' and then list the next ASN, and the same details.

[[65123]];[[65123]];[[65123]] ? ;; ? ;; ? ;;

When I do the extract, without formatting it, I can see the values all exist:

result:
  bestRoutes:
  - asPaths:
    - asLists:
      - 65123
      pathSegmentType: AS_SEQUENCE
    creationTimestamp: '2025-02-18T05:51:30.490-08:00'
    destRange: 10.0.0.0/8
    kind: compute#route
    network: 
    nextHopIp: 169.254.0.1
    nextHopOrigin: INCOMPLETE
    nextHopVpnTunnel: 
    priority: 100
    routeType: BGP
  - asPaths:
    - asLists:
      - 65123
      pathSegmentType: AS_SEQUENCE
    creationTimestamp: '2025-02-18T05:51:30.490-08:00'
    destRange: 192.168.0.0/16
    kind: compute#route
    network: 
    nextHopIp: 169.254.0.1
    nextHopOrigin: INCOMPLETE
    nextHopVpnTunnel: 
    priority: 100
    routeType: BGP

EDIT: I've sinced realised I need to use flatten, against the result.bestRoutes[] to get each ASN on it's own line, which has worked,

[65123] ?  ?  ? ;;;;;;;;;
[65123] ?  ?  ? ;;;;;;;;;
[65123] ?  ?  ? ;;;;;;;;;

But I still can't pull the other values that I also want?

I'm trying to select some values, from the status of the cloud routers to show the bgp peerings, however while I can return the ASN number correctly, trying to get any other value from the same output is failing, and I don't know why.

My command: gcloud compute routers get-status router-2 --region northamerica-northeast1 --project my-project --format="value[separator=' → '](result.bestRoutes.asPaths.asLists,result.bestRoutes.asPaths.destRange,result.bestRoutes.asPaths.nextHopIp,result.bestRoutes.asPaths.priority)"

Results in the following, showing the correct ASN, but then the other values I'm expecting returned are missing. Also, the way the values are listed isn't really what I'm looking for. I want to get the 'ASN -> destRange -> nextHopIP' and then list the next ASN, and the same details.

[[65123]];[[65123]];[[65123]] ? ;; ? ;; ? ;;

When I do the extract, without formatting it, I can see the values all exist:

result:
  bestRoutes:
  - asPaths:
    - asLists:
      - 65123
      pathSegmentType: AS_SEQUENCE
    creationTimestamp: '2025-02-18T05:51:30.490-08:00'
    destRange: 10.0.0.0/8
    kind: compute#route
    network: https://www.googleapis/compute/v1/projects/my-project/global/networks/my-vpc
    nextHopIp: 169.254.0.1
    nextHopOrigin: INCOMPLETE
    nextHopVpnTunnel: https://www.googleapis/compute/v1/projects/my-project/regions/northamerica-northeast1/vpnTunnels/my-tunnel-1
    priority: 100
    routeType: BGP
  - asPaths:
    - asLists:
      - 65123
      pathSegmentType: AS_SEQUENCE
    creationTimestamp: '2025-02-18T05:51:30.490-08:00'
    destRange: 192.168.0.0/16
    kind: compute#route
    network: https://www.googleapis/compute/v1/projects/my-project/global/networks/my-vpc
    nextHopIp: 169.254.0.1
    nextHopOrigin: INCOMPLETE
    nextHopVpnTunnel: https://www.googleapis/compute/v1/projects/my-project/regions/northamerica-northeast1/vpnTunnels/my-tunnel-1
    priority: 100
    routeType: BGP

EDIT: I've sinced realised I need to use flatten, against the result.bestRoutes[] to get each ASN on it's own line, which has worked,

[65123] ?  ?  ? ;;;;;;;;;
[65123] ?  ?  ? ;;;;;;;;;
[65123] ?  ?  ? ;;;;;;;;;

But I still can't pull the other values that I also want?

Share Improve this question edited 10 hours ago djsmiley2kStaysInside asked 13 hours ago djsmiley2kStaysInsidedjsmiley2kStaysInside 3162 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

I finally figured out that the values I was trying to extract weren't infact inunder the asPaths list, as I'd first read it.

Instead, using the correct formatting string worked

format="get(result.bestRoutes.asPaths.asLists,result.bestRoutes.destRange,result.bestRoutes.nextHopIp,result.bestRoutes.priority)"

发布评论

评论列表(0)

  1. 暂无评论