Exemplo n.º 1
0
def preflight_check():
    """
    Preliminary checks to see if we can proceed with cluster reset
    """
    exit_if_no_root()
    exit_if_no_permission()
    is_cluster_locked()
    ensure_started()
    wait_for_ready(timeout=30)
    exit_if_multinode()
Exemplo n.º 2
0
def restart_cluster():
    """
    Restart a cluster by calling the stop and start wrappers.
    """
    print("Restarting cluster")
    cmd = [f"{os.environ['SNAP']}/microk8s-stop.wrapper"]
    subprocess.run(cmd)
    time.sleep(5)
    cmd = [f"{os.environ['SNAP']}/microk8s-start.wrapper"]
    subprocess.run(cmd)
    wait_for_ready(timeout=30)
    ensure_started()
Exemplo n.º 3
0
def disable_addon(repo, addon, args=None):
    """
    Try to disable an addon. Ignore any errors and/or silence any output.
    """
    if args is None:
        args = []
    wait_for_ready(timeout=30)
    script = snap_common() / "addons" / repo / "addons" / addon / "disable"
    if not script.exists():
        return

    try:
        subprocess.run([script, *args], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
    except (FileNotFoundError, PermissionError, subprocess.CalledProcessError) as e:
        print(f"Ignoring error: {e}", file=sys.stderr)

    wait_for_ready(timeout=30)
Exemplo n.º 4
0
def enable(addons) -> None:
    """
    Enable a MicroK8s addon.

    For a list of available addons, run `microk8s status`.

    To see help for individual addons, run:

        microk8s enable ADDON -- --help
    """
    if check_help_flag(addons):
        return

    is_cluster_locked()
    exit_if_no_permission()
    ensure_started()
    wait_for_ready(timeout=30)

    xable("enable", addons)
Exemplo n.º 5
0
def enable(addons):
    """Enables a MicroK8s addon.

    For a list of available addons, run `microk8s status`.

    To see help for individual addons, run:

        microk8s enable ADDON -- --help
    """

    if check_help_flag(addons):
        return

    is_cluster_locked()
    exit_if_no_permission()
    ensure_started()
    wait_for_ready(timeout=30)

    enabled_addons, _ = get_status(get_available_addons(get_current_arch()),
                                   True)
    enabled_addons = {a['name'] for a in enabled_addons}

    xable('enable', addons, enabled_addons)
Exemplo n.º 6
0
def disable(addons):
    """Disables one or more MicroK8s addons.

    For a list of available addons, run `microk8s status`.

    To see help for individual addons, run:

        microk8s disable ADDON -- --help
    """

    if check_help_flag(addons):
        return

    is_cluster_locked()
    exit_if_no_permission()
    ensure_started()
    wait_for_ready(timeout=30)

    _, disabled_addons = get_status(get_available_addons(get_current_arch()),
                                    True)
    disabled_addons = {a["name"] for a in disabled_addons}

    xable("disable", addons, disabled_addons)
Exemplo n.º 7
0
        default=0,
    )
    parser.add_argument("-a", "--addon", help="check the status of an addon.", default="all")
    parser.add_argument(
        "--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)
Exemplo n.º 8
0
        default=0,
    )
    parser.add_argument("-a", "--addon", help="check the status of an addon.", default="all")
    parser.add_argument(
        "--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(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)