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
, project
):
31 self
._project
= project
39 return self
._nsr
['name_ref']
43 return self
._nsr
['nsd_name_ref']
47 return self
._nsr
['nsd_ref']
51 return self
._nsr
['ns_instance_config_ref']
58 def nsr_cfg_msg(self
):
63 ''' Get a new job id for config primitive'''
72 def member_vnf_index(self
):
73 return self
._vnfr
['member_vnf_index_ref']
75 def add_vnfr(self
, vnfr
, vnfr_msg
):
76 if vnfr
['id'] in self
._vnfr
_ids
.keys():
77 agent_vnfr
= self
._vnfr
_ids
[vnfr
['id']]
79 agent_vnfr
= RiftCMvnfr(self
.name
, vnfr
, vnfr_msg
, self
._project
)
80 self
._vnfrs
.append(agent_vnfr
)
81 self
._vnfrs
_msg
.append(vnfr_msg
)
82 self
._vnfr
_ids
[agent_vnfr
.id] = agent_vnfr
89 class RiftCMvnfr(object):
91 Agent base class for VNFR processing
93 def __init__(self
, nsr_name
, vnfr_dict
, vnfr_msg
, project
):
94 self
._vnfr
= vnfr_dict
95 self
._vnfr
_msg
= vnfr_msg
96 self
._nsr
_name
= nsr_name
97 self
._configurable
= False
98 self
._project
= project
102 return self
._nsr
_name
110 return self
._vnfr
_msg
114 return self
._vnfr
['short_name']
119 return self
._vnfr
['tags']
125 return self
._vnfr
['id']
128 def member_vnf_index(self
):
129 return self
._vnfr
['member_vnf_index_ref']
132 def vnf_configuration(self
):
133 return self
._vnfr
['vnf_configuration']
138 return self
._project
.add_project("D,/vnfr:vnfr-catalog/vnfr:vnfr[vnfr:id = '{}']".
141 def set_to_configurable(self
):
142 self
._configurable
= True
145 def is_configurable(self
):
146 return self
._configurable
150 return self
._vnfr
['vnf_cfg']
152 class RiftCMConfigPluginBase(object):
154 Abstract base class for the NSM Configuration agent plugin.
155 There will be single instance of this plugin for each plugin type.
158 def __init__(self
, dts
, log
, loop
, project
, config_agent
):
162 self
._project
= project
163 self
._config
_agent
= config_agent
166 def agent_type(self
):
167 raise NotImplementedError
171 raise NotImplementedError
174 def agent_data(self
):
175 raise NotImplementedError
194 def vnfr(self
, vnfr_id
):
195 raise NotImplementedError
198 def get_Service_name(self
):
199 """ Get the service name specific to the plugin """
204 def apply_config(self
, agent_nsr
, agent_vnfr
, config
, rpc_ip
):
205 """ Notification on configuration of an NSR """
210 def apply_ns_config(self
, agent_nsr
, agent_vnfrs
, config
, rpc_ip
):
211 """ Notification on configuration of an NSR """
216 def notify_create_vlr(self
, agent_nsr
, vld
):
217 """ Notification on creation of an VL """
222 def notify_create_vnfr(self
, agent_nsr
, agent_vnfr
):
223 """ Notification on creation of an VNFR """
228 def notify_instantiate_vnfr(self
, agent_nsr
, agent_vnfr
):
229 """ Notify instantiation of the virtual network function """
234 def notify_instantiate_vlr(self
, agent_nsr
, vl
):
235 """ Notify instantiate of the virtual link"""
240 def notify_terminate_vnfr(self
, agent_nsr
, agent_vnfr
):
241 """Notify termination of the VNF """
246 def notify_terminate_vlr(self
, agent_nsr
, vlr
):
247 """Notify termination of the Virtual Link Record"""
252 def apply_initial_config(self
, vnfr_id
, vnf
):
253 """Apply initial configuration"""
258 def get_config_status(self
, vnfr_id
):
259 """Get the status for the VNF"""
263 def get_action_status(self
, execution_id
):
264 """Get the action exection status"""
269 def vnf_config_primitive(self
, nsr_id
, vnfr_id
, primitive
, output
):
270 """Apply config primitive on a VNF"""
274 def is_vnfr_managed(self
, vnfr_id
):
275 """ Check if VNR is managed by config agent """
279 def add_vnfr_managed(self
, agent_vnfr
):
280 """ Add VNR to be managed by this config agent """
283 def get_service_status(self
, vnfr_id
):
284 """Get the status of the service"""
288 def invoke(self
, method
, *args
):
291 self
._log
.debug("Config agent plugin: method {} with args {}: {}".
292 format(method
, args
, self
))
294 # TBD - Do a better way than string compare to find invoke the method
295 if method
== 'notify_create_nsr':
296 rc
= yield from self
.notify_create_nsr(args
[0], args
[1])
297 elif method
== 'notify_create_vlr':
298 rc
= yield from self
.notify_create_vlr(args
[0], args
[1], args
[2])
299 elif method
== 'notify_create_vnfr':
300 rc
= yield from self
.notify_create_vnfr(args
[0], args
[1])
301 elif method
== 'notify_instantiate_nsr':
302 rc
= yield from self
.notify_instantiate_nsr(args
[0])
303 elif method
== 'notify_instantiate_vnfr':
304 rc
= yield from self
.notify_instantiate_vnfr(args
[0], args
[1])
305 elif method
== 'notify_instantiate_vlr':
306 rc
= yield from self
.notify_instantiate_vlr(args
[0], args
[1])
307 elif method
== 'notify_nsr_active':
308 rc
= yield from self
.notify_nsr_active(args
[0], args
[1])
309 elif method
== 'notify_terminate_nsr':
310 rc
= yield from self
.notify_terminate_nsr(args
[0])
311 elif method
== 'notify_terminate_vnfr':
312 rc
= yield from self
.notify_terminate_vnfr(args
[0], args
[1])
313 elif method
== 'notify_terminate_vlr':
314 rc
= yield from self
.notify_terminate_vlr(args
[0], args
[1])
315 elif method
== 'apply_initial_config':
316 rc
= yield from self
.apply_initial_config(args
[0], args
[1])
317 elif method
== 'apply_config':
318 rc
= yield from self
.apply_config(args
[0], args
[1], args
[2])
319 elif method
== 'get_config_status':
320 rc
= yield from self
.get_config_status(args
[0], args
[1])
322 self
._log
.error("Unknown method %s invoked on config agent plugin",
324 except Exception as e
:
325 self
._log
.error("Caught exception while invoking method: %s, Exception: %s", method
, str(e
))