~ttx/nova/lp724325

« back to all changes in this revision

Viewing changes to nova/api/ec2/cloud.py

  • Committer: Ken Pepple
  • Date: 2011-02-21 21:29:41 UTC
  • mfrom: (708 nova)
  • mto: This revision was merged to the branch mainline in revision 713.
  • Revision ID: ken.pepple@gmail.com-20110221212941-6n81tpeyna90erdb
merged trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
282
282
                                 'description': 'fixme'}]}
283
283
 
284
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
286
        if not key_name is None:
287
287
            key_pairs = [x for x in key_pairs if x['name'] in key_name]
288
288
 
290
290
        for key_pair in key_pairs:
291
291
            # filter out the vpn keys
292
292
            suffix = FLAGS.vpn_key_suffix
293
 
            if context.user.is_admin() or \
 
293
            if context.is_admin or \
294
294
               not key_pair['name'].endswith(suffix):
295
295
                result.append({
296
296
                    'keyName': key_pair['name'],
301
301
 
302
302
    def create_key_pair(self, context, key_name, **kwargs):
303
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
305
        return {'keyName': key_name,
306
306
                'keyFingerprint': data['fingerprint'],
307
307
                'keyMaterial': data['private_key']}
310
310
    def delete_key_pair(self, context, key_name, **kwargs):
311
311
        LOG.audit(_("Delete key pair %s"), key_name, context=context)
312
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
314
        except exception.NotFound:
315
315
            # aws returns true even if the key doesn't exist
316
316
            pass
318
318
 
319
319
    def describe_security_groups(self, context, group_name=None, **kwargs):
320
320
        self.compute_api.ensure_default_security_group(context)
321
 
        if context.user.is_admin():
 
321
        if context.is_admin:
322
322
            groups = db.security_group_get_all(context)
323
323
        else:
324
324
            groups = db.security_group_get_by_project(context,
494
494
        if db.security_group_exists(context, context.project_id, group_name):
495
495
            raise exception.ApiError(_('group %s already exists') % group_name)
496
496
 
497
 
        group = {'user_id': context.user.id,
 
497
        group = {'user_id': context.user_id,
498
498
                 'project_id': context.project_id,
499
499
                 'name': group_name,
500
500
                 'description': group_description}
674
674
        else:
675
675
            instances = self.compute_api.get_all(context, **kwargs)
676
676
        for instance in instances:
677
 
            if not context.user.is_admin():
 
677
            if not context.is_admin:
678
678
                if instance['image_id'] == FLAGS.vpn_image_id:
679
679
                    continue
680
680
            i = {}
702
702
            i['dnsName'] = i['publicDnsName'] or i['privateDnsName']
703
703
            i['keyName'] = instance['key_name']
704
704
 
705
 
            if context.user.is_admin():
 
705
            if context.is_admin:
706
706
                i['keyName'] = '%s (%s, %s)' % (i['keyName'],
707
707
                    instance['project_id'],
708
708
                    instance['host'])
736
736
 
737
737
    def format_addresses(self, context):
738
738
        addresses = []
739
 
        if context.user.is_admin():
 
739
        if context.is_admin:
740
740
            iterator = db.floating_ip_get_all(context)
741
741
        else:
742
742
            iterator = db.floating_ip_get_all_by_project(context,
750
750
                ec2_id = id_to_ec2_id(instance_id)
751
751
            address_rv = {'public_ip': address,
752
752
                          'instance_id': ec2_id}
753
 
            if context.user.is_admin():
 
753
            if context.is_admin:
754
754
                details = "%s (%s)" % (address_rv['instance_id'],
755
755
                                       floating_ip_ref['project_id'])
756
756
                address_rv['instance_id'] = details