1 # Copyright 2019 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.
19 from lcm.pub.database.models import NSLcmOpOccModel
20 from lcm.pub.utils.values import update_value
23 logger = logging.getLogger(__name__)
26 class NsLcmOpOcc(object):
28 def create(nsInstanceId, lcmOperationType, operationState, isAutomaticInvocation, operationParams):
29 logger.debug("lcm_op_occ(%s,%s,%s,%s,%s) create begin." % (nsInstanceId, lcmOperationType, operationState, isAutomaticInvocation, operationParams))
30 cur_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
31 lcm_op_occ = NSLcmOpOccModel.objects.create(
33 operation_state=operationState,
34 state_entered_time=cur_time,
36 ns_instance_id=nsInstanceId,
37 operation=lcmOperationType,
38 is_automatic_invocation=isAutomaticInvocation,
39 operation_params=operationParams,
40 is_cancel_pending=False
42 logger.debug("lcm_op_occ(%s) create successfully." % lcm_op_occ.id)
46 def update(occ_id, operationState=None, isCancelPending=None, cancelMode=None, error=None, resourceChanges=None):
47 lcm_op_occ = NSLcmOpOccModel.objects.get(id=occ_id)
49 lcm_op_occ.operation_state = operationState
50 lcm_op_occ.state_entered_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
52 lcm_op_occ.is_cancel_pending = isCancelPending
54 lcm_op_occ.cancel_mode = cancelMode
56 lcm_op_occ.error = error
58 lcm_op_occ.resource_changes = update_value(lcm_op_occ.resourceChanges if lcm_op_occ.resourceChanges else {}, resourceChanges)
60 logger.debug("lcm_op_occ(%s) update successfully." % lcm_op_occ.id)