1 # Copyright 2017 ZTE Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 from threading import Thread
21 from lcm.pub.database.models import NfInstModel, JobStatusModel
22 from lcm.pub.exceptions import NFLCMException
23 from lcm.pub.utils.jobutil import JobUtil
25 logger = logging.getLogger(__name__)
28 class InstVnf(Thread):
29 def __init__(self, data, nf_inst_id, job_id):
30 super(InstVnf, self).__init__()
32 self.nf_inst_id = nf_inst_id
37 self.inst_pre(self.nf_inst_id)
39 # self.apply_grant(args)
40 # self.apply_res(args)
41 # self.check_res_status(args)
42 # self.wait_inst_finish(args)
43 # self.lcm_notify(args)
44 except NFLCMException as e:
45 self.inst_exception(e.message)
48 logger.error(traceback.format_exc())
49 self.inst_exception('unexpected exception')
51 def inst_pre(self, args):
53 logger.info('inst_pre, args=%s' % args)
54 is_exist = NfInstModel.objects.filter(nfinstid=self.nf_inst_id).exists()
55 logger.debug("check_ns_inst_name_exist::is_exist=%s" % is_exist)
57 JobUtil.add_job_status(self.job_id, 255, "VNF nf_inst_id is not exist.")
58 raise NFLCMException('VNF nf_inst_id is not exist.')
60 JobUtil.add_job_status(self.job_id, 100, "Instantiate Vnf success.")
61 is_exist = JobStatusModel.objects.filter(jobid=self.job_id).exists()
62 logger.debug("check_ns_inst_name_exist::is_exist=%s" % is_exist)
63 except Exception as e:
64 logger.error('Nf instancing preprocess exception=%s' % e.message)
65 logger.error(traceback.format_exc())
66 return {'result': '255', 'msg': 'Nf instancing preprocess exception', 'context': {}}
68 def apply_grant(self, args):
70 logger.info('apply_grant, args=%s' % args)
71 # ApplyGrantTask(args).do_biz()
72 return {'result': '100', 'msg': 'Nf instancing apply grant finish', 'context': {}}
73 except Exception as e:
74 logger.error('Nf instancing apply grant exception=%s' % e.message)
75 logger.error(traceback.format_exc())
76 return {'result': '255', 'msg': 'Nf instancing apply grant exception', 'context': {}}
78 def apply_res(self, args):
80 logger.info('apply_res, args=%s' % args)
81 # ApplyResTask(args).do_biz()
82 return {'result': '100', 'msg': 'Nf instancing apply resource finish', 'context': {}}
83 except Exception as e:
84 logger.error('Nf instancing apply resource exception=%s' % e.message)
85 logger.error(traceback.format_exc())
86 return {'result': '255', 'msg': 'Nf instancing apply resource exception', 'context': {}}
88 def check_res_status(self, args):
90 logger.info('check_res_status, args=%s' % args)
91 # CheckResStatusTask(args).do_biz()
92 return {'result': '100', 'msg': 'Nf instancing check resource status finish', 'context': {}}
93 except Exception as e:
94 logger.error('Nf instancing check resource status exception=%s' % e.message)
95 logger.error(traceback.format_exc())
96 return {'result': '255', 'msg': 'Nf instancing check resource status exception', 'context': {}}
98 def wait_inst_finish(self, args):
100 logger.info('wait_inst_finish, args=%s' % args)
101 # WaitInstFinishTask(args).do_biz()
102 return {'result': '100', 'msg': 'Nf instancing wait finish', 'context': {}}
103 except Exception as e:
104 logger.error('Nf instancing wait exception=%s' % e.message)
105 logger.error(traceback.format_exc())
106 return {'result': '255', 'msg': 'Nf instancing wait exception', 'context': {}}
108 def lcm_notify(self, args):
110 logger.info('lcm_notify, args=%s' % args)
111 # LcmNotifyTask(args).do_biz()
112 return {'result': '100', 'msg': 'Nf instancing lcm notify finish', 'context': {}}
113 except Exception as e:
114 logger.error('Nf instancing lcm notify exception=%s' % e.message)
115 logger.error(traceback.format_exc())
116 return {'result': '255', 'msg': 'Nf instancing lcm notify exception', 'context': {}}
118 def inst_exception(self, args):
120 logger.info('inst_exception, args=%s' % args)
121 # InstExceptionTask(args).do_biz()
122 return {'result': '100', 'msg': 'Nf instancing exception process finish', 'context': {}}
123 except Exception as e:
124 logger.error('Nf instancing exception process exception=%s' % e.message)
125 logger.error(traceback.format_exc())
126 return {'result': '255', 'msg': 'Nf instancing exception process exception', 'context': {}}