1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# Copyright 2016 ZTE Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import traceback
from threading import Thread
from lcm.ns.sfcs.create_flowcla import CreateFlowClassifier
from lcm.ns.sfcs.create_port_chain import CreatePortChain
from lcm.ns.sfcs.create_portpairgp import CreatePortPairGroup
from lcm.ns.sfcs.utils import update_fp_status
from lcm.pub.exceptions import NSLCMException
from lcm.pub.utils.jobutil import JobUtil
logger = logging.getLogger(__name__)
class CreateSfcWorker(Thread):
def __init__(self, data):
super(CreateSfcWorker, self).__init__()
self.ns_inst_id = data["nsinstid"]
self.ns_model_data = data["ns_model_data"]
self.fp_id = data["fpindex"]
self.sdnControllerId = data["sdncontrollerid"]
self.fp_inst_id = data["fpinstid"]
self.data = data
self.job_id = ""
def init_data(self):
self.job_id = JobUtil.create_job("SFC", "sfc_init", self.ns_inst_id + "_" + self.fp_id)
return self.job_id
def run(self):
try:
logger.info("Service Function Chain Worker start : ")
CreateFlowClassifier(self.data).do_biz()
JobUtil.add_job_status(self.job_id, 50, "create flow classifer successfully!", "")
CreatePortPairGroup(self.data).do_biz()
JobUtil.add_job_status(self.job_id, 75, "create port pair group successfully!", "")
CreatePortChain(self.data).do_biz()
update_fp_status(self.fp_inst_id, "active")
JobUtil.add_job_status(self.job_id, 100, "create port chain successful!", "")
logger.info("Service Function Chain Worker end : ")
except NSLCMException as e:
self.handle_exception(e)
except Exception as e:
self.handle_exception(e)
def handle_exception(self, e):
detail = "sfc instantiation failed, detail message: %s" % e.message
JobUtil.add_job_status(self.job_id, 255, "create sfc failed!", "")
logger.error(traceback.format_exc())
logger.error(detail)
update_fp_status(self.fp_inst_id, "failed")
|