1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012 Nicira Networks, Inc
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
18
'''Implement Security Groups abstraction and API.
20
The nova security_group_handler flag specifies which class is to be used
21
to implement the security group calls.
23
The NullSecurityGroupHandler provides a "no-op" plugin that is loaded
24
by default and has no impact on current system behavior. In the future,
25
special purposes classes that inherit from SecurityGroupHandlerBase
26
will provide enhanced functionality and will be loadable via the
27
security_group_handler flag.
30
from nova.openstack.common import log as logging
33
LOG = logging.getLogger(__name__)
36
class SecurityGroupHandlerBase(object):
39
raise NotImplementedError()
41
def trigger_security_group_create_refresh(self, context, group):
42
'''Called when a rule is added to a security_group.
44
:param context: the security context.
45
:param group: the new group added. group is a dictionary that contains
46
the following: user_id, project_id, name, description).'''
47
raise NotImplementedError()
49
def trigger_security_group_destroy_refresh(self, context,
51
'''Called when a rule is added to a security_group.
53
:param context: the security context.
54
:param security_group_id: the security group identifier.'''
55
raise NotImplementedError()
57
def trigger_security_group_rule_create_refresh(self, context,
59
'''Called when a rule is added to a security_group.
61
:param context: the security context.
62
:param rule_ids: a list of rule ids that have been affected.'''
63
raise NotImplementedError()
65
def trigger_security_group_rule_destroy_refresh(self, context,
67
'''Called when a rule is removed from a security_group.
69
:param context: the security context.
70
:param rule_ids: a list of rule ids that have been affected.'''
71
raise NotImplementedError()
73
def trigger_instance_add_security_group_refresh(self, context, instance,
75
'''Called when a security group gains a new member.
77
:param context: the security context.
78
:param instance: the instance to be associated.
79
:param group_name: the name of the security group to be associated.'''
80
raise NotImplementedError()
82
def trigger_instance_remove_security_group_refresh(self, context, instance,
84
'''Called when a security group loses a member.
86
:param context: the security context.
87
:param instance: the instance to be associated.
88
:param group_name: the name of the security group to be associated.'''
89
raise NotImplementedError()
91
def trigger_security_group_members_refresh(self, context, group_ids):
92
'''Called when a security group gains or loses a member.
94
:param context: the security context.
95
:param group_ids: a list of security group identifiers.'''
96
raise NotImplementedError()
99
class NullSecurityGroupHandler(SecurityGroupHandlerBase):
104
def trigger_security_group_create_refresh(self, context, group):
105
'''Called when a rule is added to a security_group.
107
:param context: the security context.
108
:param group: the new group added. group is a dictionary that contains
109
the following: user_id, project_id, name, description).'''
112
def trigger_security_group_destroy_refresh(self, context,
114
'''Called when a rule is added to a security_group.
116
:param context: the security context.
117
:param security_group_id: the security group identifier.'''
120
def trigger_security_group_rule_create_refresh(self, context,
122
'''Called when a rule is added to a security_group.
124
:param context: the security context.
125
:param rule_ids: a list of rule ids that have been affected.'''
128
def trigger_security_group_rule_destroy_refresh(self, context,
130
'''Called when a rule is removed from a security_group.
132
:param context: the security context.
133
:param rule_ids: a list of rule ids that have been affected.'''
136
def trigger_instance_add_security_group_refresh(self, context, instance,
138
'''Called when a security group gains a new member.
140
:param context: the security context.
141
:param instance: the instance to be associated.
142
:param group_name: the name of the security group to be associated.'''
145
def trigger_instance_remove_security_group_refresh(self, context, instance,
147
'''Called when a security group loses a member.
149
:param context: the security context.
150
:param instance: the instance to be associated.
151
:param group_name: the name of the security group to be associated.'''
154
def trigger_security_group_members_refresh(self, context, group_ids):
155
'''Called when a security group gains or loses a member.
157
:param context: the security context.
158
:param group_ids: a list of security group identifiers.'''