~0x44/nova/extdoc

« back to all changes in this revision

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

  • Committer: Lvov Maxim
  • Date: 2011-07-26 05:50:05 UTC
  • mfrom: (1320 nova)
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: usrleon@gmail.com-20110726055005-7olsp0giqup3pao7
merge with trunk, resolve conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
530
530
            g['ipPermissions'] += [r]
531
531
        return g
532
532
 
533
 
    def _revoke_rule_args_to_dict(self, context, to_port=None, from_port=None,
 
533
    def _rule_args_to_dict(self, context, kwargs):
 
534
        rules = []
 
535
        if not 'groups' in kwargs and not 'ip_ranges' in kwargs:
 
536
            rule = self._rule_dict_last_step(context, **kwargs)
 
537
            if rule:
 
538
                rules.append(rule)
 
539
            return rules
 
540
        if 'ip_ranges' in kwargs:
 
541
            rules = self._cidr_args_split(kwargs)
 
542
        finalset = []
 
543
        for rule in rules:
 
544
            if 'groups' in rule:
 
545
                groups_values = self._groups_args_split(rule)
 
546
                for groups_value in groups_values:
 
547
                    finalset.append(groups_value)
 
548
            else:
 
549
                if rule:
 
550
                    finalset.append(rule)
 
551
        return finalset
 
552
 
 
553
    def _cidr_args_split(self, kwargs):
 
554
        cidr_args_split = []
 
555
        cidrs = kwargs['ip_ranges']
 
556
        for key, cidr in cidrs.iteritems():
 
557
            mykwargs = kwargs.copy()
 
558
            del mykwargs['ip_ranges']
 
559
            mykwargs['cidr_ip'] = cidr['cidr_ip']
 
560
            cidr_args_split.append(mykwargs)
 
561
        return cidr_args_split
 
562
 
 
563
    def _groups_args_split(self, kwargs):
 
564
        groups_args_split = []
 
565
        groups = kwargs['groups']
 
566
        for key, group in groups.iteritems():
 
567
            mykwargs = kwargs.copy()
 
568
            del mykwargs['groups']
 
569
            if 'group_name' in group:
 
570
                mykwargs['source_security_group_name'] = group['group_name']
 
571
            if 'user_id' in group:
 
572
                mykwargs['source_security_group_owner_id'] = group['user_id']
 
573
            if 'group_id' in group:
 
574
                mykwargs['source_security_group_id'] = group['group_id']
 
575
            groups_args_split.append(mykwargs)
 
576
        return groups_args_split
 
577
 
 
578
    def _rule_dict_last_step(self, context, to_port=None, from_port=None,
534
579
                                  ip_protocol=None, cidr_ip=None, user_id=None,
535
580
                                  source_security_group_name=None,
536
581
                                  source_security_group_owner_id=None):
615
660
        msg = "Revoke security group ingress %s"
616
661
        LOG.audit(_(msg), security_group['name'], context=context)
617
662
 
618
 
        criteria = self._revoke_rule_args_to_dict(context, **kwargs)
 
663
        criteria = self._rule_args_to_dict(context, kwargs)[0]
619
664
        if criteria is None:
620
665
            raise exception.ApiError(_("Not enough parameters to build a "
621
666
                                       "valid rule."))
656
701
 
657
702
        msg = "Authorize security group ingress %s"
658
703
        LOG.audit(_(msg), security_group['name'], context=context)
659
 
        values = self._revoke_rule_args_to_dict(context, **kwargs)
660
 
        if values is None:
661
 
            raise exception.ApiError(_("Not enough parameters to build a "
662
 
                                       "valid rule."))
663
 
        values['parent_group_id'] = security_group.id
664
 
 
665
 
        if self._security_group_rule_exists(security_group, values):
666
 
            raise exception.ApiError(_('This rule already exists in group %s')
667
 
                                     % group_name)
668
 
 
669
 
        security_group_rule = db.security_group_rule_create(context, values)
 
704
        prevalues = []
 
705
        try:
 
706
            prevalues = kwargs['ip_permissions']
 
707
        except KeyError:
 
708
            prevalues.append(kwargs)
 
709
        postvalues = []
 
710
        for values in prevalues:
 
711
            rulesvalues = self._rule_args_to_dict(context, values)
 
712
            if not rulesvalues:
 
713
                err = "%s Not enough parameters to build a valid rule"
 
714
                raise exception.ApiError(_(err % rulesvalues))
 
715
            for values_for_rule in rulesvalues:
 
716
                values_for_rule['parent_group_id'] = security_group.id
 
717
                if self._security_group_rule_exists(security_group,
 
718
                                                    values_for_rule):
 
719
                    err = '%s - This rule already exists in group'
 
720
                    raise exception.ApiError(_(err) % values_for_rule)
 
721
                postvalues.append(values_for_rule)
 
722
 
 
723
        for values_for_rule in postvalues:
 
724
            security_group_rule = db.security_group_rule_create(context,
 
725
                                                               values_for_rule)
670
726
 
671
727
        self.compute_api.trigger_security_group_rules_refresh(context,
672
 
                                      security_group_id=security_group['id'])
 
728
                                  security_group_id=security_group['id'])
673
729
 
 
730
        group = db.security_group_get_by_name(context, context.project_id,
 
731
                                              security_group['name'])
674
732
        return True
675
733
 
676
734
    def _get_source_project_id(self, context, source_security_group_owner_id):
1147
1205
 
1148
1206
    def rescue_instance(self, context, instance_id, **kwargs):
1149
1207
        """This is an extension to the normal ec2_api"""
1150
 
        self._do_instance(self.compute_api.rescue, contect, instnace_id)
 
1208
        self._do_instance(self.compute_api.rescue, context, instance_id)
1151
1209
        return True
1152
1210
 
1153
1211
    def unrescue_instance(self, context, instance_id, **kwargs):