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 # -------------------------------------------------------------------------
19 from osdf.utils.interfaces import RestClient
20 import xml.etree.ElementTree as ET
22 def request(model_version_id, request_id, config):
23 """Get all of the license artifacts from SDC using service_resource_id and model_version_id
24 :param model_version_id: model_version_id
25 :param request_id: request_id
26 :return: license artifacts from SDC
28 base_url = config['sdcUrl']
29 uid, passwd = config['sdcUsername'], config['sdcPassword']
30 headers = {"CSP_UID": config['sdcMechId'], "X-ONAP-InstanceID": "osdf"}
31 rc = RestClient(userid=uid, passwd=passwd, headers=headers, method="GET", req_id=request_id)
32 resource_data = rc.request(base_url + '/resources/{}/metadata'.format(model_version_id))
34 artifact_ids = [x['artifactURL'].split("/resources/")[-1] # get the part after /resources/
35 for x in resource_data.get('artifacts', []) if x.get('artifactType') == "VF_LICENSE"]
36 artifact_urls = [base_url + '/resources/' + str(artifact_id) for artifact_id in artifact_ids]
38 for x in artifact_urls:
39 licenses.append(ET.fromstring(rc.request(x, asjson=False)))