+ 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
+ headers['Content-Filename'] = basename(filename)
+ if mime_type in ['application/yaml', 'text/plain', 'application/json']:
+ headers['Content-Type'] = 'text/plain'
+ elif mime_type in ['application/gzip', 'application/x-gzip']:
+ headers['Content-Type'] = 'application/gzip'
+ 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 = '/ns_descriptors_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)
+
+ if http_code in (200, 201, 202):
+ if resp:
+ resp = json.loads(resp)
+ if not resp or 'id' not in resp:
+ raise ClientException('unexpected response from server - {}'.format(resp))
+ print(resp['id'])
+ elif http_code == 204:
+ print('Updated')