~yolanda.robla/nova/precise-security

« back to all changes in this revision

Viewing changes to nova/api/openstack/compute/contrib/security_groups.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-06-05 09:50:59 UTC
  • mto: (79.1.1 precise-proposed)
  • mto: This revision was merged to the branch mainline in revision 81.
  • Revision ID: package-import@ubuntu.com-20120605095059-kb1utt7b1a5yff2a
Tags: upstream-2012.1+stable~20120612-3ee026e
ImportĀ upstreamĀ versionĀ 2012.1+stable~20120612-3ee026e

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
from nova import exception
32
32
from nova import flags
33
33
from nova import log as logging
 
34
from nova import quota
34
35
from nova import utils
35
36
 
36
37
 
289
290
        group_name = group_name.strip()
290
291
        group_description = group_description.strip()
291
292
 
 
293
        if quota.allowed_security_groups(context, 1) < 1:
 
294
            msg = _("Quota exceeded, too many security groups.")
 
295
            raise exc.HTTPBadRequest(explanation=msg)
 
296
 
292
297
        LOG.audit(_("Create Security Group %s"), group_name, context=context)
293
298
        self.compute_api.ensure_default_security_group(context)
294
299
        if db.security_group_exists(context, context.project_id, group_name):
376
381
            msg = _('This rule already exists in group %s') % parent_group_id
377
382
            raise exc.HTTPBadRequest(explanation=msg)
378
383
 
 
384
        allowed = quota.allowed_security_group_rules(context,
 
385
                                                   parent_group_id,
 
386
                                                   1)
 
387
        if allowed < 1:
 
388
            msg = _("Quota exceeded, too many security group rules.")
 
389
            raise exc.HTTPBadRequest(explanation=msg)
 
390
 
379
391
        security_group_rule = db.security_group_rule_create(context, values)
380
392
        self.sgh.trigger_security_group_rule_create_refresh(
381
393
            context, [security_group_rule['id']])
485
497
                      to_port=to_port, msg="For ICMP, the"
486
498
                                           " type:code must be valid")
487
499
 
488
 
            values['protocol'] = ip_protocol
 
500
            values['protocol'] = ip_protocol.lower()
489
501
            values['from_port'] = from_port
490
502
            values['to_port'] = to_port
491
503
        else: