Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
georgiyekkert authored Aug 23, 2021
2 parents bcf1f31 + 691e38e commit ec2f9a7
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions samples/snippets/sample_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# [START compute_images_list_page ]
# [START compute_images_list ]
# [START compute_images_list_page]
# [START compute_images_list]
import google.cloud.compute_v1 as compute_v1
# [END compute_images_list ]
# [END compute_images_list_page ]
# [END compute_images_list]
# [END compute_images_list_page]


# [START compute_images_list ]
# [START compute_images_list]
def print_images_list(project: str) -> None:
"""
Prints a list of all non-deprecated image names available in given project.
Expand All @@ -34,18 +34,18 @@ def print_images_list(project: str) -> None:
"""
images_client = compute_v1.ImagesClient()
# Listing only non-deprecated images to reduce the size of the reply.
images_list_request = compute_v1.ListImagesRequest(project=project, max_results=3,
images_list_request = compute_v1.ListImagesRequest(project=project, max_results=100,
filter="deprecated.state != DEPRECATED")

# Although the `max_results` parameter is specified in the request, the iterable returned
# by the `list()` method hides the pagination mechanic. The library makes multiple
# requests to the API for you, so you can simply iterate over all the images.
for img in images_client.list(request=images_list_request):
print(f" - {img.name}")
# [END compute_images_list ]
# [END compute_images_list]


# [START compute_images_list_page ]
# [START compute_images_list_page]
def print_images_list_by_page(project: str, page_size: int = 10) -> None:
"""
Prints a list of all non-deprecated image names available in a given project,
Expand All @@ -70,7 +70,7 @@ def print_images_list_by_page(project: str, page_size: int = 10) -> None:
print(f"Page {page_num}: ")
for img in page.items:
print(f" - {img.name}")
# [END compute_images_list_page ]
# [END compute_images_list_page]


if __name__ == '__main__':
Expand Down

0 comments on commit ec2f9a7

Please sign in to comment.