from conductor.common import rest
from conductor.i18n import _LE
+from http.client import HTTPConnection
import json
+import logging
from oslo_config import cfg
from oslo_log import log
import time
LOG = log.getLogger(__name__)
+log = logging.getLogger('urllib3')
+log.setLevel(logging.DEBUG)
+ch = logging.StreamHandler()
+ch.setLevel(logging.DEBUG)
+log.addHandler(ch)
+HTTPConnection.debuglevel = 1
+
CONF = cfg.CONF
DCAE_OPTS = [
LOG.debug("from AAI ", candidates)
for candidate in candidates:
inventory_type = candidate.get('inventory_type')
- candidate_id = candidate.get('candidate_id')
+ if inventory_type == 'nsi':
+ candidate_id = candidate.get('instance_id')
+ elif inventory_type == 'nssi':
+ candidate_id = candidate.get('instance_id')
+ else:
+ LOG.debug("No candidate_id found")
domain = candidate.get('domain')
- response = self.get_dcae_response()
+ LOG.debug("domain from the candidate list is ", domain)
+ response = self.get_dcae_response(candidate_id)
+ LOG.debug(" DCAE response in capacity_filter() : ", response)
# max_no_of_connections = self.get_max_no_of_connections(response)
- dLThpt = self.get_dLThpt(response, candidate_id)
- uLThpt = self.get_uLThpt(response, candidate_id)
- # max_no_of_pdu_sessions = self.get_max_no_of_pdu_sessions()
- if inventory_type == 'nsi':
- uLThpt_ServiceProfile = candidate.get('uLThptPerSlice')
- dLThpt_ServiceProfile = candidate.get('dLThptPerSlice')
- uLThpt_difference = self.get_difference(uLThpt_ServiceProfile, uLThpt)
- dLThpt_difference = self.get_difference(dLThpt_ServiceProfile, dLThpt)
- candidate['uLThpt_difference'] = uLThpt_difference
- candidate['dLThpt_difference'] = dLThpt_difference
- elif inventory_type == 'nssi' and (domain != 'tn_fh' and domain != 'tn_mh'):
- uLThpt_SliceProfile = candidate.get('exp_data_rate_ul')
- dLThpt_SliceProfile = candidate.get('exp_data_rate_dl')
- uLThpt_difference = self.get_difference(uLThpt_SliceProfile, uLThpt)
- dLThpt_difference = self.get_difference(dLThpt_SliceProfile, dLThpt)
- candidate['uLThpt_difference'] = uLThpt_difference
- candidate['dLThpt_difference'] = dLThpt_difference
- # connections_difference = self.get_difference(max_no_of_pdu_sessions, max_no_of_connections)
- elif inventory_type == 'nssi' and (domain == 'tn_fh' and domain == 'tn_mh'):
- uLThpt_difference = 10
- dLThpt_difference = 10
- candidate['uLThpt_difference'] = uLThpt_difference
- candidate['dLThpt_difference'] = dLThpt_difference
+ if response is not None:
+ dLThpt = self.get_dLThpt(response, candidate_id)
+ LOG.debug("dLThpt fetched from dcae response is", dLThpt)
+ uLThpt = self.get_uLThpt(response, candidate_id)
+ LOG.debug("uLThpt fetched from dcae response is", uLThpt)
+ # max_no_of_pdu_sessions = self.get_max_no_of_pdu_sessions()
+ if inventory_type == 'nsi':
+ uLThpt_ServiceProfile = candidate.get('ul_thpt_per_slice')
+ LOG.debug("uLThpt fetched from service profile is", uLThpt_ServiceProfile)
+ dLThpt_ServiceProfile = candidate.get('dl_thpt_per_slice')
+ LOG.debug("dLThpt fetched from service profile is", dLThpt_ServiceProfile)
+ uLThpt_difference = self.get_difference(uLThpt_ServiceProfile, uLThpt)
+ LOG.debug(" uLThpt_difference for nsi is ", uLThpt_difference)
+ dLThpt_difference = self.get_difference(dLThpt_ServiceProfile, dLThpt)
+ LOG.debug(" dLThpt_difference for nsi is ", dLThpt_difference)
+ candidate['uLThpt_difference'] = uLThpt_difference
+ candidate['dLThpt_difference'] = dLThpt_difference
+ elif inventory_type == 'nssi' and (domain != 'TN_FH' and domain != 'TN_MH'):
+ uLThpt_SliceProfile = candidate.get('exp_data_rate_ul')
+ LOG.debug("uLThpt fetched from slice profile is", uLThpt_SliceProfile)
+ dLThpt_SliceProfile = candidate.get('exp_data_rate_dl')
+ LOG.debug("dLThpt fetched from slice profile is", dLThpt_SliceProfile)
+ uLThpt_difference = self.get_difference(uLThpt_SliceProfile, uLThpt)
+ LOG.debug(" uLThpt_difference for nssi is ", uLThpt_difference)
+ dLThpt_difference = self.get_difference(dLThpt_SliceProfile, dLThpt)
+ LOG.debug(" dLThpt_difference for nssi is ", dLThpt_difference)
+ candidate['uLThpt_difference'] = uLThpt_difference
+ candidate['dLThpt_difference'] = dLThpt_difference
+ # connections_difference = self.get_difference(max_no_of_pdu_sessions, max_no_of_connections)
+ elif inventory_type == 'nssi' and (domain == 'TN_FH' and domain == 'TN_MH'):
+ uLThpt_difference = 10
+ dLThpt_difference = 10
+ candidate['uLThpt_difference'] = uLThpt_difference
+ candidate['dLThpt_difference'] = dLThpt_difference
+ else:
+ LOG.debug("No difference attribute was added to the candidate")
else:
- LOG.debug("No difference attribute was added to the candidate")
+ candidate = candidate
+ LOG.debug("Returning original candidate list")
candidatesList.update(candidate)
LOG.debug("capacity filter ", candidatesList)
updated_candidateList.append(candidatesList)
responseJson = json.loads(response)
configDetails = responseJson["sliceConfigDetails"]
for i in range(len(configDetails)):
- if configDetails[i]["sliceIdentifier"] == candidate_id:
+ if configDetails[i]["sliceIdentifiers"] == candidate_id:
aggregatedConfig = configDetails[i]['aggregatedConfig']
- uLThpt = aggregatedConfig.get("uLThptPerSlice")
+ uLThpt = aggregatedConfig.get("ulthptPerSlice")
+ LOG.debug(" uLthpt from DCAE is : ", uLThpt)
return uLThpt
def get_dLThpt(self, response, candidate_id):
responseJson = json.loads(response)
configDetails = responseJson["sliceConfigDetails"]
for i in range(len(configDetails)):
- if configDetails[i]["sliceIdentifier"] == candidate_id:
+ if configDetails[i]["sliceIdentifiers"] == candidate_id:
aggregatedConfig = configDetails[i]['aggregatedConfig']
- dLThpt = aggregatedConfig.get("dLThptPerSlice")
+ dLThpt = aggregatedConfig.get("dlthptPerSlice")
+ LOG.debug(" dLthpt from DCAE is : ", dLThpt)
return dLThpt
def get_difference(self, attribute1, attribute2):
"link: {}{}").format(context, value, response.status_code, response.reason, self.base, path))
return response
- def get_dcae_response(self):
+ def get_dcae_response(self, candidate_id):
path = self.conf.dcae.get_slice_config_url
- dcae_response = self._request('get', path, data=None)
- if dcae_response is None or dcae_response.status_code != 200:
+ data = {"sliceIdentifiers": [candidate_id], "configParams": ["dLThptPerSlice",
+ "uLThptPerSlice", "maxNumberOfConns"]}
+ dcae_response = self._request('get', path, data=data)
+ LOG.debug(self._request('get', path, data=data))
+ LOG.debug(" DCAE response : ", dcae_response)
+ LOG.debug("DCAE json response is : ", json.dumps(dcae_response.json()))
+ dcae_response2 = json.dumps(dcae_response.json())
+ LOG.debug(" processed DCAE response is ", dcae_response2)
+ if dcae_response2 is None or dcae_response.status_code != 200:
return None
- if dcae_response:
- return dcae_response
+ if dcae_response2:
+ responseJson = json.loads(dcae_response2)
+ LOG.debug("response json from DCAE is :", responseJson)
+ if 'sliceConfigDetails' not in responseJson or len(responseJson['sliceConfigDetails']) == 0:
+ LOG.debug(" Returning None to capacity_filter()")
+ return None
+ else:
+ LOG.debug("returning DCAE response to capacity_filter() from get_dcae_response()")
+ return dcae_response2