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.")
while True: # Check for changes every 10 seconds sleep(10) try: if microk8s_group_exists(): 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]:
restore_cmd = "{} {}".format(restore_cmd, "--debug") try: rc = run_command(restore_cmd) if rc > 0: print("Restore process failed. {}".format(rc)) exit(3) except subprocess.CalledProcessError as e: print("Restore process failed. {}".format(e)) exit(4) if __name__ == '__main__': exit_if_no_permission() is_cluster_locked() if not kine_exists() or not is_ha_enabled(): print( "Please ensure the kubernetes apiserver is running and HA is enabled." ) exit(10) # initiate the parser with a description parser = argparse.ArgumentParser( description="backup and restore the Kubernetes datastore.", prog='microk8s dbctl') parser.add_argument('--debug', action='store_true', help='print debug output') commands = parser.add_subparsers(title='commands', help='backup and restore operations') restore_parser = commands.add_parser("restore")
cmd = "chmod -R ug+rwX {}".format(dqlite_path) subprocess.check_call(cmd.split()) cmd = "chgrp microk8s -R {}".format(dqlite_path) subprocess.check_call(cmd.split()) except Exception as e: print("Failed to set the file permissions in dqlite.") print(e) if __name__ == '__main__': while True: # Check for changes every 10 seconds sleep(10) try: if microk8s_group_exists() and is_ha_enabled(): 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()