diff options
author | Yang Xu <yang.xu3@huawei.com> | 2019-04-29 00:20:52 -0400 |
---|---|---|
committer | Yang Xu <yang.xu3@huawei.com> | 2019-04-29 00:34:42 -0400 |
commit | c52ed6e001b09f6e21f0e76cf173eda03fbf1f0e (patch) | |
tree | 3ac0714050c84986f5b4f7696ef7885d1059af6e /test/vcpe/sdcutils.py | |
parent | 42dcb266339a26803074f3190d1d9576e9dd05b7 (diff) |
Download vCPE service csar from SDC
Clean up import
Change-Id: I1a1be9b0528858fc30106978153e0af132675f93
Issue-ID: INT-847
Signed-off-by: Yang Xu <yang.xu3@huawei.com>
Diffstat (limited to 'test/vcpe/sdcutils.py')
-rwxr-xr-x | test/vcpe/sdcutils.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/vcpe/sdcutils.py b/test/vcpe/sdcutils.py new file mode 100755 index 000000000..a93872149 --- /dev/null +++ b/test/vcpe/sdcutils.py @@ -0,0 +1,54 @@ +#! /usr/bin/python + +import sys +import logging +import requests +import json +from vcpecommon import * + + +class SdcUtils: + def __init__(self, vcpecommon): + """ + :param vcpecommon: + """ + self.logger = logging.getLogger(__name__) + self.logger.setLevel(logging.DEBUG) + self.vcpecommon = vcpecommon + + def get_service_list(self): + """ + :return: + """ + + url = self.vcpecommon.sdc_service_list_url + self.logger.info(url) + r = requests.get(url, headers=self.vcpecommon.sdc_get_request_headers, auth=self.vcpecommon.sdc_get_request_userpass) + self.logger.debug(r) + data = r.json() + + self.logger.debug('---------------------------------------------------------------') + self.logger.debug('------- Creation request submitted to SDC, got response --------') + self.logger.debug('response code = %s' % r.status_code ) + self.logger.debug(json.dumps(data, indent=4, sort_keys=True)) + self.logger.debug('---------------------------------------------------------------') + + for service in data: + if service['name'].startswith('demoVCPE'): + self.logger.debug('service name = %s, url = %s' % (service['name'], service['toscaModelURL'])) + self.download_file(self.vcpecommon.sdc_url_prefix + service['toscaModelURL']) + + def get_filename_from_cd(self, cd): + """ + cd: in the format of Content-Disposition: attachment; filename="service-Demovcpeinfra-csar.csar" + """ + fname = re.findall('filename="(.+)"', cd) + self.logger.debug('fname = %s' % fname[0]) + return fname[0] + + def download_file(self, url): + self.logger.info(url) + response = requests.get(url, headers=self.vcpecommon.sdc_get_request_headers, auth=self.vcpecommon.sdc_get_request_userpass) + filename = 'csar/' + self.get_filename_from_cd(response.headers.get('Content-Disposition')) + open(filename, 'wb').write(response.content) + |