1 # ============LICENSE_START=======================================================
2 # Copyright (C) 2021 Orange
3 # ================================================================================
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.
16 # ============LICENSE_END=========================================================
22 from io import BytesIO
26 from config import Config
27 import onapsdk.constants as const
29 from onapsdk.sdc.vendor import Vendor
30 from onapsdk.sdc.vsp import Vsp
31 from onapsdk.sdc.vf import Vf
32 from onapsdk.sdc.service import Service, ServiceInstantiationType
36 logger = logging.getLogger("")
37 logger.setLevel(logging.DEBUG)
38 fh = logging.StreamHandler()
39 fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s')
40 fh.setFormatter(fh_formatter)
43 # Read SDNC MODEL NAME and VERSION from CBA.zip
44 logger.info("*******************************")
45 logger.info("Retrieving SDNC MODEL NAME and VERSION")
46 logger.info("*******************************")
47 with zipfile.ZipFile(Config.VSPFILE, 'r') as package:
48 cba_io = BytesIO(package.read("CBA.zip"))
49 with zipfile.ZipFile(cba_io) as cba:
50 with cba.open('TOSCA-Metadata/TOSCA.meta') as meta_file:
51 tosca_meta = yaml.load(meta_file, Loader=yaml.FullLoader)
52 SDNC_MODEL_NAME = tosca_meta.get("Template-Name")
53 SDNC_MODEL_VERSION = tosca_meta.get("Template-Version")
55 logger.info("*******************************")
56 logger.info("******** SERVICE DESIGN *******")
57 logger.info("*******************************")
59 logger.info("******** Onboard Vendor *******")
60 vendor = Vendor(name=Config.VENDOR)
63 logger.info("******** Onboard VSP *******")
64 mypath = os.path.dirname(os.path.realpath(__file__))
65 myvspfile = os.path.join(mypath, Config.VSPFILE)
66 vsp = Vsp(name=Config.VSPNAME, vendor=vendor, package=open(myvspfile, 'rb'))
69 logger.info("******** Onboard VF *******")
70 vf = Vf(name=Config.VFNAME)
75 logger.info("******** Onboard Service *******")
76 svc = Service(name=Config.SERVICENAME,
77 instantiation_type=ServiceInstantiationType.MACRO)
80 if svc.status == const.DRAFT:
83 logger.info("******** Set SDNC properties for VF ********")
84 component = svc.get_component(vf)
85 prop = component.get_property("sdnc_model_version")
86 prop.value = SDNC_MODEL_VERSION
87 prop = component.get_property("sdnc_artifact_name")
88 prop.value = Config.SDNC_ARTIFACT_NAME
89 prop = component.get_property("sdnc_model_name")
90 prop.value = SDNC_MODEL_NAME
91 prop = component.get_property("controller_actor")
93 prop = component.get_property("skip_post_instantiation_configuration")
94 prop.value = Config.SKIP_POST_INSTANTIATION
96 logger.info("******** Onboard Service *******")
100 logger.info("******** Check Service Distribution *******")
101 distribution_completed = False
104 while distribution_completed is False and nb_try < nb_try_max:
105 distribution_completed = svc.distributed
106 if distribution_completed is True:
107 logger.info("Service Distribution for %s is successfully finished", svc.name)
109 logger.info("Service Distribution for %s ongoing, Wait for 60 s", svc.name)
113 if distribution_completed is False:
114 logger.error("Service Distribution for %s failed !!", svc.name)