+ check_orchestration_status(service_instantiation)
+
+
+def get_base_vf_module(vf_modules):
+ base_vf_module = next(vf_module for vf_module in vf_modules if vf_module.properties["isBase"])
+ return base_vf_module
+
+
+def is_base(vf_module):
+ if vf_module.properties["isBase"]:
+ return True
+ return False
+
+
+def instantiate_vf_module(vf_module, vf_module_param_list, vnf_instance, sdnc_model_name, sdnc_model_version):
+ vf_module_label = vf_module.properties["vf_module_label"]
+ region_id = vf_module_param_list[vf_module_label]["cloud_configuration"]
+ cloud_region = get_cloud_region(
+ Config.CLOUD_REGIONS[region_id]["cloud_owner"],
+ region_id)
+ tenant = get_tenant(cloud_region, Config.CLOUD_REGIONS[region_id]["tenant"]["name"])
+
+ vfmodule_instantiation_parameters = vf_module_param_list[vf_module_label]["instantiation_parameters"].items()
+
+ base_parameters = [
+ InstantiationParameter(name="sdnc_model_name", value=sdnc_model_name),
+ InstantiationParameter(name="sdnc_model_version", value=sdnc_model_version),
+ InstantiationParameter(name="vf_module_label", value=vf_module_label)]
+
+ for instantiation_parameter_key, instantiation_parameter_value in vfmodule_instantiation_parameters:
+ base_parameters.append(InstantiationParameter(name=instantiation_parameter_key,
+ value=instantiation_parameter_value))
+
+ vf_module_instantiation = vnf_instance.add_vf_module(
+ vf_module=vf_module,
+ cloud_region=cloud_region,
+ tenant=tenant,
+ vnf_parameters=base_parameters,
+ use_preload=False
+ )
+ check_orchestration_status(vf_module_instantiation)
+
+
+def check_vf_module_list_correct(vf_modules, vf_module_param_list):
+ labels = set()
+ for vf_module in vf_modules:
+ labels.add(vf_module.properties["vf_module_label"])
+ if vf_module_param_list.keys() == labels:
+ return True
+ else:
+ return False
+
+
+def instantiate_service_alacarte(service_subscription, service_instance_name,
+ sdnc_model_name, sdnc_model_version, sdnc_artifact_name, vnf_param_list,
+ vf_module_param_list, service, cloud_region, tenant, customer, owning_entity,
+ vid_project, vid_line_of_business, vid_platform):
+ # Tworzenie Serwisu
+ service_instantiation = ServiceInstantiation.instantiate_ala_carte(
+ sdc_service=service,
+ cloud_region=cloud_region,
+ tenant=tenant,
+ customer=customer,
+ owning_entity=owning_entity,
+ project=vid_project,
+ service_instance_name=service_instance_name
+ )
+ check_orchestration_status(service_instantiation)
+ # Koniec tworzenia Serwisu
+
+ service_instance = service_subscription.get_service_instance_by_name(service_instance_name)
+ # Dodawanie VNFs (VF) do Serwisu
+ for vnf in service.vnfs:
+ vnf_parameters = get_vnf_parameters(sdnc_model_name, sdnc_model_version, sdnc_artifact_name, vnf_param_list)
+ vnf_instantiation = service_instance.add_vnf(
+ # vnf_instance_name=vf_name, TODO: support for multiple vnf in config file
+ vnf=vnf,
+ line_of_business=vid_line_of_business,
+ platform=vid_platform,
+ vnf_parameters=vnf_parameters
+ )
+ check_orchestration_status(vnf_instantiation)
+
+ # Dodawanie VF Modulow
+ vnf_type = service.name + "/" + vnf.name
+ vnf_instance = next((vnf for vnf in service_instance.vnf_instances if vnf.vnf_type == vnf_type), None)
+
+ if check_vf_module_list_correct(vnf.vf_modules, vf_module_param_list):
+ for vf_module_label in vf_module_param_list:
+ vf_module = next(
+ vf_module for vf_module in vnf.vf_modules if
+ vf_module.properties["vf_module_label"] == vf_module_label)
+ instantiate_vf_module(vf_module, vf_module_param_list, vnf_instance, sdnc_model_name,
+ sdnc_model_version)
+ else:
+ logger.error("VF_MODULE_PARAM_LIST error. ")
+ # Koniec dodawania VF Modulow
+ # Koniec dodawania VNFs
+
+ # # Dodanie base
+ # base_vf_module = get_base_vf_module(vnf.vf_modules)
+ # instantiate_vf_module(base_vf_module, vf_module_param_list, vnf_instance, sdnc_model_name, sdnc_model_version)
+ # # Dodanie reszty
+ # for vf_module in vnf.vf_modules:
+ # if not is_base(vf_module):
+ # instantiate_vf_module(vf_module, vf_module_param_list, vnf_instance, sdnc_model_name,
+ # sdnc_model_version)
+
+
+def main():
+ logger.info("*******************************")
+ logger.info("**** SERVICE INSTANTIATION ****")
+ logger.info("*******************************")
+
+ logger.info("******** GET Customer *******")
+ customer = get_customer(Config.GLOBAL_CUSTOMER_ID)
+
+ logger.info("******** GET Service Model from SDC *******")
+ service = get_service_model(Config.SERVICENAME)
+
+ logger.info("******** Subscribe Customer for Service *******")
+ subscribe_service_customer(customer, service)
+
+ logger.info("******** Get Tenant *******")
+ basic_cloud_region_name = next(iter(Config.CLOUD_REGIONS.keys()))
+ cloud_region = get_cloud_region(Config.CLOUD_REGIONS[basic_cloud_region_name]["cloud_owner"],
+ basic_cloud_region_name)
+ tenant = get_tenant(cloud_region,
+ Config.CLOUD_REGIONS[basic_cloud_region_name]["tenant"]["name"])
+
+ ######
+ logger.info("******** Connect Service to Tenant *******")
+ service_subscription = None
+ for service_sub in customer.service_subscriptions:
+ logger.debug("Service subscription %s is found", service_sub.service_type)
+ if service_sub.service_type == Config.SERVICENAME:
+ logger.info("Service %s subscribed", Config.SERVICENAME)
+ service_subscription = service_sub
+ break
+
+ if not service_subscription:
+ logger.error("Service subscription %s is not found", Config.SERVICENAME)
+ exit(1)
+
+ service_subscription.link_to_cloud_region_and_tenant(cloud_region, tenant)
+ ####
+
+ logger.info("******** Business Objects (OE, P, Pl, LoB) *******")
+ project = Config.PROJECT
+ platform = Config.PLATFORM
+ line_of_business = Config.LINE_OF_BUSINESS
+ owning_entity = add_owning_entity(Config.OWNING_ENTITY)
+
+ logger.info("******** Delete old profiles ********")
+ delete_old_profiles(service)
+
+ logger.info("******** Read SDNC MODEL NAME and VERSION from CBA.zip ********")
+ sdnc_model_name, sdnc_model_version = read_sdnc_model_details(Config.VSPFILE)
+
+ logger.info("******** Instantiate Service *******")
+ service_instance = check_service_instance_exists(service_subscription, Config.SERVICE_INSTANCE_NAME)
+ if service_instance:
+ logger.info("******** Service Instance exists, do not instantiate *******")
+ else:
+ logger.info("******** Service Instance not existing: Instantiate *******")
+ if Config.MACRO_INSTANTIATION:
+ instantiate_service_macro(Config.SERVICE_INSTANCE_NAME, sdnc_model_name,
+ sdnc_model_version, Config.SDNC_ARTIFACT_NAME, Config.VFNAME,
+ Config.VNF_PARAM_LIST,
+ Config.VF_MODULE_PARAM_LIST,
+ service, cloud_region, tenant, customer, owning_entity, project,
+ line_of_business, platform, service_subscription)
+ else:
+ instantiate_service_alacarte(service_subscription, Config.SERVICE_INSTANCE_NAME, sdnc_model_name,
+ sdnc_model_version, Config.SDNC_ARTIFACT_NAME, Config.VNF_PARAM_LIST,
+ Config.VF_MODULE_PARAM_LIST,
+ service, cloud_region, tenant, customer, owning_entity, project,
+ line_of_business, platform)
+
+
+if __name__ == "__main__":
+ main()