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