Skip to content

Commit

Permalink
Added the find_images_by_name() method.
Browse files Browse the repository at this point in the history
This allows you to locate an image by specifying part of its name. The
search is done in a case-insensitive manner.

For example, if 'cs' represents the nova client, you can find all Ubuntu
images by calling:

    ubu_imgs = cs.find_images_by_name("ubun")

It support regular expressions, so if you wanted all PVHVM Ubuntu
images, you can call:

   ubu_phhvm_imgs = cs.find_images_by_name("ubu.+pvhvm")
  • Loading branch information
EdLeafe committed Jul 9, 2014
1 parent dfaa751 commit 4045210
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pyrax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import inspect
import logging
import os
import re
import six.moves.configparser as ConfigParser
import warnings

Expand Down Expand Up @@ -690,8 +691,19 @@ def list_snapshots():
return [image for image in cloudservers.images.list()
if hasattr(image, "server")]

def find_images_by_name(expr):
"""
Returns a list of images whose name contains the specified expression.
The value passed is treated as a regular expression, allowing for more
specific searches than simple wildcards. The matching is done in a
case-insensitive manner.
"""
return [image for image in cloudservers.images.list()
if re.search(expr, image.name, re.I)]

cloudservers.list_base_images = list_base_images
cloudservers.list_snapshots = list_snapshots
cloudservers.find_images_by_name = find_images_by_name
cloudservers.identity = identity
return cloudservers

Expand Down

0 comments on commit 4045210

Please sign in to comment.