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(-) 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 From a1a1ee16992c0292de18828cd9bfc93d9bc6c1cc Mon Sep 17 00:00:00 2001 From: Devin Carlen Date: Fri, 28 Jan 2011 12:37:19 -0800 Subject: Fixed whitespace --- nova/adminclient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/adminclient.py b/nova/adminclient.py index 6b7549d26..dc949dd95 100644 --- a/nova/adminclient.py +++ b/nova/adminclient.py @@ -288,7 +288,7 @@ class NovaAdminClient(object): return self.apiconn.get_list('DescribeUsers', {}, [('item', UserInfo)]) def get_user(self, name): - """ grab a single user by name """ + """Grab a single user by name.""" try: return self.apiconn.get_object('DescribeUser', {'Name': name}, UserInfo) except boto.exception.BotoServerError, e: -- cgit From 6ed93f6116ed092e64ceef9a255b46167099bfc3 Mon Sep 17 00:00:00 2001 From: Devin Carlen Date: Sun, 30 Jan 2011 15:45:17 -0800 Subject: pep8 --- nova/adminclient.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nova/adminclient.py b/nova/adminclient.py index dc949dd95..4106f0f47 100644 --- a/nova/adminclient.py +++ b/nova/adminclient.py @@ -290,7 +290,9 @@ class NovaAdminClient(object): def get_user(self, name): """Grab a single user by name.""" try: - return self.apiconn.get_object('DescribeUser', {'Name': name}, UserInfo) + 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 -- cgit