530
530
g['ipPermissions'] += [r]
533
def _revoke_rule_args_to_dict(self, context, to_port=None, from_port=None,
533
def _rule_args_to_dict(self, context, kwargs):
535
if not 'groups' in kwargs and not 'ip_ranges' in kwargs:
536
rule = self._rule_dict_last_step(context, **kwargs)
540
if 'ip_ranges' in kwargs:
541
rules = self._cidr_args_split(kwargs)
545
groups_values = self._groups_args_split(rule)
546
for groups_value in groups_values:
547
finalset.append(groups_value)
550
finalset.append(rule)
553
def _cidr_args_split(self, kwargs):
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
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
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)
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 "
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)
661
raise exception.ApiError(_("Not enough parameters to build a "
663
values['parent_group_id'] = security_group.id
665
if self._security_group_rule_exists(security_group, values):
666
raise exception.ApiError(_('This rule already exists in group %s')
669
security_group_rule = db.security_group_rule_create(context, values)
706
prevalues = kwargs['ip_permissions']
708
prevalues.append(kwargs)
710
for values in prevalues:
711
rulesvalues = self._rule_args_to_dict(context, values)
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,
719
err = '%s - This rule already exists in group'
720
raise exception.ApiError(_(err) % values_for_rule)
721
postvalues.append(values_for_rule)
723
for values_for_rule in postvalues:
724
security_group_rule = db.security_group_rule_create(context,
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'])
730
group = db.security_group_get_by_name(context, context.project_id,
731
security_group['name'])
676
734
def _get_source_project_id(self, context, source_security_group_owner_id):
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)
1153
1211
def unrescue_instance(self, context, instance_id, **kwargs):