+ def get_file(self, session, item, _id, path=None, accept_header=None):
+ """
+ Return the file content of a vnfd or nsd
+ :param session: contains the used login username and working project
+ :param item: it can be vnfds or nsds
+ :param _id: Identity of the vnfd, ndsd
+ :param path: artifact path or "$DESCRIPTOR" or None
+ :param accept_header: Content of Accept header. Must contain applition/zip or/and text/plain
+ :return: opened file or raises an exception
+ """
+ accept_text = accept_zip = False
+ if accept_header:
+ if 'text/plain' in accept_header or '*/*' in accept_header:
+ accept_text = True
+ if 'application/zip' in accept_header or '*/*' in accept_header:
+ accept_zip = True
+ if not accept_text and not accept_zip:
+ raise EngineException("provide request header 'Accept' with 'application/zip' or 'text/plain'",
+ http_code=HTTPStatus.NOT_ACCEPTABLE)
+
+ content = self.get_item(session, item, _id)
+ if content["_admin"]["onboardingState"] != "ONBOARDED":
+ raise EngineException("Cannot get content because this resource is not at 'ONBOARDED' state. "
+ "onboardingState is {}".format(content["_admin"]["onboardingState"]),
+ http_code=HTTPStatus.CONFLICT)
+ storage = content["_admin"]["storage"]
+ if path is not None and path != "$DESCRIPTOR": # artifacts
+ if not storage.get('pkg-dir'):
+ raise EngineException("Packages does not contains artifacts", http_code=HTTPStatus.BAD_REQUEST)
+ if self.fs.file_exists((storage['folder'], storage['pkg-dir'], *path), 'dir'):
+ folder_content = self.fs.dir_ls((storage['folder'], storage['pkg-dir'], *path))
+ return folder_content, "text/plain"
+ # TODO manage folders in http
+ else:
+ return self.fs.file_open((storage['folder'], storage['pkg-dir'], *path), "rb"), \
+ "application/octet-stream"
+
+ # pkgtype accept ZIP TEXT -> result
+ # manyfiles yes X -> zip
+ # no yes -> error
+ # onefile yes no -> zip
+ # X yes -> text
+
+ if accept_text and (not storage.get('pkg-dir') or path == "$DESCRIPTOR"):
+ return self.fs.file_open((storage['folder'], storage['descriptor']), "r"), "text/plain"
+ elif storage.get('pkg-dir') and not accept_zip:
+ raise EngineException("Packages that contains several files need to be retrieved with 'application/zip'"
+ "Accept header", http_code=HTTPStatus.NOT_ACCEPTABLE)
+ else:
+ if not storage.get('zipfile'):
+ # TODO generate zipfile if not present
+ raise EngineException("Only allowed 'text/plain' Accept header for this descriptor. To be solved in future versions"
+ "", http_code=HTTPStatus.NOT_ACCEPTABLE)
+ return self.fs.file_open((storage['folder'], storage['zipfile']), "rb"), "application/zip"
+