import novaclient.exceptions for cs.images.find

cs.images.find(human_id= throws novaclient.exceptions.NotFound,
resulting in the try/except block with
image = cs.images.find(name=image)  being skipped. catching
novaclient.exception.NotFound allows images to be specified with the
human readable name.

Example:
  tasks:
    - name: Server build request
      local_action:
        module: rax
        region: DFW
        image: Ubuntu 12.04 LTS (Precise Pangolin)

Also, the import is placed after try: import pyrax, because pyrax
imports novaclient and should fail if novaclient is missing.
This commit is contained in:
Troy C 2013-12-13 16:27:21 -06:00
parent 76c3055986
commit c2d34efd21

View file

@ -162,6 +162,8 @@ except ImportError:
print("failed=True msg='pyrax is required for this module'")
sys.exit(1)
import novaclient.exceptions
ACTIVE_STATUSES = ('ACTIVE', 'BUILD', 'HARD_REBOOT', 'MIGRATING', 'PASSWORD',
'REBOOT', 'REBUILD', 'RESCUE', 'RESIZE', 'REVERT_RESIZE')
FINAL_STATUSES = ('ACTIVE', 'ERROR')
@ -366,11 +368,13 @@ def cloudservers(module, state, name, flavor, image, meta, key_name, files,
except ValueError:
try:
image = cs.images.find(human_id=image)
except (pyrax.exceptions.NotFound,
except (novaclient.exceptions.NotFound,
pyrax.exceptions.NotFound,
pyrax.exceptions.NoUniqueMatch):
try:
image = cs.images.find(name=image)
except (pyrax.exceptions.NotFound,
except (novaclient.exceptions.NotFound,
pyrax.exceptions.NotFound,
pyrax.exceptions.NoUniqueMatch):
module.fail_json(msg='No matching image found (%s)' %
image)