Reputation: 335
How do I get the labels for all the resources in GCP with the use of api? Is there any specific api to access or view all the labels of all resources for a given project?
Upvotes: 2
Views: 719
Reputation: 3220
You can view labels for resources by using the Cloud Console, the gcloud tool, or the Compute Engine API. To view labels for forwarding rules, use the gcloud tool or the Compute Engine API.
To retrieve labels with the use of api, make a GET request to the following resource:
For VM instances, use the instances.setLabels() method.
For snapshots, use the snapshots.setLabels() method.
For images, use the images.setLabels() method.
For disks, use the disks.setLabels() method.
For forwarding rules, use the beta forwardingRules.setLabels() method.
For regional static external IP addresses, use the beta addresses.setLabels() method.
For global static external IP addresses, use the beta globalAddresses.setLabels() method.
For VPN tunnels, use the beta vpnTunnels.setLabels() method.
For example, the following snippet makes a GET request to retrieve labels for a VM instance:
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME
Refer to the document on Creating and Managing Labels.
Upvotes: 1