projects
/
osm
/
osmclient.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Remove set_default_params method from client.py
[osm/osmclient.git]
/
osmclient
/
sol005
/
package.py
diff --git
a/osmclient/sol005/package.py
b/osmclient/sol005/package.py
index
622fb86
..
a083300
100644
(file)
--- a/
osmclient/sol005/package.py
+++ b/
osmclient/sol005/package.py
@@
-18,8
+18,8
@@
OSM package API handling
"""
OSM package API handling
"""
-#from os import stat
-#from os.path import basename
+#
from os import stat
+#
from os.path import basename
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
from osmclient.common import utils
from osmclient.common.exceptions import ClientException
from osmclient.common.exceptions import NotFound
from osmclient.common import utils
@@
-32,7
+32,7
@@
class Package(object):
def __init__(self, http=None, client=None):
self._client = client
self._http = http
def __init__(self, http=None, client=None):
self._client = client
self._http = http
- self._logger = logging.getLogger(
'osmclient'
)
+ self._logger = logging.getLogger(
"osmclient"
)
def get_key_val_from_pkg(self, descriptor_file):
self._logger.debug("")
def get_key_val_from_pkg(self, descriptor_file):
self._logger.debug("")
@@
-40,9
+40,9
@@
class Package(object):
def _wait_for_package(self, pkg_type):
self._logger.debug("")
def _wait_for_package(self, pkg_type):
self._logger.debug("")
- if
'vnfd' in pkg_type['type'
]:
+ if
"vnfd" in pkg_type["type"
]:
get_method = self._client.vnfd.get
get_method = self._client.vnfd.get
- elif
'nsd' in pkg_type['type'
]:
+ elif
"nsd" in pkg_type["type"
]:
get_method = self._client.nsd.get
else:
raise ClientException("no valid package type found")
get_method = self._client.nsd.get
else:
raise ClientException("no valid package type found")
@@
-56,13
+56,13
@@
class Package(object):
return False
return True
return False
return True
- return utils.wait_for_value(
lambda:
- check_exists(lambda:
-
get_method(pkg_type['name']))
)
+ return utils.wait_for_value(
+ lambda: check_exists(lambda: get_method(pkg_type["name"]))
+ )
def wait_for_upload(self, filename):
"""wait(block) for an upload to succeed.
def wait_for_upload(self, filename):
"""wait(block) for an upload to succeed.
-
The filename passed is assumed to be a descriptor tarball.
+ The filename passed is assumed to be a descriptor tarball.
"""
self._logger.debug("")
self._client.get_token()
"""
self._logger.debug("")
self._client.get_token()
@@
-72,47
+72,51
@@
class Package(object):
raise ClientException("Cannot determine package type")
if not self._wait_for_package(pkg_type):
raise ClientException("Cannot determine package type")
if not self._wait_for_package(pkg_type):
- raise ClientException("package {} failed to upload"
- .format(filename))
+ raise ClientException("package {} failed to upload".format(filename))
def upload(self, filename, skip_charm_build=False):
self._logger.debug("")
if os.path.isdir(filename):
def upload(self, filename, skip_charm_build=False):
self._logger.debug("")
if os.path.isdir(filename):
- filename = filename.rstrip('/')
- filename = self._client.package_tool.build(filename, skip_validation=False, skip_charm_build=skip_charm_build)
+ filename = filename.rstrip("/")
+ filename = self._client.package_tool.build(
+ filename, skip_validation=False, skip_charm_build=skip_charm_build
+ )
self.upload(filename)
else:
self._client.get_token()
pkg_type = utils.get_key_val_from_pkg(filename)
if pkg_type is None:
raise ClientException("Cannot determine package type")
self.upload(filename)
else:
self._client.get_token()
pkg_type = utils.get_key_val_from_pkg(filename)
if pkg_type is None:
raise ClientException("Cannot determine package type")
- if pkg_type[
'type'] == 'nsd'
:
- endpoint =
'/nsd/v1/ns_descriptors_content'
+ if pkg_type[
"type"] == "nsd"
:
+ endpoint =
"/nsd/v1/ns_descriptors_content"
else:
else:
- endpoint =
'/vnfpkgm/v1/vnf_packages_content'
- #endpoint = '/nsds' if pkg_type['type'] == 'nsd' else '/vnfds'
- #print('Endpoint: {}'.format(endpoint))
+ endpoint =
"/vnfpkgm/v1/vnf_packages_content"
+ #
endpoint = '/nsds' if pkg_type['type'] == 'nsd' else '/vnfds'
+ #
print('Endpoint: {}'.format(endpoint))
headers = self._client._headers
headers = self._client._headers
- headers['Content-Type'] = 'application/gzip'
- #headers['Content-Type'] = 'application/binary'
+
+ if filename.endswith(".tar.gz"):
+ headers["Content-Type"] = "application/gzip"
+ else:
+ headers["Content-Type"] = "application/zip"
+ # headers['Content-Type'] = 'application/binary'
# Next three lines are to be removed in next version
# 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)
+ #
headers['Content-Filename'] = basename(filename)
+ #
file_size = stat(filename).st_size
+ #
headers['Content-Range'] = 'bytes 0-{}/{}'.format(file_size - 1, file_size)
headers["Content-File-MD5"] = utils.md5(filename)
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)
+ self._http.set_http_header(headers)
http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename)
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):
+ #
print('HTTP CODE: {}'.format(http_code))
+ #
print('RESP: {}'.format(resp))
+ #
if http_code in (200, 201, 202, 204):
if resp:
resp = json.loads(resp)
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'])
+ if not resp or "id" not in resp:
+ raise ClientException(
+ "unexpected response from server - {}".format(resp)
+ )
+ print(resp["id"])
# else:
# msg = ""
# if resp:
# else:
# msg = ""
# if resp: