@@ -34,21 +34,19 @@ class AgentMechanismDriverBase(api.MechanismDriver):
34
34
running on the port's host, and that agent to have connectivity to
35
35
at least one segment of the port's network.
36
36
37
- MechanismDrivers using this base class must pass the agent type
38
- and VIF type constants to __init__(), and must implement
37
+ MechanismDrivers using this base class must pass the agent type to
38
+ __init__(), and must implement try_to_bind_segment_for_agent() and
39
39
check_segment_for_agent().
40
40
"""
41
41
42
- def __init__ (self , agent_type , vif_type , cap_port_filter ,
42
+ def __init__ (self , agent_type ,
43
43
supported_vnic_types = [portbindings .VNIC_NORMAL ]):
44
44
"""Initialize base class for specific L2 agent type.
45
45
46
46
:param agent_type: Constant identifying agent type in agents_db
47
- :param vif_type: Value for binding:vif_type to when bound
47
+ :param supported_vnic_types: The binding:vnic_type values we can bind
48
48
"""
49
49
self .agent_type = agent_type
50
- self .vif_type = vif_type
51
- self .cap_port_filter = cap_port_filter
52
50
self .supported_vnic_types = supported_vnic_types
53
51
54
52
def initialize (self ):
@@ -69,10 +67,8 @@ def bind_port(self, context):
69
67
LOG .debug (_ ("Checking agent: %s" ), agent )
70
68
if agent ['alive' ]:
71
69
for segment in context .network .network_segments :
72
- if self .check_segment_for_agent (segment , agent ):
73
- context .set_binding (segment [api .ID ],
74
- self .vif_type ,
75
- self .cap_port_filter )
70
+ if self .try_to_bind_segment_for_agent (context , segment ,
71
+ agent ):
76
72
LOG .debug (_ ("Bound using segment: %s" ), segment )
77
73
return
78
74
else :
@@ -99,6 +95,25 @@ def unbind_port(self, context):
99
95
{'port' : context .current ['id' ],
100
96
'network' : context .network .current ['id' ]})
101
97
98
+ @abstractmethod
99
+ def try_to_bind_segment_for_agent (self , context , segment , agent ):
100
+ """Try to bind with segment for agent.
101
+
102
+ :param context: PortContext instance describing the port
103
+ :param segment: segment dictionary describing segment to bind
104
+ :param agent: agents_db entry describing agent to bind
105
+ :returns: True iff segment has been bound for agent
106
+
107
+ Called inside transaction during bind_port() so that derived
108
+ MechanismDrivers can use agent_db data along with built-in
109
+ knowledge of the corresponding agent's capabilities to attempt
110
+ to bind to the specified network segment for the agent.
111
+
112
+ If the segment can be bound for the agent, this function must
113
+ call context.set_binding() with appropriate values and then
114
+ return True. Otherwise, it must return False.
115
+ """
116
+
102
117
@abstractmethod
103
118
def check_segment_for_agent (self , segment , agent ):
104
119
"""Check if segment can be bound for agent.
@@ -107,9 +122,49 @@ def check_segment_for_agent(self, segment, agent):
107
122
:param agent: agents_db entry describing agent to bind
108
123
:returns: True iff segment can be bound for agent
109
124
110
- Called inside transaction during bind_port () and
111
- validate_port_binding() so that derived MechanismDrivers can
112
- use agent_db data along with built-in knowledge of the
113
- corresponding agent's capabilities to determine whether or not
114
- the specified network segment can be bound for the agent.
125
+ Called inside transaction during validate_port_binding () so
126
+ that derived MechanismDrivers can use agent_db data along with
127
+ built-in knowledge of the corresponding agent's capabilities
128
+ to determine whether or not the specified network segment can
129
+ be bound for the agent.
115
130
"""
131
+
132
+
133
+ @six .add_metaclass (ABCMeta )
134
+ class SimpleAgentMechanismDriverBase (AgentMechanismDriverBase ):
135
+ """Base class for simple drivers using an L2 agent.
136
+
137
+ The SimpleAgentMechanismDriverBase provides common code for
138
+ mechanism drivers that integrate the ml2 plugin with L2 agents,
139
+ where the binding:vif_type and binding:vif_details values are the
140
+ same for all bindings. Port binding with this driver requires the
141
+ driver's associated agent to be running on the port's host, and
142
+ that agent to have connectivity to at least one segment of the
143
+ port's network.
144
+
145
+ MechanismDrivers using this base class must pass the agent type
146
+ and the values for binding:vif_type and binding:vif_details to
147
+ __init__(). They must implement check_segment_for_agent() as
148
+ defined in AgentMechanismDriverBase, which will be called during
149
+ both binding establishment and validation.
150
+ """
151
+
152
+ def __init__ (self , agent_type , vif_type , vif_details ,
153
+ supported_vnic_types = [portbindings .VNIC_NORMAL ]):
154
+ """Initialize base class for specific L2 agent type.
155
+
156
+ :param agent_type: Constant identifying agent type in agents_db
157
+ :param vif_type: Value for binding:vif_type when bound
158
+ :param vif_details: Dictionary with details for VIF driver when bound
159
+ :param supported_vnic_types: The binding:vnic_type values we can bind
160
+ """
161
+ super (SimpleAgentMechanismDriverBase , self ).__init__ (
162
+ agent_type , supported_vnic_types )
163
+ self .vif_type = vif_type
164
+ self .vif_details = vif_details
165
+
166
+ def try_to_bind_segment_for_agent (self , context , segment , agent ):
167
+ if self .check_segment_for_agent (segment , agent ):
168
+ context .set_binding (segment [api .ID ],
169
+ self .vif_type ,
170
+ self .vif_details )
0 commit comments