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()
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()
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)
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)
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)
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)
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)
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)