Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python/gcp-compute/get_compute_engine_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

def get_compute_instances(project_id):
""" Prints all the google compute instances of a project """

instance_client = compute_v1.InstancesClient()

request = compute_v1.AggregatedListInstancesRequest()
request.project = project_id
request.max_results = 50
Expand All @@ -24,4 +24,4 @@ def main():
get_compute_instances(args.project_id)

if __name__ == "__main__":
main()
main()
31 changes: 31 additions & 0 deletions python/gcp-compute/list_vms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from google.cloud import compute_v1

def list_vms(project_id, instance_zone):
""" Prints all the google compute instances of a project """

# Empty list to store instance names
instance_names = []

# Create a client
client = compute_v1.InstancesClient()

# Initialize request argument(s)
request = compute_v1.ListInstancesRequest(
project=project_id,
zone=instance_zone,
)

# Make the request
page_result = client.list(request=request)

# Handle the response
for response in page_result:
print(response.name)
instance_names.append(response.name)

return instance_names

if __name__ == "__main__":
project_id = "tidal-outlook-488409-e6"
instance_zone = "us-central1-c"
list_vms(project_id, instance_zone)
2 changes: 1 addition & 1 deletion python/gcp-compute/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
requests
google-cloud-compute==1.11.0
google-cloud-resource-manager==1.10.1
google-cloud-resource-manager==1.10.1