1 # Copyright 2016 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.
18 from threading import Thread
20 from lcm.ns_sfcs.biz.create_flowcla import CreateFlowClassifier
21 from lcm.ns_sfcs.biz.create_port_chain import CreatePortChain
22 from lcm.ns_sfcs.biz.create_portpairgp import CreatePortPairGroup
24 from lcm.pub.exceptions import NSLCMException
25 from lcm.pub.utils.jobutil import JobUtil
26 from lcm.ns_sfcs.biz.utils import update_fp_status
28 logger = logging.getLogger(__name__)
31 class CreateSfcWorker(Thread):
32 def __init__(self, data):
33 super(CreateSfcWorker, self).__init__()
34 self.ns_inst_id = data["nsinstid"]
35 self.ns_model_data = data["ns_model_data"]
36 self.fp_id = data["fpindex"]
37 self.sdnControllerId = data["sdncontrollerid"]
38 self.fp_inst_id = data["fpinstid"]
43 self.job_id = JobUtil.create_job("SFC", "sfc_init", self.ns_inst_id + "_" + self.fp_id)
48 logger.info("Service Function Chain Worker start : ")
50 CreateFlowClassifier(self.data).do_biz()
51 JobUtil.add_job_status(self.job_id, 50, "create flow classifer successfully!", "")
52 CreatePortPairGroup(self.data).do_biz()
53 JobUtil.add_job_status(self.job_id, 75, "create port pair group successfully!", "")
54 CreatePortChain(self.data).do_biz()
55 update_fp_status(self.fp_inst_id, "active")
56 JobUtil.add_job_status(self.job_id, 100, "create port chain successful!", "")
57 logger.info("Service Function Chain Worker end : ")
58 except NSLCMException as e:
59 self.handle_exception(e)
60 except Exception as e:
61 self.handle_exception(e)
63 def handle_exception(self, e):
64 detail = "sfc instantiation failed, detail message: %s" % e.message
65 JobUtil.add_job_status(self.job_id, 255, "create sfc failed!", "")
66 logger.error(traceback.format_exc())
68 update_fp_status(self.fp_inst_id, "failed")