Merge lp:~vishvananda/nova/lp721660 into lp:~hudson-openstack/nova/trunk

Proposed by Vish Ishaya
Status: Merged
Approved by: Jesse Andrews
Approved revision: 704
Merged at revision: 706
Proposed branch: lp:~vishvananda/nova/lp721660
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 153 lines (+15/-15)
5 files modified
nova/api/ec2/__init__.py (+1/-1)
nova/api/ec2/cloud.py (+10/-10)
nova/objectstore/bucket.py (+1/-1)
nova/objectstore/image.py (+1/-1)
nova/volume/api.py (+2/-2)
To merge this branch: bzr merge lp:~vishvananda/nova/lp721660
Reviewer Review Type Date Requested Status
Jesse Andrews (community) Approve
Devin Carlen (community) Approve
Rick Harris (community) Approve
Review via email: mp+50440@code.launchpad.net

Description of the change

Various optimizations of lookups relating to users.

To post a comment you must log in.
Revision history for this message
Rick Harris (rconradharris) wrote :

lgtm

review: Approve
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve
Revision history for this message
Jesse Andrews (anotherjesse) wrote :

I I can haz speed!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'nova/api/ec2/__init__.py'
--- nova/api/ec2/__init__.py 2011-02-13 18:45:20 +0000
+++ nova/api/ec2/__init__.py 2011-02-19 09:49:55 +0000
@@ -294,7 +294,7 @@
294 return True294 return True
295 if 'none' in roles:295 if 'none' in roles:
296 return False296 return False
297 return any(context.project.has_role(context.user.id, role)297 return any(context.project.has_role(context.user_id, role)
298 for role in roles)298 for role in roles)
299299
300300
301301
=== modified file 'nova/api/ec2/cloud.py'
--- nova/api/ec2/cloud.py 2011-02-15 00:51:51 +0000
+++ nova/api/ec2/cloud.py 2011-02-19 09:49:55 +0000
@@ -282,7 +282,7 @@
282 'description': 'fixme'}]}282 'description': 'fixme'}]}
283283
284 def describe_key_pairs(self, context, key_name=None, **kwargs):284 def describe_key_pairs(self, context, key_name=None, **kwargs):
285 key_pairs = db.key_pair_get_all_by_user(context, context.user.id)285 key_pairs = db.key_pair_get_all_by_user(context, context.user_id)
286 if not key_name is None:286 if not key_name is None:
287 key_pairs = [x for x in key_pairs if x['name'] in key_name]287 key_pairs = [x for x in key_pairs if x['name'] in key_name]
288288
@@ -290,7 +290,7 @@
290 for key_pair in key_pairs:290 for key_pair in key_pairs:
291 # filter out the vpn keys291 # filter out the vpn keys
292 suffix = FLAGS.vpn_key_suffix292 suffix = FLAGS.vpn_key_suffix
293 if context.user.is_admin() or \293 if context.is_admin or \
294 not key_pair['name'].endswith(suffix):294 not key_pair['name'].endswith(suffix):
295 result.append({295 result.append({
296 'keyName': key_pair['name'],296 'keyName': key_pair['name'],
@@ -301,7 +301,7 @@
301301
302 def create_key_pair(self, context, key_name, **kwargs):302 def create_key_pair(self, context, key_name, **kwargs):
303 LOG.audit(_("Create key pair %s"), key_name, context=context)303 LOG.audit(_("Create key pair %s"), key_name, context=context)
304 data = _gen_key(context, context.user.id, key_name)304 data = _gen_key(context, context.user_id, key_name)
305 return {'keyName': key_name,305 return {'keyName': key_name,
306 'keyFingerprint': data['fingerprint'],306 'keyFingerprint': data['fingerprint'],
307 'keyMaterial': data['private_key']}307 'keyMaterial': data['private_key']}
@@ -310,7 +310,7 @@
310 def delete_key_pair(self, context, key_name, **kwargs):310 def delete_key_pair(self, context, key_name, **kwargs):
311 LOG.audit(_("Delete key pair %s"), key_name, context=context)311 LOG.audit(_("Delete key pair %s"), key_name, context=context)
312 try:312 try:
313 db.key_pair_destroy(context, context.user.id, key_name)313 db.key_pair_destroy(context, context.user_id, key_name)
314 except exception.NotFound:314 except exception.NotFound:
315 # aws returns true even if the key doesn't exist315 # aws returns true even if the key doesn't exist
316 pass316 pass
@@ -318,7 +318,7 @@
318318
319 def describe_security_groups(self, context, group_name=None, **kwargs):319 def describe_security_groups(self, context, group_name=None, **kwargs):
320 self.compute_api.ensure_default_security_group(context)320 self.compute_api.ensure_default_security_group(context)
321 if context.user.is_admin():321 if context.is_admin:
322 groups = db.security_group_get_all(context)322 groups = db.security_group_get_all(context)
323 else:323 else:
324 groups = db.security_group_get_by_project(context,324 groups = db.security_group_get_by_project(context,
@@ -494,7 +494,7 @@
494 if db.security_group_exists(context, context.project_id, group_name):494 if db.security_group_exists(context, context.project_id, group_name):
495 raise exception.ApiError(_('group %s already exists') % group_name)495 raise exception.ApiError(_('group %s already exists') % group_name)
496496
497 group = {'user_id': context.user.id,497 group = {'user_id': context.user_id,
498 'project_id': context.project_id,498 'project_id': context.project_id,
499 'name': group_name,499 'name': group_name,
500 'description': group_description}500 'description': group_description}
@@ -674,7 +674,7 @@
674 else:674 else:
675 instances = self.compute_api.get_all(context, **kwargs)675 instances = self.compute_api.get_all(context, **kwargs)
676 for instance in instances:676 for instance in instances:
677 if not context.user.is_admin():677 if not context.is_admin:
678 if instance['image_id'] == FLAGS.vpn_image_id:678 if instance['image_id'] == FLAGS.vpn_image_id:
679 continue679 continue
680 i = {}680 i = {}
@@ -702,7 +702,7 @@
702 i['dnsName'] = i['publicDnsName'] or i['privateDnsName']702 i['dnsName'] = i['publicDnsName'] or i['privateDnsName']
703 i['keyName'] = instance['key_name']703 i['keyName'] = instance['key_name']
704704
705 if context.user.is_admin():705 if context.is_admin:
706 i['keyName'] = '%s (%s, %s)' % (i['keyName'],706 i['keyName'] = '%s (%s, %s)' % (i['keyName'],
707 instance['project_id'],707 instance['project_id'],
708 instance['host'])708 instance['host'])
@@ -736,7 +736,7 @@
736736
737 def format_addresses(self, context):737 def format_addresses(self, context):
738 addresses = []738 addresses = []
739 if context.user.is_admin():739 if context.is_admin:
740 iterator = db.floating_ip_get_all(context)740 iterator = db.floating_ip_get_all(context)
741 else:741 else:
742 iterator = db.floating_ip_get_all_by_project(context,742 iterator = db.floating_ip_get_all_by_project(context,
@@ -750,7 +750,7 @@
750 ec2_id = id_to_ec2_id(instance_id)750 ec2_id = id_to_ec2_id(instance_id)
751 address_rv = {'public_ip': address,751 address_rv = {'public_ip': address,
752 'instance_id': ec2_id}752 'instance_id': ec2_id}
753 if context.user.is_admin():753 if context.is_admin:
754 details = "%s (%s)" % (address_rv['instance_id'],754 details = "%s (%s)" % (address_rv['instance_id'],
755 floating_ip_ref['project_id'])755 floating_ip_ref['project_id'])
756 address_rv['instance_id'] = details756 address_rv['instance_id'] = details
757757
=== modified file 'nova/objectstore/bucket.py'
--- nova/objectstore/bucket.py 2010-11-29 12:14:26 +0000
+++ nova/objectstore/bucket.py 2011-02-19 09:49:55 +0000
@@ -107,7 +107,7 @@
107107
108 def is_authorized(self, context):108 def is_authorized(self, context):
109 try:109 try:
110 return context.user.is_admin() or \110 return context.is_admin or \
111 self.owner_id == context.project_id111 self.owner_id == context.project_id
112 except Exception, e:112 except Exception, e:
113 return False113 return False
114114
=== modified file 'nova/objectstore/image.py'
--- nova/objectstore/image.py 2011-01-20 17:52:02 +0000
+++ nova/objectstore/image.py 2011-02-19 09:49:55 +0000
@@ -69,7 +69,7 @@
69 # but only modified by admin or owner.69 # but only modified by admin or owner.
70 try:70 try:
71 return (self.metadata['isPublic'] and readonly) or \71 return (self.metadata['isPublic'] and readonly) or \
72 context.user.is_admin() or \72 context.is_admin or \
73 self.metadata['imageOwnerId'] == context.project_id73 self.metadata['imageOwnerId'] == context.project_id
74 except:74 except:
75 return False75 return False
7676
=== modified file 'nova/volume/api.py'
--- nova/volume/api.py 2011-02-04 10:26:28 +0000
+++ nova/volume/api.py 2011-02-19 09:49:55 +0000
@@ -49,7 +49,7 @@
4949
50 options = {50 options = {
51 'size': size,51 'size': size,
52 'user_id': context.user.id,52 'user_id': context.user_id,
53 'project_id': context.project_id,53 'project_id': context.project_id,
54 'availability_zone': FLAGS.storage_availability_zone,54 'availability_zone': FLAGS.storage_availability_zone,
55 'status': "creating",55 'status': "creating",
@@ -85,7 +85,7 @@
85 return self.db.volume_get(context, volume_id)85 return self.db.volume_get(context, volume_id)
8686
87 def get_all(self, context):87 def get_all(self, context):
88 if context.user.is_admin():88 if context.is_admin:
89 return self.db.volume_get_all(context)89 return self.db.volume_get_all(context)
90 return self.db.volume_get_all_by_project(context, context.project_id)90 return self.db.volume_get_all_by_project(context, context.project_id)
9191