2 # Copyright 2016 RIFT.IO Inc
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
20 # Default config agent plugin type
21 DEFAULT_CAP_TYPE
= "riftca"
23 class RiftCMnsr(object):
26 created for Agents to use objects from NSR
28 def __init__(self
, nsr_dict
, cfg
):
38 return self
._nsr
['name_ref']
42 return self
._nsr
['nsd_name_ref']
46 return self
._nsr
['nsd_ref']
50 return self
._nsr
['ns_instance_config_ref']
57 def nsr_cfg_msg(self
):
62 ''' Get a new job id for config primitive'''
71 def member_vnf_index(self
):
72 return self
._vnfr
['member_vnf_index_ref']
74 def add_vnfr(self
, vnfr
, vnfr_msg
):
75 if vnfr
['id'] in self
._vnfr
_ids
.keys():
76 agent_vnfr
= self
._vnfr
_ids
[vnfr
['id']]
78 agent_vnfr
= RiftCMvnfr(self
.name
, vnfr
, vnfr_msg
)
79 self
._vnfrs
.append(agent_vnfr
)
80 self
._vnfrs
_msg
.append(vnfr_msg
)
81 self
._vnfr
_ids
[agent_vnfr
.id] = agent_vnfr
88 class RiftCMvnfr(object):
90 Agent base class for VNFR processing
92 def __init__(self
, nsr_name
, vnfr_dict
, vnfr_msg
):
93 self
._vnfr
= vnfr_dict
94 self
._vnfr
_msg
= vnfr_msg
95 self
._nsr
_name
= nsr_name
96 self
._configurable
= False
100 return self
._nsr
_name
108 return self
._vnfr
_msg
112 return self
._vnfr
['short_name']
117 return self
._vnfr
['tags']
123 return self
._vnfr
['id']
126 def member_vnf_index(self
):
127 return self
._vnfr
['member_vnf_index_ref']
130 def vnf_configuration(self
):
131 return self
._vnfr
['vnf_configuration']
136 return "D,/vnfr:vnfr-catalog/vnfr:vnfr[vnfr:id = '{}']".format(self
.id)
138 def set_to_configurable(self
):
139 self
._configurable
= True
142 def is_configurable(self
):
143 return self
._configurable
147 return self
._vnfr
['vnf_cfg']
149 class RiftCMConfigPluginBase(object):
151 Abstract base class for the NSM Configuration agent plugin.
152 There will be single instance of this plugin for each plugin type.
155 def __init__(self
, dts
, log
, loop
, config_agent
):
159 self
._config
_agent
= config_agent
162 def agent_type(self
):
163 raise NotImplementedError
167 raise NotImplementedError
170 def agent_data(self
):
171 raise NotImplementedError
190 def vnfr(self
, vnfr_id
):
191 raise NotImplementedError
195 def apply_config(self
, agent_nsr
, agent_vnfr
, config
, rpc_ip
):
196 """ Notification on configuration of an NSR """
201 def apply_ns_config(self
, agent_nsr
, agent_vnfrs
, config
, rpc_ip
):
202 """ Notification on configuration of an NSR """
207 def notify_create_vlr(self
, agent_nsr
, vld
):
208 """ Notification on creation of an VL """
213 def notify_create_vnfr(self
, agent_nsr
, agent_vnfr
):
214 """ Notification on creation of an VNFR """
219 def notify_instantiate_vnfr(self
, agent_nsr
, agent_vnfr
):
220 """ Notify instantiation of the virtual network function """
225 def notify_instantiate_vlr(self
, agent_nsr
, vl
):
226 """ Notify instantiate of the virtual link"""
231 def notify_terminate_vnfr(self
, agent_nsr
, agent_vnfr
):
232 """Notify termination of the VNF """
237 def notify_terminate_vlr(self
, agent_nsr
, vlr
):
238 """Notify termination of the Virtual Link Record"""
243 def apply_initial_config(self
, vnfr_id
, vnf
):
244 """Apply initial configuration"""
249 def get_config_status(self
, vnfr_id
):
250 """Get the status for the VNF"""
254 def get_action_status(self
, execution_id
):
255 """Get the action exection status"""
260 def vnf_config_primitive(self
, nsr_id
, vnfr_id
, primitive
, output
):
261 """Apply config primitive on a VNF"""
265 def is_vnfr_managed(self
, vnfr_id
):
266 """ Check if VNR is managed by config agent """
270 def add_vnfr_managed(self
, agent_vnfr
):
271 """ Add VNR to be managed by this config agent """
274 def get_service_status(self
, vnfr_id
):
275 """Get the status of the service"""
279 def invoke(self
, method
, *args
):
282 self
._log
.debug("Config agent plugin: method {} with args {}: {}".
283 format(method
, args
, self
))
285 # TBD - Do a better way than string compare to find invoke the method
286 if method
== 'notify_create_nsr':
287 rc
= yield from self
.notify_create_nsr(args
[0], args
[1])
288 elif method
== 'notify_create_vlr':
289 rc
= yield from self
.notify_create_vlr(args
[0], args
[1], args
[2])
290 elif method
== 'notify_create_vnfr':
291 rc
= yield from self
.notify_create_vnfr(args
[0], args
[1])
292 elif method
== 'notify_instantiate_nsr':
293 rc
= yield from self
.notify_instantiate_nsr(args
[0])
294 elif method
== 'notify_instantiate_vnfr':
295 rc
= yield from self
.notify_instantiate_vnfr(args
[0], args
[1])
296 elif method
== 'notify_instantiate_vlr':
297 rc
= yield from self
.notify_instantiate_vlr(args
[0], args
[1])
298 elif method
== 'notify_nsr_active':
299 rc
= yield from self
.notify_nsr_active(args
[0], args
[1])
300 elif method
== 'notify_terminate_nsr':
301 rc
= yield from self
.notify_terminate_nsr(args
[0])
302 elif method
== 'notify_terminate_vnfr':
303 rc
= yield from self
.notify_terminate_vnfr(args
[0], args
[1])
304 elif method
== 'notify_terminate_vlr':
305 rc
= yield from self
.notify_terminate_vlr(args
[0], args
[1])
306 elif method
== 'apply_initial_config':
307 rc
= yield from self
.apply_initial_config(args
[0], args
[1])
308 elif method
== 'apply_config':
309 rc
= yield from self
.apply_config(args
[0], args
[1], args
[2])
310 elif method
== 'get_config_status':
311 rc
= yield from self
.get_config_status(args
[0], args
[1])
313 self
._log
.error("Unknown method %s invoked on config agent plugin",
315 except Exception as e
:
316 self
._log
.error("Caught exception while invoking method: %s, Exception: %s", method
, str(e
))