Exemplo n.º 1
0
def disable_addons(destroy_storage):
    """
    Iterate over all addons and disable the enabled ones.
    """
    print("Disabling all addons")

    available_addons_info = get_available_addons(get_current_arch())
    enabled, disabled = get_status(available_addons_info, True)
    for addon in available_addons_info:
        # Do not disable HA
        if addon["name"] == "ha-cluster":
            continue

        # Do not disable the community repository
        if addon["name"] == "community":
            continue

        print(f"Disabling addon : {addon['repository']}/{addon['name']}")
        # Do not disable disabled addons
        if addon in disabled:
            continue

        if (addon["name"] == "hostpath-storage" or addon["name"] == "storage") and destroy_storage:
            disable_addon(addon["repository"], f"{addon['name']}", ["destroy-storage"])
        else:
            disable_addon(addon["repository"], addon["name"])
    print("All addons are disabled.")
Exemplo n.º 2
0
def list(format: str):
    arch = get_current_arch()
    repositories = []
    for dir in os.listdir(snap_common() / "addons"):
        try:
            repo_dir = snap_common() / "addons" / dir
            addons_yaml = repo_dir / "addons.yaml"
            with open(addons_yaml, "r") as fin:
                addons = yaml.safe_load(fin)

            count = 0
            for addon in addons["microk8s-addons"]["addons"]:
                if arch in addon["supported_architectures"]:
                    count += 1

            source = "(built-in)"
            try:
                remote_url = subprocess.check_output(
                    [GIT, "remote", "get-url", "origin"],
                    cwd=repo_dir,
                    stderr=subprocess.DEVNULL).decode()
                revision = subprocess.check_output(
                    [GIT, "rev-parse", "HEAD"],
                    cwd=repo_dir,
                    stderr=subprocess.DEVNULL).decode()[:6]
                source = "{}@{}".format(remote_url.strip(), revision.strip())
            except (subprocess.CalledProcessError, TypeError, ValueError):
                pass

            repositories.append({
                "name":
                dir,
                "addons":
                count,
                "source":
                source,
                "description":
                addons["microk8s-addons"]["description"],
            })

        except Exception as e:
            click.echo("could not load addons from {}: {}".format(
                addons_yaml, e),
                       err=True)

    if format == "json":
        click.echo(json.dumps(repositories))
    elif format == "yaml":
        click.echo(yaml.safe_dump(repositories))
    elif format == "table":
        click.echo(("{:10} {:>6} {}").format("REPO", "ADDONS", "SOURCE"))
        for repo in repositories:
            click.echo("{:10} {:>6} {}".format(repo["name"], repo["addons"],
                                               repo["source"]))
Exemplo n.º 3
0
        "--yaml", action='store_true', help="DEPRECATED, use '--format yaml' instead"
    )

    # read arguments from the command line
    args = parser.parse_args()

    wait_ready = args.wait_ready
    timeout = args.timeout
    yaml_short = args.yaml

    if wait_ready:
        isReady = wait_for_ready(wait_ready, timeout)
    else:
        isReady = is_cluster_ready()

    available_addons = get_available_addons(get_current_arch())

    if args.addon != "all":
        available_addons = get_addon_by_name(available_addons, args.addon)

    enabled, disabled = get_status(available_addons, isReady)

    if args.addon != "all":
        print_addon_status(enabled)
    else:
        if args.format == "yaml":
            print_yaml(isReady, enabled, disabled)
        elif args.format == "short":
            print_short(isReady, enabled, disabled)
        else:
            if yaml_short: