def create_security_group_rule(self, q_context, security_group_rule): rule = security_group_rule['security_group_rule'] if rule['remote_group_id']: raise n_exceptions.RemoteGroupNotSupported() sg_id = rule['security_group_id'] sg = self.get_security_group(q_context, sg_id) if sg['name'] == 'default': raise n_exceptions.DefaultGroupUpdateNotSupported() new_rule = super(TricircleSecurityGroupMixin, self).create_security_group_rule(q_context, security_group_rule) t_context = context.get_context_from_neutron_context(q_context) mappings = db_api.get_bottom_mappings_by_top_id( t_context, sg_id, constants.RT_SG) try: for pod, b_sg_id in mappings: client = self._get_client(pod['pod_name']) rule['security_group_id'] = b_sg_id self._safe_create_security_group_rule( t_context, client, {'security_group_rule': rule}) except Exception: super(TricircleSecurityGroupMixin, self).delete_security_group_rule(q_context, new_rule['id']) raise n_exceptions.BottomPodOperationFailure( resource='security group rule', pod_name=pod['pod_name']) return new_rule
def delete_security_group_rule(self, q_context, _id): rule = self.get_security_group_rule(q_context, _id) if rule['remote_group_id']: raise n_exceptions.RemoteGroupNotSupported() sg_id = rule['security_group_id'] sg = self.get_security_group(q_context, sg_id) if sg['name'] == 'default': raise n_exceptions.DefaultGroupUpdateNotSupported() t_context = context.get_context_from_neutron_context(q_context) mappings = db_api.get_bottom_mappings_by_top_id( t_context, sg_id, constants.RT_SG) try: for pod, b_sg_id in mappings: client = self._get_client(pod['pod_name']) rule['security_group_id'] = b_sg_id b_sg = client.get_security_groups(t_context, b_sg_id) for b_rule in b_sg['security_group_rules']: if not self._compare_rule(b_rule, rule): continue self._safe_delete_security_group_rule(t_context, client, b_rule['id']) break except Exception: raise n_exceptions.BottomPodOperationFailure( resource='security group rule', pod_name=pod['pod_name']) super(TricircleSecurityGroupMixin, self).delete_security_group_rule(q_context, _id)
def create_security_group_rule(self, q_context, security_group_rule): rule = security_group_rule['security_group_rule'] if rule['remote_group_id']: raise n_exceptions.RemoteGroupNotSupported() sg_id = rule['security_group_id'] sg = self.get_security_group(q_context, sg_id) if not sg: raise n_exceptions.SecurityGroupNotFound(sg_id=sg_id) new_rule = super(TricircleSecurityGroupMixin, self).create_security_group_rule( q_context, security_group_rule) t_context = context.get_context_from_neutron_context(q_context) try: self.xjob_handler.configure_security_group_rules( t_context, rule['project_id']) except Exception: raise n_exceptions.BottomPodOperationFailure( resource='security group rule', region_name='') return new_rule