- raise ClientException(
- "Unexpected MIME type for file {}: MIME type {}".format(
- filename, mime_type)
- )
- headers["Content-File-MD5"] = utils.md5(filename)
- http_header = ['{}: {}'.format(key,val)
- for (key,val) in list(headers.items())]
- self._http.set_http_header(http_header)
- if update_endpoint:
- http_code, resp = self._http.put_cmd(endpoint=update_endpoint, filename=filename)
- else:
- ow_string = ''
- if overwrite:
- ow_string = '?{}'.format(overwrite)
- self._apiResource = '/netslice_templates_content'
- self._apiBase = '{}{}{}'.format(self._apiName,
- self._apiVersion, self._apiResource)
- endpoint = '{}{}'.format(self._apiBase,ow_string)
- http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename)
- #print('HTTP CODE: {}'.format(http_code))
- #print('RESP: {}'.format(resp))
- if http_code in (200, 201, 202, 204):
+ self._client.get_token()
+ mime_type = magic.from_file(filename, mime=True)
+ if mime_type is None:
+ raise ClientException(
+ "Unexpected MIME type for file {}: MIME type {}".format(
+ filename, mime_type)
+ )
+ headers= self._client._headers
+ if mime_type in ['application/yaml', 'text/plain']:
+ headers['Content-Type'] = 'application/yaml'
+ elif mime_type in ['application/gzip', 'application/x-gzip']:
+ headers['Content-Type'] = 'application/gzip'
+ #headers['Content-Type'] = 'application/binary'
+ # Next three lines are to be removed in next version
+ #headers['Content-Filename'] = basename(filename)
+ #file_size = stat(filename).st_size
+ #headers['Content-Range'] = 'bytes 0-{}/{}'.format(file_size - 1, file_size)
+ else:
+ raise ClientException(
+ "Unexpected MIME type for file {}: MIME type {}".format(
+ filename, mime_type)
+ )
+ headers["Content-File-MD5"] = utils.md5(filename)
+ http_header = ['{}: {}'.format(key,val)
+ for (key,val) in list(headers.items())]
+ self._http.set_http_header(http_header)
+ if update_endpoint:
+ http_code, resp = self._http.put_cmd(endpoint=update_endpoint, filename=filename)
+ else:
+ ow_string = ''
+ if overwrite:
+ ow_string = '?{}'.format(overwrite)
+ self._apiResource = '/netslice_templates_content'
+ self._apiBase = '{}{}{}'.format(self._apiName,
+ self._apiVersion, self._apiResource)
+ endpoint = '{}{}'.format(self._apiBase,ow_string)
+ http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename)
+ #print('HTTP CODE: {}'.format(http_code))
+ #print('RESP: {}'.format(resp))
+ # if http_code in (200, 201, 202, 204):