def print_yaml(isReady, enabled_addons, disabled_addons): print("microk8s:") print("{:>2}{} {}".format("", "running:", isReady)) print("{:>2}".format("high-availability:")) ha_enabled = is_ha_enabled() print("{:>2}{} {}".format("", "enabled:", ha_enabled)) if ha_enabled: info = get_dqlite_info() print("{:>2}{}".format("", "nodes:")) for node in info: print("{:>6}address: {:<1}".format("- ", node[0])) print("{:>6}role: {:<1}".format("", node[1])) if isReady: print("{:>2}".format("addons:")) for enabled in enabled_addons: print("{:>4}name: {:<1}".format("- ", enabled["name"])) print("{:>4}description: {:<1}".format("", enabled["description"])) print("{:>4}version: {:<1}".format("", enabled["version"])) print("{:>4}status: enabled".format("")) for disabled in disabled_addons: print("{:>4}name: {:<1}".format("- ", disabled["name"])) print("{:>4}description: {:<1}".format("", disabled["description"])) print("{:>4}version: {:<1}".format("", disabled["version"])) print("{:>4}status: disabled".format("")) else: print( "{:>2} {} {}".format( "", "message:", "microk8s is not running. Use microk8s inspect for a deeper inspection.", ) )
def print_pretty(isReady, enabled_addons, disabled_addons): console_formatter = "{:>3} {:<20} # ({}) {}" if isReady: print("microk8s is running") if not is_ha_enabled(): print("high-availability: no") else: info = get_dqlite_info() if ha_cluster_formed(info): print("high-availability: yes") else: print("high-availability: no") masters = "none" standby = "none" for node in info: if node[1] == "voter": if masters == "none": masters = "{}".format(node[0]) else: masters = "{} {}".format(masters, node[0]) if node[1] == "standby": if standby == "none": standby = "{}".format(node[0]) else: standby = "{} {}".format(standby, node[0]) print("{:>2}{} {}".format("", "datastore master nodes:", masters)) print("{:>2}{} {}".format("", "datastore standby nodes:", standby)) print("addons:") if enabled_addons and len(enabled_addons) > 0: print("{:>2}{}".format("", "enabled:")) for enabled in enabled_addons: print( console_formatter.format( "", enabled["name"], enabled["repository"], enabled["description"] ) ) if disabled_addons and len(disabled_addons) > 0: print("{:>2}{}".format("", "disabled:")) for disabled in disabled_addons: print( console_formatter.format( "", disabled["name"], disabled["repository"], disabled["description"] ) ) else: print("microk8s is not running. Use microk8s inspect for a deeper inspection.")
set_dqlite_file_permissions() # We will not attempt to stop services if: # 1. The cluster is not ready # 2. We are not on an HA cluster # 3. The control plane kicker is disabled # 4. dqlite has less than 4 nodes if ( not is_cluster_ready() or not is_ha_enabled() or not is_service_expected_to_start('control-plane-kicker') ): start_control_plane_services() continue info = get_dqlite_info() if len(info) <= 3: start_control_plane_services() continue local_ips = [] for interface in netifaces.interfaces(): if netifaces.AF_INET not in netifaces.ifaddresses(interface): continue for link in netifaces.ifaddresses(interface)[netifaces.AF_INET]: local_ips.append(link['addr']) voter_ips = [] for node in info: if node[1] == "voter": ip_parts = node[0].split(':')