Bug 36 Multi site NS support and support for IP profile params
[osm/SO.git] / rwlaunchpad / plugins / rwnsm / rift / tasklets / rwnsmtasklet / openmano_nsm.py
1
2 #
3 # Copyright 2016 RIFT.IO Inc
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17
18 import asyncio
19 import os
20 import sys
21 import time
22 import yaml
23
24 import gi
25 gi.require_version('RwDts', '1.0')
26 gi.require_version('RwVnfrYang', '1.0')
27 from gi.repository import (
28 RwDts as rwdts,
29 RwVnfrYang,
30 )
31
32 import rift.openmano.rift2openmano as rift2openmano
33 import rift.openmano.openmano_client as openmano_client
34 from . import rwnsmplugin
35
36 import rift.tasklets
37
38 if sys.version_info < (3, 4, 4):
39 asyncio.ensure_future = asyncio.async
40
41
42 DUMP_OPENMANO_DIR = os.path.join(
43 os.environ["RIFT_ARTIFACTS"],
44 "openmano_descriptors"
45 )
46
47
48 def dump_openmano_descriptor(name, descriptor_str):
49 filename = "{}_{}.yaml".format(
50 time.strftime("%Y%m%d-%H%M%S"),
51 name
52 )
53
54 filepath = os.path.join(
55 DUMP_OPENMANO_DIR,
56 filename
57 )
58
59 try:
60 if not os.path.exists(DUMP_OPENMANO_DIR):
61 os.makedirs(DUMP_OPENMANO_DIR)
62
63 with open(filepath, 'w') as hdl:
64 hdl.write(descriptor_str)
65
66 except OSError as e:
67 print("Failed to dump openmano descriptor: %s" % str(e))
68
69 return filepath
70
71 class VnfrConsoleOperdataDtsHandler(object):
72 """ registers 'D,/vnfr:vnfr-console/vnfr:vnfr[id]/vdur[id]' and handles CRUD from DTS"""
73 @property
74 def vnfr_vdu_console_xpath(self):
75 """ path for resource-mgr"""
76 return ("D,/rw-vnfr:vnfr-console/rw-vnfr:vnfr[rw-vnfr:id='{}']/rw-vnfr:vdur[vnfr:id='{}']".format(self._vnfr_id,self._vdur_id))
77
78 def __init__(self, dts, log, loop, nsr, vnfr_id, vdur_id, vdu_id):
79 self._dts = dts
80 self._log = log
81 self._loop = loop
82 self._regh = None
83 self._nsr = nsr
84
85 self._vnfr_id = vnfr_id
86 self._vdur_id = vdur_id
87 self._vdu_id = vdu_id
88
89 @asyncio.coroutine
90 def register(self):
91 """ Register for VNFR VDU Operational Data read from dts """
92
93 @asyncio.coroutine
94 def on_prepare(xact_info, action, ks_path, msg):
95 """ prepare callback from dts """
96 xpath = ks_path.to_xpath(RwVnfrYang.get_schema())
97 self._log.debug(
98 "Got VNFR VDU Opdata xact_info: %s, action: %s): %s:%s",
99 xact_info, action, xpath, msg
100 )
101
102 if action == rwdts.QueryAction.READ:
103 schema = RwVnfrYang.YangData_RwVnfr_VnfrConsole_Vnfr_Vdur.schema()
104 path_entry = schema.keyspec_to_entry(ks_path)
105 self._log.debug("VDU Opdata path is {}".format(path_entry))
106
107 try:
108 console_url = yield from self._loop.run_in_executor(
109 None,
110 self._nsr._http_api.get_instance_vm_console_url,
111 self._nsr._nsr_uuid,
112 self._vdur_id
113 )
114
115 self._log.debug("Got console response: %s for NSR ID %s vdur ID %s",
116 console_url,
117 self._nsr._nsr_uuid,
118 self._vdur_id
119 )
120 vdur_console = RwVnfrYang.YangData_RwVnfr_VnfrConsole_Vnfr_Vdur()
121 vdur_console.id = self._vdur_id
122 if console_url:
123 vdur_console.console_url = console_url
124 else:
125 vdur_console.console_url = 'none'
126 self._log.debug("Recevied console URL for vdu {} is {}".format(self._vdu_id,vdur_console))
127 except openmano_client.InstanceStatusError as e:
128 self._log.error("Could not get NS instance console URL: %s",
129 str(e))
130 vdur_console = RwVnfrYang.YangData_RwVnfr_VnfrConsole_Vnfr_Vdur()
131 vdur_console.id = self._vdur_id
132 vdur_console.console_url = 'none'
133
134 xact_info.respond_xpath(rsp_code=rwdts.XactRspCode.ACK,
135 xpath=self.vnfr_vdu_console_xpath,
136 msg=vdur_console)
137 else:
138 #raise VnfRecordError("Not supported operation %s" % action)
139 self._log.error("Not supported operation %s" % action)
140 xact_info.respond_xpath(rsp_code=rwdts.XactRspCode.ACK)
141 return
142
143 self._log.debug("Registering for VNFR VDU using xpath: %s",
144 self.vnfr_vdu_console_xpath)
145 hdl = rift.tasklets.DTS.RegistrationHandler(on_prepare=on_prepare,)
146 with self._dts.group_create() as group:
147 self._regh = group.register(xpath=self.vnfr_vdu_console_xpath,
148 handler=hdl,
149 flags=rwdts.Flag.PUBLISHER,
150 )
151
152
153
154 class OpenmanoVnfr(object):
155 def __init__(self, log, loop, cli_api, vnfr):
156 self._log = log
157 self._loop = loop
158 self._cli_api = cli_api
159 self._vnfr = vnfr
160 self._vnfd_id = vnfr.vnfd.id
161
162 self._vnf_id = None
163
164 self._created = False
165
166 @property
167 def vnfd(self):
168 return rift2openmano.RiftVNFD(self._vnfr.vnfd)
169
170 @property
171 def vnfr(self):
172 return self._vnfr
173
174 @property
175 def rift_vnfd_id(self):
176 return self._vnfd_id
177
178 @property
179 def openmano_vnfd_id(self):
180 return self._vnf_id
181
182 @property
183 def openmano_vnfd(self):
184 self._log.debug("Converting vnfd %s from rift to openmano", self.vnfd.id)
185 openmano_vnfd = rift2openmano.rift2openmano_vnfd(self.vnfd)
186 return openmano_vnfd
187
188 @property
189 def openmano_vnfd_yaml(self):
190 return yaml.safe_dump(self.openmano_vnfd, default_flow_style=False)
191
192 @asyncio.coroutine
193 def create(self):
194 self._log.debug("Creating openmano vnfd")
195 openmano_vnfd = self.openmano_vnfd
196 name = openmano_vnfd["vnf"]["name"]
197
198 # If the name already exists, get the openmano vnfd id
199 name_uuid_map = yield from self._loop.run_in_executor(
200 None,
201 self._cli_api.vnf_list,
202 )
203
204 if name in name_uuid_map:
205 vnf_id = name_uuid_map[name]
206 self._log.debug("Vnf already created. Got existing openmano vnfd id: %s", vnf_id)
207 self._vnf_id = vnf_id
208 return
209
210 self._vnf_id, _ = yield from self._loop.run_in_executor(
211 None,
212 self._cli_api.vnf_create,
213 self.openmano_vnfd_yaml,
214 )
215
216 fpath = dump_openmano_descriptor(
217 "{}_vnf".format(name),
218 self.openmano_vnfd_yaml
219 )
220
221 self._log.debug("Dumped Openmano VNF descriptor to: %s", fpath)
222
223 self._created = True
224
225 @asyncio.coroutine
226 def delete(self):
227 if not self._created:
228 return
229
230 self._log.debug("Deleting openmano vnfd")
231 if self._vnf_id is None:
232 self._log.warning("Openmano vnf id not set. Cannot delete.")
233 return
234
235 yield from self._loop.run_in_executor(
236 None,
237 self._cli_api.vnf_delete,
238 self._vnf_id,
239 )
240
241
242 class OpenmanoNsr(object):
243 TIMEOUT_SECS = 120
244
245 def __init__(self, dts, log, loop, publisher, cli_api, http_api, nsd_msg, nsr_config_msg):
246 self._dts = dts
247 self._log = log
248 self._loop = loop
249 self._publisher = publisher
250 self._cli_api = cli_api
251 self._http_api = http_api
252
253 self._nsd_msg = nsd_msg
254 self._nsr_config_msg = nsr_config_msg
255
256 self._vlrs = []
257 self._vnfrs = []
258 self._vdur_console_handler = {}
259
260 self._nsd_uuid = None
261 self._nsr_uuid = None
262
263 self._nsr_msg = None
264
265 self._created = False
266
267 self._monitor_task = None
268
269 @property
270 def nsd(self):
271 return rift2openmano.RiftNSD(self._nsd_msg)
272
273 @property
274 def vnfds(self):
275 return {v.rift_vnfd_id: v.vnfd for v in self._vnfrs}
276
277 @property
278 def vnfrs(self):
279 return self._vnfrs
280
281 @property
282 def openmano_nsd_yaml(self):
283 self._log.debug("Converting nsd %s from rift to openmano", self.nsd.id)
284 openmano_nsd = rift2openmano.rift2openmano_nsd(self.nsd, self.vnfds)
285 return yaml.safe_dump(openmano_nsd, default_flow_style=False)
286
287
288 @property
289 def openmano_instance_create_yaml(self):
290 self._log.debug("Creating instance-scenario-create input file for nsd %s with name %s", self.nsd.id, self._nsr_config_msg.name)
291 openmano_instance_create = {}
292 openmano_instance_create["name"] = self._nsr_config_msg.name
293 openmano_instance_create["description"] = self._nsr_config_msg.description
294 openmano_instance_create["scenario"] = self._nsd_uuid
295 if self._nsr_config_msg.has_field("om_datacenter"):
296 openmano_instance_create["datacenter"] = self._nsr_config_msg.om_datacenter
297 openmano_instance_create["vnfs"] = {}
298 for vnfr in self._vnfrs:
299 if "om_datacenter" in vnfr.vnfr.vnfr_msg:
300 vnfr_name = vnfr.vnfr.vnfd.name + "__" + str(vnfr.vnfr.vnfr_msg.member_vnf_index_ref)
301 openmano_instance_create["vnfs"][vnfr_name] = {"datacenter": vnfr.vnfr.vnfr_msg.om_datacenter}
302 openmano_instance_create["networks"] = {}
303 for vld_msg in self._nsd_msg.vld:
304 openmano_instance_create["networks"][vld_msg.name] = {}
305 openmano_instance_create["networks"][vld_msg.name]["sites"] = list()
306 for vlr in self._vlrs:
307 if vlr.vld_msg.name == vld_msg.name:
308 self._log.debug("Received VLR name %s, VLR DC: %s for VLD: %s",vlr.vld_msg.name,
309 vlr.om_datacenter_name,vld_msg.name)
310 #network["vim-network-name"] = vld_msg.name
311 network = {}
312 ip_profile = {}
313 if vld_msg.vim_network_name:
314 network["netmap-use"] = vld_msg.vim_network_name
315 elif vlr._ip_profile.has_field("ip_profile_params"):
316 ip_profile_params = vlr._ip_profile.ip_profile_params
317 if ip_profile_params.ip_version == "ipv6":
318 ip_profile['ip-version'] = "IPv6"
319 else:
320 ip_profile['ip-version'] = "IPv4"
321 if ip_profile_params.has_field('subnet_address'):
322 ip_profile['subnet-address'] = ip_profile_params.subnet_address
323 if ip_profile_params.has_field('gateway_address'):
324 ip_profile['gateway-address'] = ip_profile_params.gateway_address
325 if ip_profile_params.has_field('dns_server') and len(ip_profile_params.dns_server) > 0:
326 ip_profile['dns-address'] = ip_profile_params.dns_server[0]
327 if ip_profile_params.has_field('dhcp_params'):
328 ip_profile['dhcp'] = {}
329 ip_profile['dhcp']['enabled'] = ip_profile_params.dhcp_params.enabled
330 ip_profile['dhcp']['start-address'] = ip_profile_params.dhcp_params.start_address
331 ip_profile['dhcp']['count'] = ip_profile_params.dhcp_params.count
332 else:
333 network["netmap-create"] = vlr.name
334 if vlr.om_datacenter_name:
335 network["datacenter"] = vlr.om_datacenter_name
336 elif vld_msg.has_field("om_datacenter"):
337 network["datacenter"] = vld_msg.om_datacenter
338 elif "datacenter" in openmano_instance_create:
339 network["datacenter"] = openmano_instance_create["datacenter"]
340 if network:
341 openmano_instance_create["networks"][vld_msg.name]["sites"].append(network)
342 if ip_profile:
343 openmano_instance_create["networks"][vld_msg.name]['ip-profile'] = ip_profile
344
345 return yaml.safe_dump(openmano_instance_create, default_flow_style=False)
346
347 @asyncio.coroutine
348 def add_vlr(self, vlr):
349 self._vlrs.append(vlr)
350 yield from asyncio.sleep(1, loop=self._loop)
351
352 @asyncio.coroutine
353 def add_vnfr(self, vnfr):
354 vnfr = OpenmanoVnfr(self._log, self._loop, self._cli_api, vnfr)
355 yield from vnfr.create()
356 self._vnfrs.append(vnfr)
357
358 @asyncio.coroutine
359 def delete(self):
360 if not self._created:
361 self._log.debug("NSD wasn't created. Skipping delete.")
362 return
363
364 self._log.debug("Deleting openmano nsr")
365
366 yield from self._loop.run_in_executor(
367 None,
368 self._cli_api.ns_delete,
369 self._nsd_uuid,
370 )
371
372 self._log.debug("Deleting openmano vnfrs")
373 for vnfr in self._vnfrs:
374 yield from vnfr.delete()
375
376
377 @asyncio.coroutine
378 def create(self):
379 self._log.debug("Creating openmano scenario")
380 name_uuid_map = yield from self._loop.run_in_executor(
381 None,
382 self._cli_api.ns_list,
383 )
384
385 if self._nsd_msg.name in name_uuid_map:
386 self._log.debug("Found existing openmano scenario")
387 self._nsd_uuid = name_uuid_map[self._nsd_msg.name]
388 return
389
390
391 # Use the nsd uuid as the scenario name to rebind to existing
392 # scenario on reload or to support muliple instances of the name
393 # nsd
394 self._nsd_uuid, _ = yield from self._loop.run_in_executor(
395 None,
396 self._cli_api.ns_create,
397 self.openmano_nsd_yaml,
398 self._nsd_msg.name
399 )
400 fpath = dump_openmano_descriptor(
401 "{}_nsd".format(self._nsd_msg.name),
402 self.openmano_nsd_yaml,
403 )
404
405 self._log.debug("Dumped Openmano NS descriptor to: %s", fpath)
406
407 self._created = True
408
409 @asyncio.coroutine
410 def instance_monitor_task(self):
411 self._log.debug("Starting Instance monitoring task")
412
413 start_time = time.time()
414 active_vnfs = []
415
416 while True:
417 yield from asyncio.sleep(1, loop=self._loop)
418
419 try:
420 instance_resp_json = yield from self._loop.run_in_executor(
421 None,
422 self._http_api.get_instance,
423 self._nsr_uuid,
424 )
425
426 self._log.debug("Got instance response: %s for NSR ID %s",
427 instance_resp_json,
428 self._nsr_uuid)
429
430 except openmano_client.InstanceStatusError as e:
431 self._log.error("Could not get NS instance status: %s", str(e))
432 continue
433
434 def all_vms_active(vnf):
435 for vm in vnf["vms"]:
436 vm_status = vm["status"]
437 vm_uuid = vm["uuid"]
438 if vm_status != "ACTIVE":
439 self._log.debug("VM is not yet active: %s (status: %s)", vm_uuid, vm_status)
440 return False
441
442 return True
443
444 def any_vm_active_nomgmtip(vnf):
445 for vm in vnf["vms"]:
446 vm_status = vm["status"]
447 vm_uuid = vm["uuid"]
448 if vm_status != "ACTIVE":
449 self._log.debug("VM is not yet active: %s (status: %s)", vm_uuid, vm_status)
450 return False
451
452 return True
453
454 def any_vms_error(vnf):
455 for vm in vnf["vms"]:
456 vm_status = vm["status"]
457 vm_vim_info = vm["vim_info"]
458 vm_uuid = vm["uuid"]
459 if vm_status == "ERROR":
460 self._log.error("VM Error: %s (vim_info: %s)", vm_uuid, vm_vim_info)
461 return True
462
463 return False
464
465 def get_vnf_ip_address(vnf):
466 if "ip_address" in vnf:
467 return vnf["ip_address"].strip()
468 return None
469
470 def get_ext_cp_info(vnf):
471 cp_info_list = []
472 for vm in vnf["vms"]:
473 if "interfaces" not in vm:
474 continue
475
476 for intf in vm["interfaces"]:
477 if "external_name" not in intf:
478 continue
479
480 if not intf["external_name"]:
481 continue
482
483 ip_address = intf["ip_address"]
484 if ip_address is None:
485 ip_address = "0.0.0.0"
486
487 cp_info_list.append((intf["external_name"], ip_address))
488
489 return cp_info_list
490
491 def get_vnf_status(vnfr):
492 # When we create an openmano descriptor we use <name>__<idx>
493 # to come up with openmano constituent VNF name. Use this
494 # knowledge to map the vnfr back.
495 openmano_vnfr_suffix = "__{}".format(
496 vnfr.vnfr.vnfr_msg.member_vnf_index_ref
497 )
498
499 for vnf in instance_resp_json["vnfs"]:
500 if vnf["vnf_name"].endswith(openmano_vnfr_suffix):
501 return vnf
502
503 self._log.warning("Could not find vnf status with name that ends with: %s",
504 openmano_vnfr_suffix)
505 return None
506
507 for vnfr in self._vnfrs:
508 if vnfr in active_vnfs:
509 # Skipping, so we don't re-publish the same VNF message.
510 continue
511
512 vnfr_msg = vnfr.vnfr.vnfr_msg.deep_copy()
513 vnfr_msg.operational_status = "init"
514
515 try:
516 vnf_status = get_vnf_status(vnfr)
517 self._log.debug("Found VNF status: %s", vnf_status)
518 if vnf_status is None:
519 self._log.error("Could not find VNF status from openmano")
520 vnfr_msg.operational_status = "failed"
521 yield from self._publisher.publish_vnfr(None, vnfr_msg)
522 return
523
524 # If there was a VNF that has a errored VM, then just fail the VNF and stop monitoring.
525 if any_vms_error(vnf_status):
526 self._log.debug("VM was found to be in error state. Marking as failed.")
527 vnfr_msg.operational_status = "failed"
528 yield from self._publisher.publish_vnfr(None, vnfr_msg)
529 return
530
531 if all_vms_active(vnf_status):
532 vnf_ip_address = get_vnf_ip_address(vnf_status)
533
534 if vnf_ip_address is None:
535 self._log.warning("No IP address obtained "
536 "for VNF: {}, will retry.".format(
537 vnf_status['vnf_name']))
538 continue
539
540 self._log.debug("All VMs in VNF are active. Marking as running.")
541 vnfr_msg.operational_status = "running"
542
543 self._log.debug("Got VNF ip address: %s", vnf_ip_address)
544 vnfr_msg.mgmt_interface.ip_address = vnf_ip_address
545 vnfr_msg.vnf_configuration.config_access.mgmt_ip_address = vnf_ip_address
546
547
548 for vm in vnf_status["vms"]:
549 if vm["uuid"] not in self._vdur_console_handler:
550 vdur_console_handler = VnfrConsoleOperdataDtsHandler(self._dts, self._log, self._loop,
551 self, vnfr_msg.id,vm["uuid"],vm["name"])
552 yield from vdur_console_handler.register()
553 self._vdur_console_handler[vm["uuid"]] = vdur_console_handler
554
555 vdur_msg = vnfr_msg.vdur.add()
556 vdur_msg.vim_id = vm["vim_vm_id"]
557 vdur_msg.id = vm["uuid"]
558
559 # Add connection point information for the config manager
560 cp_info_list = get_ext_cp_info(vnf_status)
561 for (cp_name, cp_ip) in cp_info_list:
562 cp = vnfr_msg.connection_point.add()
563 cp.name = cp_name
564 cp.short_name = cp_name
565 cp.ip_address = cp_ip
566
567 yield from self._publisher.publish_vnfr(None, vnfr_msg)
568 active_vnfs.append(vnfr)
569
570 if (time.time() - start_time) > OpenmanoNsr.TIMEOUT_SECS:
571 self._log.error("NSR timed out before reaching running state")
572 vnfr_msg.operational_status = "failed"
573 yield from self._publisher.publish_vnfr(None, vnfr_msg)
574 return
575
576 except Exception as e:
577 vnfr_msg.operational_status = "failed"
578 yield from self._publisher.publish_vnfr(None, vnfr_msg)
579 self._log.exception("Caught exception publishing vnfr info: %s", str(e))
580 return
581
582 if len(active_vnfs) == len(self._vnfrs):
583 self._log.info("All VNF's are active. Exiting NSR monitoring task")
584 return
585
586 @asyncio.coroutine
587 def deploy(self,nsr_msg):
588 if self._nsd_uuid is None:
589 raise ValueError("Cannot deploy an uncreated nsd")
590
591 self._log.debug("Deploying openmano scenario")
592
593 name_uuid_map = yield from self._loop.run_in_executor(
594 None,
595 self._cli_api.ns_instance_list,
596 )
597
598 if self._nsr_config_msg.name in name_uuid_map:
599 self._log.debug("Found existing instance with nsr name: %s", self._nsr_config_msg.name)
600 self._nsr_uuid = name_uuid_map[self._nsr_config_msg.name]
601 else:
602 self._nsr_msg = nsr_msg
603 fpath = dump_openmano_descriptor(
604 "{}_instance_sce_create".format(self._nsr_config_msg.name),
605 self.openmano_instance_create_yaml,
606 )
607 self._log.debug("Dumped Openmano NS Scenario Cretae to: %s", fpath)
608
609 self._nsr_uuid = yield from self._loop.run_in_executor(
610 None,
611 self._cli_api.ns_instance_scenario_create,
612 self.openmano_instance_create_yaml)
613
614
615 self._monitor_task = asyncio.ensure_future(
616 self.instance_monitor_task(), loop=self._loop
617 )
618
619 @asyncio.coroutine
620 def terminate(self):
621
622 for _,handler in self._vdur_console_handler.items():
623 handler._regh.deregister()
624
625 if self._nsr_uuid is None:
626 self._log.warning("Cannot terminate an un-instantiated nsr")
627 return
628
629 if self._monitor_task is not None:
630 self._monitor_task.cancel()
631 self._monitor_task = None
632
633 self._log.debug("Terminating openmano nsr")
634 yield from self._loop.run_in_executor(
635 None,
636 self._cli_api.ns_terminate,
637 self._nsr_uuid,
638 )
639
640
641 class OpenmanoNsPlugin(rwnsmplugin.NsmPluginBase):
642 """
643 RW Implentation of the NsmPluginBase
644 """
645 def __init__(self, dts, log, loop, publisher, ro_account):
646 self._dts = dts
647 self._log = log
648 self._loop = loop
649 self._publisher = publisher
650
651 self._cli_api = None
652 self._http_api = None
653 self._openmano_nsrs = {}
654
655 self._set_ro_account(ro_account)
656
657 def _set_ro_account(self, ro_account):
658 self._log.debug("Setting openmano plugin cloud account: %s", ro_account)
659 self._cli_api = openmano_client.OpenmanoCliAPI(
660 self.log,
661 ro_account.openmano.host,
662 ro_account.openmano.port,
663 ro_account.openmano.tenant_id,
664 )
665
666 self._http_api = openmano_client.OpenmanoHttpAPI(
667 self.log,
668 ro_account.openmano.host,
669 ro_account.openmano.port,
670 ro_account.openmano.tenant_id,
671 )
672
673 def create_nsr(self, nsr_config_msg, nsd_msg):
674 """
675 Create Network service record
676 """
677 openmano_nsr = OpenmanoNsr(
678 self._dts,
679 self._log,
680 self._loop,
681 self._publisher,
682 self._cli_api,
683 self._http_api,
684 nsd_msg,
685 nsr_config_msg
686 )
687 self._openmano_nsrs[nsr_config_msg.id] = openmano_nsr
688
689 @asyncio.coroutine
690 def deploy(self, nsr_msg):
691 self._log.debug("Received NSR Deploy msg : %s", nsr_msg)
692 openmano_nsr = self._openmano_nsrs[nsr_msg.ns_instance_config_ref]
693 yield from openmano_nsr.create()
694 yield from openmano_nsr.deploy(nsr_msg)
695
696 @asyncio.coroutine
697 def instantiate_ns(self, nsr, xact):
698 """
699 Instantiate NSR with the passed nsr id
700 """
701 yield from nsr.instantiate(xact)
702
703 @asyncio.coroutine
704 def instantiate_vnf(self, nsr, vnfr):
705 """
706 Instantiate NSR with the passed nsr id
707 """
708 openmano_nsr = self._openmano_nsrs[nsr.id]
709 yield from openmano_nsr.add_vnfr(vnfr)
710
711 # Mark the VNFR as running
712 # TODO: Create a task to monitor nsr/vnfr status
713 vnfr_msg = vnfr.vnfr_msg.deep_copy()
714 vnfr_msg.operational_status = "init"
715
716 self._log.debug("Attempting to publish openmano vnf: %s", vnfr_msg)
717 with self._dts.transaction() as xact:
718 yield from self._publisher.publish_vnfr(xact, vnfr_msg)
719
720 @asyncio.coroutine
721 def instantiate_vl(self, nsr, vlr):
722 """
723 Instantiate NSR with the passed nsr id
724 """
725 self._log.debug("Received instantiate VL for NSR {}; VLR {}".format(nsr.id,vlr))
726 openmano_nsr = self._openmano_nsrs[nsr.id]
727 yield from openmano_nsr.add_vlr(vlr)
728
729 @asyncio.coroutine
730 def terminate_ns(self, nsr):
731 """
732 Terminate the network service
733 """
734 nsr_id = nsr.id
735 openmano_nsr = self._openmano_nsrs[nsr_id]
736 yield from openmano_nsr.terminate()
737 yield from openmano_nsr.delete()
738
739 with self._dts.transaction() as xact:
740 for vnfr in openmano_nsr.vnfrs:
741 self._log.debug("Unpublishing VNFR: %s", vnfr.vnfr.vnfr_msg)
742 yield from self._publisher.unpublish_vnfr(xact, vnfr.vnfr.vnfr_msg)
743
744 del self._openmano_nsrs[nsr_id]
745
746 @asyncio.coroutine
747 def terminate_vnf(self, vnfr):
748 """
749 Terminate the network service
750 """
751 pass
752
753 @asyncio.coroutine
754 def terminate_vl(self, vlr):
755 """
756 Terminate the virtual link
757 """
758 pass
759