+ # cloud-init
+ boot_data = {}
+ if vdu.get("cloud-init"):
+ boot_data["user-data"] = str(vdu["cloud-init"])
+ elif vdu.get("cloud-init-file"):
+ # TODO Where this file content is present???
+ # boot_data["user-data"] = vnfd_yang.files[vdu["cloud-init-file"]]
+ boot_data["user-data"] = str(vdu["cloud-init-file"])
+
+ if vdu.get("supplemental-boot-data"):
+ if vdu["supplemental-boot-data"].get('boot-data-drive'):
+ boot_data['boot-data-drive'] = True
+ if vdu["supplemental-boot-data"].get('config-file'):
+ om_cfgfile_list = list()
+ for custom_config_file in vdu["supplemental-boot-data"]['config-file'].itervalues():
+ # TODO Where this file content is present???
+ cfg_source = str(custom_config_file["source"])
+ om_cfgfile_list.append({"dest": custom_config_file["dest"],
+ "content": cfg_source})
+ boot_data['config-files'] = om_cfgfile_list
+ if boot_data:
+ db_vm["boot_data"] = yaml.safe_dump(boot_data, default_flow_style=True, width=256)
+
+ db_vms.append(db_vm)
+ db_vms_index += 1
+
+ # table interfaces (internal/external interfaces)
+ flavor_epa_interfaces = []
+ vdu_id2cp_name = {} # stored only when one external connection point is presented at this VDU
+ # for iface in chain(vdu.get("internal-interface").itervalues(), vdu.get("external-interface").itervalues()):
+ for iface in vdu.get("interface").itervalues():
+ flavor_epa_interface = {}
+ iface_uuid = str(uuid4())
+ uuid_list.append(iface_uuid)
+ db_interface = {
+ "uuid": iface_uuid,
+ "internal_name": get_str(iface, "name", 255),
+ "vm_id": vm_uuid,
+ }
+ flavor_epa_interface["name"] = db_interface["internal_name"]
+ if iface.get("virtual-interface").get("vpci"):
+ db_interface["vpci"] = get_str(iface.get("virtual-interface"), "vpci", 12)
+ flavor_epa_interface["vpci"] = db_interface["vpci"]
+
+ if iface.get("virtual-interface").get("bandwidth"):
+ bps = int(iface.get("virtual-interface").get("bandwidth"))
+ db_interface["bw"] = int(math.ceil(bps/1000000.0))
+ flavor_epa_interface["bandwidth"] = "{} Mbps".format(db_interface["bw"])
+
+ if iface.get("virtual-interface").get("type") == "OM-MGMT":
+ db_interface["type"] = "mgmt"
+ elif iface.get("virtual-interface").get("type") in ("VIRTIO", "E1000"):
+ db_interface["type"] = "bridge"
+ db_interface["model"] = get_str(iface.get("virtual-interface"), "type", 12)
+ elif iface.get("virtual-interface").get("type") in ("SR-IOV", "PCI-PASSTHROUGH"):
+ db_interface["type"] = "data"
+ db_interface["model"] = get_str(iface.get("virtual-interface"), "type", 12)
+ flavor_epa_interface["dedicated"] = "no" if iface["virtual-interface"]["type"] == "SR-IOV" \
+ else "yes"
+ flavor_epa_interfaces.append(flavor_epa_interface)
+ else:
+ raise NfvoException("Error. Invalid VNF descriptor at 'vnfd[{}]':'vdu[{}]':'interface':'virtual"
+ "-interface':'type':'{}'. Interface type is not supported".format(
+ vnfd_id, vdu_id, iface.get("virtual-interface").get("type")),
+ HTTP_Bad_Request)
+
+ if iface.get("external-connection-point-ref"):
+ try:
+ cp = vnfd.get("connection-point")[iface.get("external-connection-point-ref")]
+ db_interface["external_name"] = get_str(cp, "name", 255)
+ cp_name2iface_uuid[db_interface["external_name"]] = iface_uuid
+ cp_name2vm_uuid[db_interface["external_name"]] = vm_uuid
+ cp_name2db_interface[db_interface["external_name"]] = db_interface
+ for cp_descriptor in vnfd_descriptor["connection-point"]:
+ if cp_descriptor["name"] == db_interface["external_name"]:
+ break
+ else:
+ raise KeyError()
+
+ if vdu_id in vdu_id2cp_name:
+ vdu_id2cp_name[vdu_id] = None # more than two connecdtion point for this VDU
+ else:
+ vdu_id2cp_name[vdu_id] = db_interface["external_name"]
+
+ # port security
+ if str(cp_descriptor.get("port-security-enabled")).lower() == "false":
+ db_interface["port_security"] = 0
+ elif str(cp_descriptor.get("port-security-enabled")).lower() == "true":
+ db_interface["port_security"] = 1
+ except KeyError:
+ raise NfvoException("Error. Invalid VNF descriptor at 'vnfd[{vnf}]':'vdu[{vdu}]':"
+ "'interface[{iface}]':'vnfd-connection-point-ref':'{cp}' is not present"
+ " at connection-point".format(
+ vnf=vnfd_id, vdu=vdu_id, iface=iface["name"],
+ cp=iface.get("vnfd-connection-point-ref")),
+ HTTP_Bad_Request)
+ elif iface.get("internal-connection-point-ref"):
+ try:
+ for vld in vnfd.get("internal-vld").itervalues():
+ for cp in vld.get("internal-connection-point").itervalues():
+ if cp.get("id-ref") == iface.get("internal-connection-point-ref"):
+ db_interface["net_id"] = net_id2uuid[vld.get("id")]
+ for cp_descriptor in vnfd_descriptor["connection-point"]:
+ if cp_descriptor["name"] == db_interface["external_name"]:
+ break
+ if str(cp_descriptor.get("port-security-enabled")).lower() == "false":
+ db_interface["port_security"] = 0
+ elif str(cp_descriptor.get("port-security-enabled")).lower() == "true":
+ db_interface["port_security"] = 1
+ break
+ except KeyError:
+ raise NfvoException("Error. Invalid VNF descriptor at 'vnfd[{vnf}]':'vdu[{vdu}]':"
+ "'interface[{iface}]':'vdu-internal-connection-point-ref':'{cp}' is not"
+ " referenced by any internal-vld".format(
+ vnf=vnfd_id, vdu=vdu_id, iface=iface["name"],
+ cp=iface.get("vdu-internal-connection-point-ref")),
+ HTTP_Bad_Request)
+ if iface.get("position") is not None:
+ db_interface["created_at"] = int(iface.get("position")) - 1000
+ db_interfaces.append(db_interface)
+