Esempio n. 1
0
def _verify_package_urls(urls):
    verified_urls = []
    for package_url in urls:
        if package_url is None:
            verified_urls.append(None)
            continue

        # Throw an error if not valid URL
        if is_package_url(package_url):
            verified_urls.append(package_url)
        else:
            user_error("Wrong package URL: {}".format(package_url))

    return verified_urls
Esempio n. 2
0
def _download_urls(urls):
    """Download packages from URLs, replace URLs with filenames

    Return a new list of packages where URLs are replaced with paths
    to packages which have been downloaded. Other values, like None
    and paths to local packages are preserved.
    """
    urls_dir = cf_remote_packages_dir("url_specified")

    downloaded_urls = []
    downloaded_paths = []
    paths = []
    for package_url in urls:
        # Skip anything that is not a package url:
        if package_url is None or not is_package_url(package_url):
            paths.append(package_url)
            continue

        if not os.path.isdir(urls_dir):
            os.mkdir(urls_dir)

        # separate name from url and construct path for downloaded file
        url, name = package_url, get_package_name(package_url)
        path = os.path.join(urls_dir, name)

        # replace url with local path to package in list which will be returned
        paths.append(path)

        if path in downloaded_paths and url not in downloaded_urls:
            user_error(
                f"2 packages with the same name '{name}' from different URLs")

        download_package(url, path)
        downloaded_urls.append(url)
        downloaded_paths.append(path)

    return paths
Esempio n. 3
0
def validate_command(command, args):
    if command in ["install", "packages", "list", "download"]:
        if args.edition:
            args.edition = args.edition.lower()
            if args.edition == "core":
                args.edition = "community"
            if args.edition not in ["enterprise", "community"]:
                user_error("--edition must be either community or enterprise")
        else:
            args.edition = "enterprise"

    if command in ["uninstall"] and not (args.hosts or args.hub or args.clients):
        user_error("Use --hosts, --hub or --clients to specify remote hosts")

    if command == "install":
        if args.call_collect and not args.demo:
            user_error("--call-collect must be used with --demo")
        if not args.clients and not args.hub:
            user_error("Specify hosts using --hub and --clients")
        if args.hub and args.clients and args.package:
            user_error(
                "Use --hub-package / --client-package instead to distinguish between hosts")
        if args.package and (args.hub_package or args.client_package):
            user_error(
                "--package cannot be used in combination with --hub-package / --client-package")
        if args.package and not is_package_url(args.package):
            if not os.path.exists(os.path.expanduser(args.package)):
                user_error(f"Package/directory '{args.package}' does not exist")
        if args.hub_package and not is_package_url(args.hub_package):
            if not os.path.isfile(args.hub_package):
                user_error(f"Hub package '{args.hub_package}' does not exist")
        if args.client_package and not is_package_url(args.client_package):
            if not os.path.isfile(args.client_package):
                user_error(f"Client package '{args.client_package}' does not exist")

    if command in ["sudo", "run"]:
        if len(args.remote_command) != 1:
            user_error("cf-remote sude/run requires exactly 1 command (use quotes)")
        args.remote_command = args.remote_command[0]

    if command == "spawn" and not args.list_platforms and not args.init_config:
        # --list-platforms doesn't require any other options/arguments (TODO:
        # --provider), but otherwise all have to be given
        if not args.platform:
            user_error("--platform needs to be specified")
        if not args.count:
            user_error("--count needs to be specified")
        if not args.role:
            user_error("--role needs to be specified")
        if not args.name:
            user_error("--name needs to be specified")

    if command == "destroy":
        if not args.all and not args.name:
            user_error("One of --all or NAME required for destroy")

    if command == "deploy":
        if not args.directory:
            user_error("Must specify a masterfiles directory")
        if not args.hub:
            user_error("Must specify at least one hub")
        if not os.path.isdir(args.directory):
            user_error(f"'{args.directory}' is not a directory")