1 # -------------------------------------------------------------------------
2 # Copyright (c) 2015-2017 AT&T Intellectual Property
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # -------------------------------------------------------------------------
21 from requests import RequestException
22 from osdf.adapters.sdc import sdc, constraint_handler
23 from osdf.logging.osdf_logging import audit_log, metrics_log, MH
24 from osdf.config.base import osdf_config
27 def license_optim(request_json):
29 Fetch license artifacts associated with the service model and search licensekey-group-UUID and entitlement-pool-uuid
30 associated with the given att part number and nominal throughput in a request
31 :param request_json: Request in a JSON format
32 :return: A tuple of licensekey-group-uuid-list and entitlement-group-uuid-list
34 req_id = request_json["requestInfo"]["requestId"]
35 config = osdf_config.deployment
37 model_name = request_json['placementInfo']['serviceModelInfo']['modelName']
38 # service_name = data_mapping.get_service_type(model_name)
39 service_name = model_name
43 order_info = json.loads(request_json["placementInfo"]["requestParameters"])
44 if service_name == 'VPE':
45 data_mapping.normalize_user_params(order_info)
46 for licenseDemand in request_json['placementInfo']['demandInfo']['licenseDemand']:
47 metrics_log.info(MH.requesting("sdc", req_id))
48 license_artifacts = sdc.request(licenseDemand['resourceModelInfo']['modelVersionId'],request_json["requestInfo"]["requestId"], config)
49 entitlement_pool_uuids, license_key_group_uuids = constraint_handler.choose_license(license_artifacts,order_info, service_name)
51 {'serviceResourceId': licenseDemand['serviceResourceId'],
52 'resourceModuleName': licenseDemand['resourceModuleName'],
53 'entitlementPoolList': entitlement_pool_uuids,
54 'licenseKeyGroupList': license_key_group_uuids