1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#!/usr/bin/python
# http://www.apache.org/licenses/LICENSE-2.0
"""Clamp Onboard service class."""
from yaml import load
from onapsdk.sdc.service import Service
from onapsdk.sdc.vf import Vf
from onapsdk.configuration import settings
from ..base import YamlTemplateBaseStep
from .service import YamlTemplateVfOnboardStep
class OnboardClampStep(YamlTemplateBaseStep):
"""Onboard class to create CLAMP templates."""
def __init__(self, cleanup=False):
"""Initialize Clamp Onboard object."""
super().__init__(cleanup=cleanup)
self._yaml_template: dict = None
self.add_step(YamlTemplateVfOnboardStep(cleanup=cleanup))
# if "service_name" in kwargs:
# self.service_name = kwargs['service_name']
# else:
# raise ValueError("Service Name to define")
# self.vf_list = []
# self.vsp_list = []
# self.set_logger()
@property
def description(self) -> str:
"""Step description."""
return "Onboard service in SDC including a TCA blueprint for CLAMP."
@property
def component(self) -> str:
"""Component name."""
return "SDC"
@property
def yaml_template(self) -> dict:
"""Step YAML template.
Load from file if it's a root step, get from parent otherwise.
Returns:
dict: Step YAML template
"""
if self.is_root:
if not self._yaml_template:
with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template:
self._yaml_template: dict = load(yaml_template)
return self._yaml_template
return self.parent.yaml_template
@property
def service_name(self) -> str:
"""Service name.
Get from YAML template if it's a root step, get from parent otherwise.
Returns:
str: Service name
"""
if self.is_root:
return next(iter(self.yaml_template.keys()))
else:
return self.parent.service_name
@YamlTemplateBaseStep.store_state
def execute(self):
"""Onboard service."""
super().execute()
# retrieve the Vf
vf = None
for sdc_vf in Vf.get_all():
if sdc_vf.name == settings.VF_NAME:
vf = sdc_vf
self._logger.debug("Vf retrieved %s", vf)
service: Service = Service(name=self.service_name,
resources=[vf])
service.create()
self._logger.info(" Service %s created", service)
if not service.distributed:
service.add_resource(vf)
# we add the artifact to the first VNF
self._logger.info("Try to add blueprint to %s", vf.name)
payload_file = open(settings.CONFIGURATION_PATH + 'tca-microservice.yaml', 'rb')
data = payload_file.read()
self._logger.info("DCAE INVENTORY BLUEPRINT file retrieved")
service.add_artifact_to_vf(vnf_name=vf.name,
artifact_type="DCAE_INVENTORY_BLUEPRINT",
artifact_name="tca-microservice.yaml",
artifact=data)
payload_file.close()
service.checkin()
service.onboard()
self._logger.info("DCAE INVENTORY BLUEPRINT ADDED")
|