return openmano
def cloud_init(rift_vnfd_id, vdu):
- """ Populate cloud_init with cloud-config script from
+ """ Populate cloud_init with script from
either the inline contents or from the file provided
"""
vnfd_package_store = rift.package.store.VnfdPackageFilesystemStore(logger)
return
logger.debug("Current cloud init msg is {}".format(cloud_init_msg))
- if cloud_init_msg:
- try:
- cloud_init_dict = yaml.load(cloud_init_msg)
- except Exception as e:
- logger.exception(e)
- logger.error("Error loading cloud init Yaml file with exception %s", str(e))
- return cloud_init_msg
+ return cloud_init_msg
- logger.debug("Current cloud init dict is {}".format(cloud_init_dict))
+def config_file_init(rift_vnfd_id, vdu, cfg_file):
+ """ Populate config file init with file provided
+ """
+ vnfd_package_store = rift.package.store.VnfdPackageFilesystemStore(logger)
- cloud_msg = yaml.safe_dump(cloud_init_dict,width=1000,default_flow_style=False)
- cloud_init = "#cloud-config\n"+cloud_msg
- logger.debug("Cloud init msg is {}".format(cloud_init))
- return cloud_init
+ # Get script contents from the file provided in the cloud_init directory
+ logger.debug("config file script provided in file {}".format(cfg_file))
+ filename = cfg_file
+ vnfd_package_store.refresh()
+ stored_package = vnfd_package_store.get_package(rift_vnfd_id)
+ cloud_init_extractor = rift.package.cloud_init.PackageCloudInitExtractor(logger)
+ try:
+ cfg_file_msg = cloud_init_extractor.read_script(stored_package, filename)
+ except rift.package.cloud_init.CloudInitExtractionError as e:
+ raise ValueError(e)
+
+ logger.debug("Current config file msg is {}".format(cfg_file_msg))
+ return cfg_file_msg
def rift2openmano_vnfd(rift_vnfd, rift_nsd):
openmano_vnf = {"vnf":{}}
connection = {
"name": vld.name,
"description": vld.description,
- "type": "data",
+ "type": "bridge",
"elements": [],
}
if vdu.vm_flavor.has_field("vcpu_count"):
vnfc["numas"][0]["cores"] = max(vdu.vm_flavor.vcpu_count, 1)
- else:
- if vdu.vm_flavor.has_field("vcpu_count") and vdu.vm_flavor.vcpu_count:
- vnfc["vcpus"] = vdu.vm_flavor.vcpu_count
+ if vdu.vm_flavor.has_field("vcpu_count") and vdu.vm_flavor.vcpu_count:
+ vnfc["vcpus"] = vdu.vm_flavor.vcpu_count
- if vdu.vm_flavor.has_field("memory_mb") and vdu.vm_flavor.memory_mb:
- vnfc["ram"] = vdu.vm_flavor.memory_mb
+ if vdu.vm_flavor.has_field("memory_mb") and vdu.vm_flavor.memory_mb:
+ vnfc["ram"] = vdu.vm_flavor.memory_mb
if vdu.has_field("hypervisor_epa"):
# Add Openmano devices
device = {}
device["type"] = volume.device_type
- device["image"] = volume.image
+ device["image name"] = volume.image
+ if volume.has_field("image_checksum"):
+ device["image checksum"] = volume.image_checksum
vnfc["devices"].append(device)
- vnfc_cloud_config_init = False
+ vnfc_boot_data_init = False
if vdu.has_field("cloud_init") or vdu.has_field("cloud_init_file"):
- vnfc['cloud-config'] = dict()
- vnfc_cloud_config_init = True
- vnfc['cloud-config']['user-data'] = cloud_init(rift_vnfd.id, vdu)
+ vnfc['boot-data'] = dict()
+ vnfc_boot_data_init = True
+ vnfc['boot-data']['user-data'] = cloud_init(rift_vnfd.id, vdu)
if vdu.has_field("supplemental_boot_data"):
if vdu.supplemental_boot_data.has_field('boot_data_drive'):
if vdu.supplemental_boot_data.boot_data_drive is True:
- if vnfc_cloud_config_init is False:
- vnfc['cloud-config'] = dict()
- vnfc_cloud_config_init = True
- vnfc['cloud-config']['config-drive'] = vdu.supplemental_boot_data.boot_data_drive
- if vdu.supplemental_boot_data.has_field('custom_meta_data'):
- if vnfc_cloud_config_init is False:
- vnfc['cloud-config'] = dict()
- vnfc_cloud_config_init = True
- vnfc['cloud-config']['meta-data'] = list()
- for metaitem in vdu.supplemental_boot_data.custom_meta_data:
- openmano_metaitem = dict()
- openmano_metaitem['key'] = metaitem.name
- openmano_metaitem['value'] = metaitem.value
- vnfc['cloud-config']['meta-data'].append(openmano_metaitem)
+ if vnfc_boot_data_init is False:
+ vnfc['boot-data'] = dict()
+ vnfc_boot_data_init = True
+ vnfc['boot-data']['boot-data-drive'] = vdu.supplemental_boot_data.boot_data_drive
+
+ if vdu.supplemental_boot_data.has_field('config_file'):
+ om_cfgfile_list = list()
+ for custom_config_file in vdu.supplemental_boot_data.config_file:
+ cfg_source = config_file_init(rift_vnfd.id, vdu, custom_config_file.source)
+ om_cfgfile_list.append({"dest":custom_config_file.dest, "content": cfg_source})
+ vnfc['boot-data']['config-files'] = om_cfgfile_list
+
vnf["VNFC"].append(vnfc)
if bps/x[1] >= 1:
intf["bandwidth"] = "{} {}bps".format(math.ceil(bps/x[1]), x[0])
+ # Sort bridge-ifaces-list TODO sort others
+ newlist = sorted(vnfc["bridge-ifaces"], key=lambda k: k['name'])
+ vnfc["bridge-ifaces"] = newlist
return openmano_vnf