From 3f3f169d6b9cdf0b0d4dca308dbded38bf9a87b9 Mon Sep 17 00:00:00 2001 From: Devin Carlen Date: Fri, 28 Jan 2011 12:32:21 -0800 Subject: Made adminclient get_user return None instead of throwing EC2Exception if requested user not available --- nova/adminclient.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'nova/adminclient.py') diff --git a/nova/adminclient.py b/nova/adminclient.py index 3cdd8347f..6b7549d26 100644 --- a/nova/adminclient.py +++ b/nova/adminclient.py @@ -21,6 +21,7 @@ Nova User API client library. import base64 import boto +import boto.exception import httplib from boto.ec2.regioninfo import RegionInfo @@ -287,11 +288,13 @@ class NovaAdminClient(object): return self.apiconn.get_list('DescribeUsers', {}, [('item', UserInfo)]) def get_user(self, name): - """Grab a single user by name.""" - user = self.apiconn.get_object('DescribeUser', {'Name': name}, - UserInfo) - if user.username != None: - return user + """ grab a single user by name """ + try: + return self.apiconn.get_object('DescribeUser', {'Name': name}, UserInfo) + except boto.exception.BotoServerError, e: + if e.status == 400 and e.error_code == 'NotFound': + return None + raise def has_user(self, username): """Determine if user exists.""" -- cgit