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