X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fsol005%2Fnsd.py;h=ef9e5ab4d10288123af3dbdfdb0ed0dcf59e68dc;hb=6d10e04620f3985e23dcce03d366f5734ba72a7c;hp=95fc92a40cffac65a4a28965a09689ad0e5ac1de;hpb=ce093de18e01ebda56b54c36ab69074cf3761f50;p=osm%2Fosmclient.git diff --git a/osmclient/sol005/nsd.py b/osmclient/sol005/nsd.py index 95fc92a..ef9e5ab 100644 --- a/osmclient/sol005/nsd.py +++ b/osmclient/sol005/nsd.py @@ -22,6 +22,7 @@ from osmclient.common.exceptions import NotFound from osmclient.common.exceptions import ClientException from osmclient.common import utils import yaml +import json import magic #from os import stat #from os.path import basename @@ -73,11 +74,11 @@ class Nsd(object): nsd = self.get(name) headers = self._client._headers headers['Accept'] = 'application/binary' - http_code, resp2 = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, nsd['_id'], thing)) + http_code, resp = self._http.get2_cmd('{}/{}/{}'.format(self._apiBase, nsd['_id'], thing)) #print yaml.safe_dump(resp2) - if resp2: + if resp: #store in a file - return resp2 + return resp raise NotFound("nsd {} not found".format(name)) def get_descriptor(self, name, filename): @@ -89,9 +90,15 @@ class Nsd(object): def get_artifact(self, name, artifact, filename): self.get_thing(name, 'artifacts/{}'.format(artifact), filename) - def delete(self, name): + def delete(self, name, force=False): nsd = self.get(name) - http_code, resp = self._http.delete_cmd('{}/{}'.format(self._apiBase, nsd['_id'])) + querystring = '' + if force: + querystring = '?FORCE=True' + http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase, + nsd['_id'], querystring)) + if resp: + resp = json.loads(resp) #print 'RESP: {}'.format(resp) if http_code == 202: print 'Deletion in progress' @@ -125,7 +132,7 @@ class Nsd(object): for (key,val) in headers.items()] self._http.set_http_header(http_header) if update_endpoint: - resp = self._http.put_cmd(endpoint=update_endpoint, filename=filename) + http_code, resp = self._http.put_cmd(endpoint=update_endpoint, filename=filename) else: ow_string = '' if overwrite: @@ -134,7 +141,9 @@ class Nsd(object): self._apiBase = '{}{}{}'.format(self._apiName, self._apiVersion, self._apiResource) endpoint = '{}{}'.format(self._apiBase,ow_string) - resp = self._http.post_cmd(endpoint=endpoint, filename=filename) + http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename) + if resp: + resp = json.loads(resp) #print resp if not resp or 'id' not in resp: raise ClientException("failed to upload package")