SOL003 API Align
[vfc/nfvo/lcm.git] / lcm / ns_sfcs / biz / utils.py
1 # Copyright 2016 ZTE Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 import logging
15
16 from lcm.pub.database.models import FPInstModel
17
18 logger = logging.getLogger(__name__)
19
20
21 def sfc_inst_failed_handle(fp_inst_id, error_msg):
22     logger.error('create sfc  failed, detail message: %s' % error_msg)
23     FPInstModel.objects.filter(fpid=fp_inst_id).update(status="disabled").get()
24
25
26 def ignorcase_get(args, key):
27     if not key:
28         return ""
29     if key in args:
30         return args[key]
31     for oldkey in args:
32         if oldkey.upper() == key.upper():
33             return args[oldkey]
34     return ""
35
36
37 def ignor_dot(str):
38     index = str.find('.')
39     if index == -1:
40         return str
41     return str[0:index]
42
43
44 def get_fp_id(fpindex, ns_model):
45     index = int(int(float(fpindex)) - 1)
46     return ns_model['fps'][index].get("fp_id")
47
48
49 def update_fp_status(fp_inst_id, status_info):
50     FPInstModel.objects.filter(fpinstid=fp_inst_id).update(status=status_info)
51
52
53 def get_fp_model_by_fp_inst_id(ns_model_data, fp_inst_id):
54     fp_databas_info = FPInstModel.objects.filter(fpinstid=fp_inst_id).get()
55     fps_model = ns_model_data["fps"]
56     for fp_model in fps_model:
57         if fp_model["fp_id"] == fp_databas_info.fpid:
58             return fp_model