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
68
69
70
71
72
73
74
75
76
77
78
79
|
# Copyright (C) 2018 Verizon. All Rights Reserved
#
# 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 json
import logging
from lcm.pub.database.models import VNFLcmOpOccModel
from lcm.pub.exceptions import NFLCMException
logger = logging.getLogger(__name__)
FILTERS = {
'id': 'id',
'operationState': 'operation_state',
'stateEnteredTime': 'state_entered_time',
'startTime': 'start_time',
'vnfInstanceId': 'vnf_instance_id',
'grantId': 'grant_id',
'operation': 'operation'
}
class QueryVnfLcmOpOcc:
def __init__(self, data, lcm_op_occ_id=''):
self.vnf_lcm_op_occ_id = lcm_op_occ_id
self.params = data
def query_multi_vnf_lcm_op_occ(self):
query_data = {}
logger.debug("QueryMultiVnfLcmOpOccs--get--biz::> Check for filters in query params" % self.params)
for query, value in list(self.params.items()):
if query in FILTERS:
query_data[FILTERS[query]] = value
# Query the database with filters if the request has fields in request params, else fetch all records
if query_data:
lcm_ops = VNFLcmOpOccModel.objects.filter(**query_data)
else:
lcm_ops = VNFLcmOpOccModel.objects.all()
if not lcm_ops.exists():
raise NFLCMException('LCM Operation Occurances do not exist')
return [self.fill_resp_data(lcm_op) for lcm_op in lcm_ops]
def fill_resp_data(self, lcm_op):
resp_data = {
'id': lcm_op.id,
'operationState': lcm_op.operation_state,
'stateEnteredTime': lcm_op.state_entered_time,
'startTime': lcm_op.start_time,
'vnfInstanceId': lcm_op.vnf_instance_id,
'grantId': None,
'operation': lcm_op.operation,
'isAutomaticInvocation': False if lcm_op.is_automatic_invocation == 'False' else True,
'operationParams': json.loads(lcm_op.operation_params),
'isCancelPending': False if lcm_op.is_cancel_pending == 'False' else True,
'cancelMode': lcm_op.cancel_mode,
'error': None if not lcm_op.error else json.loads(lcm_op.error),
'resourceChanges': None if not lcm_op.resource_changes else json.loads(lcm_op.resource_changes),
'changedInfo': None if not lcm_op.changed_info else json.loads(lcm_op.changed_info),
'changedExtConnectivity': None if not lcm_op.changed_ext_connectivity else json.loads(lcm_op.changed_ext_connectivity),
'_links': json.loads(lcm_op.links)
}
return resp_data
def query_single_vnf_lcm_op_occ(self):
lcm_op = VNFLcmOpOccModel.objects.filter(id=self.vnf_lcm_op_occ_id)
if not lcm_op.exists():
raise NFLCMException('LCM Operation Occurance does not exist')
resp_data = self.fill_resp_data(lcm_op[0])
return resp_data
|