summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/nf/biz/scale_vnf.py2
-rw-r--r--lcm/lcm/nf/biz/scale_vnf_to_level.py93
-rw-r--r--lcm/lcm/nf/views/scale_to_level_view.py3
3 files changed, 96 insertions, 2 deletions
diff --git a/lcm/lcm/nf/biz/scale_vnf.py b/lcm/lcm/nf/biz/scale_vnf.py
index 404b0369..dfabec2f 100644
--- a/lcm/lcm/nf/biz/scale_vnf.py
+++ b/lcm/lcm/nf/biz/scale_vnf.py
@@ -47,7 +47,7 @@ class ScaleVnf(Thread):
def run(self):
try:
- self.heal_pre()
+ self.scale_pre()
JobUtil.add_job_status(self.job_id,
50,
"Start to apply grant.")
diff --git a/lcm/lcm/nf/biz/scale_vnf_to_level.py b/lcm/lcm/nf/biz/scale_vnf_to_level.py
new file mode 100644
index 00000000..03189e9a
--- /dev/null
+++ b/lcm/lcm/nf/biz/scale_vnf_to_level.py
@@ -0,0 +1,93 @@
+# Copyright (C) 2019 ZTE. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import json
+import logging
+
+from lcm.nf.biz.scale_vnf import ScaleVnf
+from lcm.nf.const import GRANT_TYPE
+from lcm.pub.database.models import VmInstModel
+from lcm.pub.exceptions import NFLCMException
+
+logger = logging.getLogger(__name__)
+
+
+class ScaleVnfToLevel(ScaleVnf):
+ def __init__(self, data, nf_inst_id, job_id):
+ super(ScaleVnfToLevel, self).__init__(data=data,
+ nf_inst_id=nf_inst_id,
+ job_id=job_id)
+ self.aspect_id = ''
+
+ def scale_pre(self):
+ self.vnfd_info = json.loads(self.vnf_insts[0].vnfd_model)
+ scale_in_vms = VmInstModel.objects.filter(instid=self.nf_inst_id)
+ vms_num = scale_in_vms.count()
+ self.instantiation_level_id = self.data.get("instantiationLevelId")
+ self.additional_params = self.data.get("additionalParams", {})
+ if not self.instantiation_level_id:
+ self.scale_info = self.data.get("scaleInfo")
+ self.aspect_id = self.scale_info.get("aspectId")
+ self.instantiation_level_id = self.get_instantiation_level_id()
+ else:
+ self.aspect_id = self.get_aspect_id()
+
+ number_of_instances = self.get_number_of_instances()
+ if number_of_instances == vms_num:
+ raise NFLCMException("Don't need scale in/out.")
+ elif number_of_instances > vms_num:
+ self.scale_type = GRANT_TYPE.SCALE_OUT
+ else:
+ self.scale_type = GRANT_TYPE.SCALE_IN
+
+ self.scale_inst_num = abs(number_of_instances - vms_num)
+ self.is_scale_in = (self.scale_type == GRANT_TYPE.SCALE_IN)
+ self.step_delta = self.get_scale_step_delta()
+ self.target_vdu, self.step_inst_num = self.get_vdu_scale_aspect_deltas()
+ self.min_instance_num, self.max_instance_num = self.get_instance_range()
+ self.check_if_can_scale()
+ self.scale_out_resource = {}
+
+ def get_number_of_instances(self):
+ for policy in self.vnfd_info.get("policies", []):
+ if policy.get("type") != "tosca.policies.nfv.VduInstantiationLevels":
+ continue
+ # if not self.aspect_id:
+ # self.aspect_id = policy.get("targets")[0]
+ levels = policy["properties"]["levels"]
+ number_of_instances = levels.get(self.instantiation_level_id)
+ if number_of_instances:
+ return number_of_instances.get("number_of_instances")
+ raise NFLCMException("InstantiationLevelId(%s) does not exist" % self.instantiation_level_id)
+
+ def get_instantiation_level_id(self):
+ scale_level_in_request = self.scale_info.get("scaleLevel")
+ for policy in self.vnfd_info.get("policies", []):
+ if policy.get("type") != "tosca.policies.nfv.InstantiationLevels":
+ continue
+ levels = policy["properties"]["levels"]
+ for level_id, level_info in levels.items():
+ scale_aspect = level_info["scale_info"].get(self.aspect_id)
+ scale_level_in_vnfd = scale_aspect["scale_level"]
+ if scale_level_in_request == scale_level_in_vnfd:
+ return level_id
+ raise NFLCMException("Failed to get scale_info in vnfd")
+
+ def get_aspect_id(self):
+ for policy in self.vnfd_info.get("policies", []):
+ if policy.get("type") != "tosca.policies.nfv.InstantiationLevels":
+ continue
+ levels = policy["properties"]["levels"]
+ level_info = levels.get(self.instantiation_level_id)
+ return level_info.get("scale_info").keys()[0]
+ raise NFLCMException("Failed to get aspect_id in vnfd")
diff --git a/lcm/lcm/nf/views/scale_to_level_view.py b/lcm/lcm/nf/views/scale_to_level_view.py
index 9dafc9ec..9ae2cd36 100644
--- a/lcm/lcm/nf/views/scale_to_level_view.py
+++ b/lcm/lcm/nf/views/scale_to_level_view.py
@@ -26,6 +26,7 @@ from lcm.pub.exceptions import NFLCMException, NFLCMExceptionNotFound, NFLCMExce
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.database.models import NfInstModel
from lcm.nf.const import VNF_STATUS
+from lcm.nf.biz.scale_vnf_to_level import ScaleVnfToLevel
logger = logging.getLogger(__name__)
@@ -51,7 +52,7 @@ class ScaleVnfToLevelView(APIView):
JobUtil.add_job_status(job_id, 0, "SCALE_VNF_TO_LEVEL_READY")
self.scale_pre_check(instanceid, job_id)
- # ScaleVnfToLevel(scale_to_level_serializer.data, instanceid, job_id).start()
+ ScaleVnfToLevel(scale_to_level_serializer.data, instanceid, job_id).start()
response = Response(data={"jobId": job_id},
status=status.HTTP_202_ACCEPTED)