3 from onapsdk.configuration import settings
4 from onapsdk.sdc.service import Service
5 from onapsdk.sdc.vf import Vf
7 from ..base import BaseStep, YamlTemplateBaseStep
8 from .vf import VfOnboardStep, YamlTemplateVfOnboardStep
11 class ServiceOnboardStep(BaseStep):
12 """Service onboard step."""
14 def __init__(self, cleanup=False):
20 super().__init__(cleanup=cleanup)
21 self.add_step(VfOnboardStep(cleanup=cleanup))
32 vf: Vf = Vf(name=settings.VF_NAME)
33 service: Service = Service(name=settings.SERVICE_NAME, resources=[vf])
37 class YamlTemplateServiceOnboardStep(YamlTemplateBaseStep):
38 """Service onboard using YAML template step."""
40 def __init__(self, cleanup=False):
44 - YamlTemplateVfOnboardStep.
46 super().__init__(cleanup=cleanup)
47 self._yaml_template: dict = None
48 self.add_step(YamlTemplateVfOnboardStep(cleanup=cleanup))
51 def yaml_template(self) -> dict:
52 """Step YAML template.
54 Load from file if it's a root step, get from parent otherwise.
57 dict: Step YAML template
61 if not self._yaml_template:
62 with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template:
63 self._yaml_template: dict = load(yaml_template)
64 return self._yaml_template
65 return self.parent.yaml_template
68 def service_name(self) -> str:
71 Get from YAML template if it's a root step, get from parent otherwise.
78 return next(iter(self.yaml_template.keys()))
80 return self.parent.service_name
83 """Onboard service."""
85 service: Service = Service(name=self.service_name,
86 resources=[Vf(name=vnf["vnf_name"]) \
87 for vnf in self.yaml_template[self.name]["vnfs"]])