From 4045210d5175b6486a32aecc1fc4a49c20b4875b Mon Sep 17 00:00:00 2001 From: EdLeafe Date: Wed, 9 Jul 2014 08:32:24 -0500 Subject: [PATCH] Added the find_images_by_name() method. 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") --- pyrax/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pyrax/__init__.py b/pyrax/__init__.py index 6fd228f6..75b3f41e 100755 --- a/pyrax/__init__.py +++ b/pyrax/__init__.py @@ -34,6 +34,7 @@ import inspect import logging import os +import re import six.moves.configparser as ConfigParser import warnings @@ -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