def _get_package_by_definition(self, package_def): package_id = package_def.id package_name = package_def.fully_qualified_name package_directory = os.path.join(self._cache_directory, package_name) if os.path.exists(package_directory): try: return app_pkg.load_from_dir(package_directory, preload=True, loader=YaqlYamlLoader) except pkg_exc.PackageLoadError: LOG.exception("Unable to load package from cache. Clean-up...") shutil.rmtree(package_directory, ignore_errors=True) try: package_data = self._client.packages.download(package_id) except muranoclient_exc.HTTPException: LOG.exception("Unable to download " "package with id {0}".format(package_id)) raise pkg_exc.PackageLoadError() try: with tempfile.NamedTemporaryFile(delete=False) as package_file: package_file.write(package_data) return app_pkg.load_from_file( package_file.name, target_dir=package_directory, drop_dir=False, loader=YaqlYamlLoader ) except IOError: LOG.exception("Unable to write package file") raise pkg_exc.PackageLoadError() finally: try: os.remove(package_file.name) except OSError: pass
def _build_index(self): for entry in os.listdir(self._base_path): folder = os.path.join(self._base_path, entry) if not os.path.isdir(folder) or entry in self._processed_entries: continue try: package = app_pkg.load_from_dir(folder, preload=True, loader=YaqlYamlLoader) except pkg_exc.PackageLoadError: LOG.exception("Unable to load package from path: " "{0}".format(entry)) continue for c in package.classes: self._packages_by_class[c] = package self._packages_by_name[package.full_name] = package self._processed_entries.add(entry)
def _build_index(self): for entry in os.listdir(self._base_path): folder = os.path.join(self._base_path, entry) if not os.path.isdir(folder) or entry in self._processed_entries: continue try: package = app_pkg.load_from_dir(folder, preload=True, loader=YaqlYamlLoader) except pkg_exc.PackageLoadError: LOG.exception('Unable to load package from path: ' '{0}'.format(entry)) continue for c in package.classes: self._packages_by_class[c] = package self._packages_by_name[package.full_name] = package self._processed_entries.add(entry)
def _get_package_by_definition(self, package_def): package_id = package_def.id package_name = package_def.fully_qualified_name package_directory = os.path.join(self._cache_directory, package_name) if os.path.exists(package_directory): try: return app_pkg.load_from_dir(package_directory, preload=True, loader=YaqlYamlLoader) except pkg_exc.PackageLoadError: LOG.exception('Unable to load package from cache. Clean-up...') shutil.rmtree(package_directory, ignore_errors=True) try: package_data = self._client.packages.download(package_id) except muranoclient_exc.HTTPException: LOG.exception('Unable to download ' 'package with id {0}'.format(package_id)) raise pkg_exc.PackageLoadError() try: with tempfile.NamedTemporaryFile(delete=False) as package_file: package_file.write(package_data) return app_pkg.load_from_file( package_file.name, target_dir=package_directory, drop_dir=False, loader=YaqlYamlLoader ) except IOError: LOG.exception('Unable to write package file') raise pkg_exc.PackageLoadError() finally: try: os.remove(package_file.name) except OSError: pass
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))