Esempio n. 1
0
    def post(self, **kwargs):
        t_start = time.time()
        args = packages_parser.parse_args()
        LOG.info("POST to /packages w. args: {}".format(args),
                 extra={"start_stop": "START"})
        if args.package.filename is None:
            LOG.warning("Posted package filename was None.")
            args.package.filename = "temp_pkg.tgo"
        temppkg_path = _write_to_temp_file(args.package)
        args.package = None
        args.unpackage = temppkg_path
        # pass CLI args to REST args
        args.offline = False
        args.no_checksums = False
        args.no_autoversion = False
        args.store_skip = False
        if app.cliargs is not None:
            args.output = None
            args.workspace = None
            args.offline = app.cliargs.offline
            args.no_checksums = app.cliargs.no_checksums
            args.no_autoversion = app.cliargs.skip_autoversion
            args.store_skip = app.cliargs.store_skip
            args.skip_validation = app.cliargs.skip_validation

        # select and instantiate storage backend
        sb = None
        if (not args.store_skip  # from CLI
                and not args.skip_store  # from request
                and not os.environ.get("STORE_SKIP", "False") == "True"):
            sb_env = os.environ.get("STORE_BACKEND", "TangoCatalogBackend")
            if sb_env == "TangoCatalogBackend":
                sb = TangoCatalogBackend(args)
            elif sb_env == "TangoProjectFilesystemBackend":
                sb = TangoProjectFilesystemBackend(args)
            elif sb_env == "OsmNbiBackend":
                sb = OsmNbiBackend(args)
            else:
                LOG.warning("Unknown storage backend: {}.".format(sb_env))
        # instantiate packager
        p = PM.new_packager(args, storage_backend=sb)
        try:
            p.unpackage(callback_func=on_unpackaging_done)
        except BaseException as e:
            LOG.exception("Unpackaging error: {}".format(e))
        LOG.info("POST to /packages done",
                 extra={
                     "start_stop": "STOP",
                     "status": p.status,
                     "time_elapsed": str(time.time() - t_start)
                 })
        return {
            "package_process_uuid": str(p.uuid),
            "status": p.status,
            "error_msg": p.error_msg
        }
Esempio n. 2
0
def dispatch(args):
    # trigger pack/unpack
    if args.package:
        # instantiate packager
        p = PM.new_packager(args, pkg_format=args.pkg_format)
        p.package()
        LOG.debug("Packager result: {}".format(p.result))
        display_result_package(args, p.result)
    elif args.unpackage:
        # select and instantiate storage backend
        # default in CLI mode: TangoProjectFilesystemBackend
        sb = None
        if (not args.store_skip
                and not os.environ.get("STORE_SKIP", "False") == "True"):
            sb_env = args.store_backend
            if sb_env is None:
                sb_env = os.environ.get("STORE_BACKEND",
                                        "TangoProjectFilesystemBackend")
            if sb_env == "TangoCatalogBackend":
                sb = TangoCatalogBackend(args)
            elif sb_env == "TangoProjectFilesystemBackend":
                sb = TangoProjectFilesystemBackend(args)
            elif sb_env == "OsmNbiBackend":
                sb = OsmNbiBackend(args)
            else:
                LOG.warning(
                    "Unknown storage backend: {}. Stop.".format(sb_env))
                exit(1)
        # instantiate packager
        p = PM.new_packager(args, storage_backend=sb)
        p.unpackage()
        LOG.debug("Packager result: {}".format(p.result))
        display_result_unpackage(args, p.result)
    else:
        print("Missing arguments. Type tng-package -h.")
        exit(1)
    return p.result