def upload(self, req, body=None): """ Upload new file archive for the new package together with package metadata """ _check_content_type(req, 'multipart/form-data') file_obj, package_meta = _validate_body(body) try: jsonschema.validate(package_meta, schemas.PKG_UPLOAD_SCHEMA) except jsonschema.ValidationError as e: LOG.exception(e) raise exc.HTTPBadRequest(explanation=e.message) with tempfile.NamedTemporaryFile(delete=False) as tempf: LOG.debug("Storing package archive in a temporary file") content = file_obj.file.read() if not content: msg = _("Uploading file can't be empty") LOG.error(msg) raise exc.HTTPBadRequest(msg) tempf.write(content) package_meta['archive'] = content try: LOG.debug("Deleting package archive temporary file") pkg_to_upload = app_pkg.load_from_file(tempf.name, target_dir=None, drop_dir=True) except pkg_exc.PackageLoadError as e: LOG.exception(e) raise exc.HTTPBadRequest(e) finally: os.remove(tempf.name) # extend dictionary for update db for k, v in PKG_PARAMS_MAP.iteritems(): if hasattr(pkg_to_upload, k): package_meta[v] = getattr(pkg_to_upload, k) try: package = db_api.package_upload(package_meta, req.context.tenant) except db_exc.DBDuplicateEntry: msg = _('Package with specified full name is already registered') LOG.exception(msg) raise exc.HTTPServerError(msg) return package.to_dict()
def _do_import_package(_dir, categories): LOG.info("Going to import Murano package from {0}".format(_dir)) pkg = application_package.load_from_dir(_dir) package = { 'fully_qualified_name': pkg.full_name, 'type': pkg.package_type, 'author': pkg.author, 'name': pkg.display_name, 'description': pkg.description, # note: we explicitly mark all the imported packages as public, # until a parameter added to control visibility scope of a package 'is_public': True, 'tags': pkg.tags, 'logo': pkg.logo, 'ui_definition': pkg.raw_ui, 'class_definitions': pkg.classes, 'archive': pkg.blob, 'categories': categories or [] } # note(ruhe): the second parameter is tenant_id # it is a required field in the DB, that's why we pass an empty string result = db_catalog_api.package_upload(package, '') LOG.info("Finished import of package {0}".format(result.id))
def _do_import_package(_dir, categories): LOG.info("Going to import Murano package from {0}".format(_dir)) pkg = application_package.load_from_dir(_dir) package = { "fully_qualified_name": pkg.full_name, "type": pkg.package_type, "author": pkg.author, "name": pkg.display_name, "description": pkg.description, # note: we explicitly mark all the imported packages as public, # until a parameter added to control visibility scope of a package "is_public": True, "tags": pkg.tags, "logo": pkg.logo, "ui_definition": pkg.raw_ui, "class_definitions": pkg.classes, "archive": pkg.blob, "categories": categories or [], } # note(ruhe): the second parameter is tenant_id # it is a required field in the DB, that's why we pass an empty string result = db_catalog_api.package_upload(package, "") LOG.info("Finished import of package {0}".format(result.id))