+def _osdf_request(rancher_ip, onap_ip, aai_data, exclude, use_oof_cache):
+ dirname = os.path.join('templates/oof-cache/', aai_data['vf-module-id'])
+ if exclude:
+ file = os.path.join(dirname, 'sample-osdf-excluded.json')
+ else:
+ file = os.path.join(dirname, 'sample-osdf-required.json')
+ if use_oof_cache and os.path.exists(file):
+ migrate_from = json.loads(open(file).read())
+ return migrate_from
+
+ print('Making OSDF request for excluded {}'.format(str(exclude)))
+ api = _init_python_osdf_api(onap_ip)
+ request_id = str(uuid.uuid4())
+ transaction_id = str(uuid.uuid4())
+ callback_url = "http://{}:9000/osdfCallback/".format(str(rancher_ip))
+ template = json.loads(open('templates/osdfRequest.json').read())
+ template["requestInfo"]["transactionId"] = transaction_id
+ template["requestInfo"]["requestId"] = request_id
+ template["requestInfo"]["callbackUrl"] = callback_url
+ template["serviceInfo"]["serviceInstanceId"] = aai_data['service-info']['service-instance-id']
+ template["placementInfo"]["requestParameters"]["chosenCustomerId"] = aai_data['service-info']['global-customer-id']
+ template["placementInfo"]["placementDemands"][0]["resourceModelInfo"]["modelInvariantId"] =\
+ aai_data['vfw-model-info']['model-invariant-id']
+ template["placementInfo"]["placementDemands"][0]["resourceModelInfo"]["modelVersionId"] =\
+ aai_data['vfw-model-info']['model-version-id']
+ template["placementInfo"]["placementDemands"][1]["resourceModelInfo"]["modelInvariantId"] =\
+ aai_data['vpgn-model-info']['model-invariant-id']
+ template["placementInfo"]["placementDemands"][1]["resourceModelInfo"]["modelVersionId"] =\
+ aai_data['vpgn-model-info']['model-version-id']
+ if exclude:
+ template["placementInfo"]["placementDemands"][0]["excludedCandidates"][0]["identifiers"].\
+ append(aai_data['vf-module-id'])
+ else:
+ template["placementInfo"]["placementDemands"][0]["requiredCandidates"][0]["identifiers"].\
+ append(aai_data['vf-module-id'])
+
+ #print(json.dumps(template, indent=4))
+
+ with _no_ssl_verification():
+ response = api.osdf.placement(body=template, params={}, headers={})
+ #if response.body.get('error_message') is not None:
+ # raise Exception(response.body['error_message']['explanation'])
+
+ counter = 0
+ while counter < 600 and osdf_response["last"]["id"] != request_id:
+ time.sleep(1)
+ if counter % 20 == 0:
+ print("solving")
+ counter += 1
+
+ if osdf_response["last"]["id"] == request_id:
+ status = osdf_response["last"]["data"]["requestStatus"]
+ if status == "completed":
+ result = {
+ "solution": osdf_response["last"]["data"]["solutions"]["placementSolutions"]
+ }
+ if not os.path.exists(dirname):
+ os.makedirs(dirname)
+ f = open(file, 'w+')
+ f.write(json.dumps(result, indent=4))
+ f.close()
+ return result
+ else:
+ message = osdf_response["last"]["data"]["statusMessage"]
+ raise Exception("OOF request {}: {}".format(status, message))
+ else:
+ raise Exception("No response for OOF request")
+
+