Skip to content

Instantly share code, notes, and snippets.

@Neutrollized
Created June 3, 2022 15:31
Show Gist options
  • Save Neutrollized/c34f676226a91d2f9ae13010e2c84957 to your computer and use it in GitHub Desktop.
Save Neutrollized/c34f676226a91d2f9ae13010e2c84957 to your computer and use it in GitHub Desktop.
Medium: Managing your GCP inventory with Cloud Asset API
def search_reserved_ips():
# create client
client = asset_v1.AssetServiceClient()
# init request
request = asset_v1.SearchAllResourcesRequest(
scope="projects/myproject-123",
asset_types=[
"compute.googleapis.com/Address",
],
query="NOT state:in_use",
)
# make request
page_result = client.search_all_resources(request=request)
# handle response
for response in page_result:
print(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment