nsi_instantiate,
ns_migrate,
ns_verticalscale,
+ nslcmop_cancel,
)
from osm_nbi.base_topic import (
BaseTopic,
return ns_k8s_namespace
+ def _add_shared_volumes_to_nsr(
+ self, vdu, vnfd, nsr_descriptor, member_vnf_index, revision=None
+ ):
+ svsd = []
+ for vsd in vnfd.get("virtual-storage-desc", ()):
+ if vsd.get("vdu-storage-requirements"):
+ if (
+ vsd.get("vdu-storage-requirements")[0].get("key") == "multiattach"
+ and vsd.get("vdu-storage-requirements")[0].get("value") == "True"
+ ):
+ # Avoid setting the volume name multiple times
+ if not match(f"shared-.*-{vnfd['id']}", vsd["id"]):
+ vsd["id"] = f"shared-{vsd['id']}-{vnfd['id']}"
+ svsd.append(vsd)
+ if svsd:
+ nsr_descriptor["shared-volumes"] = svsd
+
def _add_flavor_to_nsr(
self, vdu, vnfd, nsr_descriptor, member_vnf_index, revision=None
):
"flavor": [],
"image": [],
"affinity-or-anti-affinity-group": [],
+ "shared-volumes": [],
}
if "revision" in nsd["_admin"]:
nsr_descriptor["revision"] = nsd["_admin"]["revision"]
for vdu in vnfd.get("vdu", ()):
member_vnf_index = vnf_profile.get("id")
self._add_flavor_to_nsr(vdu, vnfd, nsr_descriptor, member_vnf_index)
+ self._add_shared_volumes_to_nsr(
+ vdu, vnfd, nsr_descriptor, member_vnf_index
+ )
sw_image_id = vdu.get("sw-image-desc")
if sw_image_id:
image_data = self._get_image_data_from_vnfd(vnfd, sw_image_id)
)
vld["name"] = vld["id"]
nsr_descriptor["vld"] = nsr_vld
-
return nsr_descriptor
def _get_affinity_or_anti_affinity_group_data_from_vnfd(
if (
cpd.get("constituent-cpd-id")
== iface_ext_cp
- ):
+ ) and vnf_profile.get("id") == vnf_index:
vdu_iface["ns-vld-id"] = vlc.get(
"virtual-link-profile-id"
)
if nsr_flavor_desc:
vdur["ns-flavor-id"] = nsr_flavor_desc["id"]
+ # Adding Shared Volume information to vdur
+ if vdur.get("virtual-storages"):
+ nsr_sv = []
+ for vsd in vdur["virtual-storages"]:
+ if vsd.get("vdu-storage-requirements"):
+ if (
+ vsd["vdu-storage-requirements"][0].get("key")
+ == "multiattach"
+ and vsd["vdu-storage-requirements"][0].get("value")
+ == "True"
+ ):
+ nsr_sv.append(vsd["id"])
+ if nsr_sv:
+ vdur["shared-volumes-id"] = nsr_sv
+
# Adding Affinity groups information to vdur
try:
vdu_profile_affinity_group = utils.find_in_list(
vdur["id"] = vdur["_id"]
vdur["count-index"] = index
vnfr_descriptor["vdur"].append(vdur)
-
return vnfr_descriptor
def vca_status_refresh(self, session, ns_instance_content, filter_q):
"terminate": ns_terminate,
"migrate": ns_migrate,
"verticalscale": ns_verticalscale,
+ "cancel": nslcmop_cancel,
}
def __init__(self, db, fs, msg, auth):
vnf_index = vnfr["member-vnf-index-ref"]
self.logger.info("nsr {}".format(nsr))
for vdu in vnfd["vdu"]:
+ self.nsrtopic._add_shared_volumes_to_nsr(
+ vdu, vnfd, nsr, vnf_index, latest_vnfd_revision
+ )
self.nsrtopic._add_flavor_to_nsr(
vdu, vnfd, nsr, vnf_index, latest_vnfd_revision
)
self.nsrtopic._add_image_to_nsr(nsr, image_data)
nsr_update["image"] = nsr["image"]
nsr_update["flavor"] = nsr["flavor"]
+ nsr_update["shared-volumes"] = nsr["shared-volumes"]
self.db.set_one("nsrs", {"_id": nsr["_id"]}, nsr_update)
ns_k8s_namespace = self.nsrtopic._get_ns_k8s_namespace(
nsd, ns_request, session
# except DbException as e:
# raise EngineException("Cannot get ns_instance '{}': {}".format(e), HTTPStatus.NOT_FOUND)
+ def cancel(self, rollback, session, indata=None, kwargs=None, headers=None):
+ validate_input(indata, self.operation_schema["cancel"])
+ # Override descriptor with query string kwargs
+ self._update_input_with_kwargs(indata, kwargs, yaml_format=True)
+ nsLcmOpOccId = indata["nsLcmOpOccId"]
+ cancelMode = indata["cancelMode"]
+ # get nslcmop from nsLcmOpOccId
+ _filter = BaseTopic._get_project_filter(session)
+ _filter["_id"] = nsLcmOpOccId
+ nslcmop = self.db.get_one("nslcmops", _filter)
+ # Fail is this is not an ongoing nslcmop
+ if nslcmop.get("operationState") not in [
+ "STARTING",
+ "PROCESSING",
+ "ROLLING_BACK",
+ ]:
+ raise EngineException(
+ "Operation is not in STARTING, PROCESSING or ROLLING_BACK state",
+ http_code=HTTPStatus.CONFLICT,
+ )
+ nsInstanceId = nslcmop["nsInstanceId"]
+ update_dict = {
+ "isCancelPending": True,
+ "cancelMode": cancelMode,
+ }
+ self.db.set_one(
+ "nslcmops", q_filter=_filter, update_dict=update_dict, fail_on_empty=False
+ )
+ data = {
+ "_id": nsLcmOpOccId,
+ "nsInstanceId": nsInstanceId,
+ "cancelMode": cancelMode,
+ }
+ self.msg.write("nslcmops", "cancel", data)
+
def delete(self, session, _id, dry_run=False, not_send_msg=None):
raise EngineException(
"Method delete called directly", HTTPStatus.INTERNAL_SERVER_ERROR