Check whether the database is updated
[vfc/gvnfm/vnflcm.git] / lcm / lcm / nf / vnfs / create_vnfs.py
1 # Copyright 2017 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
15 import logging
16 import traceback
17 from threading import Thread
18
19 from lcm.pub.exceptions import NFLCMException
20
21 logger = logging.getLogger(__name__)
22
23
24 class CreateVnfs(Thread):
25     def __init__(self, data, nf_inst_id, job_id):
26         super(CreateVnfs, self).__init__()
27         self.data = data
28         self.nf_inst_id = nf_inst_id
29         self.job_id = job_id
30
31     def run(self):
32         try:
33             args = {}
34             self.inst_pre(args)
35             self.apply_grant(args)
36             self.apply_res(args)
37             self.check_res_status(args)
38             self.wait_inst_finish(args)
39             self.lcm_notify(args)
40         except NFLCMException as e:
41             self.inst_exception(e.message)
42             pass
43         except Exception:
44             logger.error(traceback.format_exc())
45             self.inst_exception('unexpected exception')
46
47     def inst_pre(self, args):
48         try:
49             logger.info('inst_pre, args=%s' % args)
50             # InstPreTask(args).do_biz()
51             return {'result': '100', 'sessionid': '', 'msg': 'Nf instancing preprocess finish', 'context': {}}
52         except Exception as e:
53             logger.error('Nf instancing preprocess exception=%s' % e.message)
54             logger.error(traceback.format_exc())
55             return {'result': '255', 'msg': 'Nf instancing preprocess exception', 'context': {}}
56
57     def apply_grant(self, args):
58         try:
59             logger.info('apply_grant, args=%s' % args)
60             # ApplyGrantTask(args).do_biz()
61             return {'result': '100', 'msg': 'Nf instancing apply grant finish', 'context': {}}
62         except Exception as e:
63             logger.error('Nf instancing apply grant exception=%s' % e.message)
64             logger.error(traceback.format_exc())
65             return {'result': '255', 'msg': 'Nf instancing apply grant exception', 'context': {}}
66
67     def apply_res(self, args):
68         try:
69             logger.info('apply_res, args=%s' % args)
70             # ApplyResTask(args).do_biz()
71             return {'result': '100', 'msg': 'Nf instancing apply resource finish', 'context': {}}
72         except Exception as e:
73             logger.error('Nf instancing apply resource exception=%s' % e.message)
74             logger.error(traceback.format_exc())
75             return {'result': '255', 'msg': 'Nf instancing apply resource exception', 'context': {}}
76
77     def check_res_status(self, args):
78         try:
79             logger.info('check_res_status, args=%s' % args)
80             # CheckResStatusTask(args).do_biz()
81             return {'result': '100', 'msg': 'Nf instancing check resource status finish', 'context': {}}
82         except Exception as e:
83             logger.error('Nf instancing check resource status exception=%s' % e.message)
84             logger.error(traceback.format_exc())
85             return {'result': '255', 'msg': 'Nf instancing check resource status exception', 'context': {}}
86
87     def wait_inst_finish(self, args):
88         try:
89             logger.info('wait_inst_finish, args=%s' % args)
90             # WaitInstFinishTask(args).do_biz()
91             return {'result': '100', 'msg': 'Nf instancing wait finish', 'context': {}}
92         except Exception as e:
93             logger.error('Nf instancing wait exception=%s' % e.message)
94             logger.error(traceback.format_exc())
95             return {'result': '255', 'msg': 'Nf instancing wait exception', 'context': {}}
96
97     def lcm_notify(self, args):
98         try:
99             logger.info('lcm_notify, args=%s' % args)
100             # LcmNotifyTask(args).do_biz()
101             return {'result': '100', 'msg': 'Nf instancing lcm notify finish', 'context': {}}
102         except Exception as e:
103             logger.error('Nf instancing lcm notify exception=%s' % e.message)
104             logger.error(traceback.format_exc())
105             return {'result': '255', 'msg': 'Nf instancing lcm notify exception', 'context': {}}
106
107     def inst_exception(self, args):
108         try:
109             logger.info('inst_exception, args=%s' % args)
110             # InstExceptionTask(args).do_biz()
111             return {'result': '100', 'msg': 'Nf instancing exception process finish', 'context': {}}
112         except Exception as e:
113             logger.error('Nf instancing exception process exception=%s' % e.message)
114             logger.error(traceback.format_exc())
115             return {'result': '255', 'msg': 'Nf instancing exception process exception', 'context': {}}