def helm_install(self):
     try:
         self.queue.put(('Preparing for installation', 'ONPROGRESS'))
         helm = Helm()
         if gluu_settings.db.get("INSTALL_REDIS") == "Y" or \
                 gluu_settings.db.get("INSTALL_GLUU_GATEWAY") == "Y" or \
                 gluu_settings.db.get("JACKRABBIT_CLUSTER") == "Y":
             helm.uninstall_kubedb()
             helm.install_kubedb()
         if gluu_settings.db.get("JACKRABBIT_CLUSTER") == "Y":
             kustomize = Kustomize(self.timeout)
             kustomize.deploy_postgres()
         if gluu_settings.db.get("INSTALL_REDIS") == "Y":
             kustomize = Kustomize(self.timeout)
             kustomize.uninstall_redis()
             kustomize.deploy_redis()
         self.queue.put(('Installation in progress', 'ONPROGRESS'))
         helm.install_gluu()
         self.queue.put(('Installation is complete', 'COMPLETED'))
     except SystemExit:
         if self.queue:
             self.queue.put(("Oops! Something went wrong", "ERROR"))
         else:
             logger.error("***** Error caught in main loop *****")
             logger.error(traceback.format_exc())
 def install_ldap_backup(self):
     try:
         self.queue.put(('Installation in progress', 'ONPROGRESS'))
         kustomize = Kustomize(self.timeout)
         kustomize.setup_backup_ldap()
         self.queue.put(('Installation is complete', 'COMPLETED'))
     except SystemExit:
         if self.queue:
             self.queue.put(("Oops! Something went wrong", "ERROR"))
         else:
             logger.error("***** Error caught in main loop *****")
             logger.error(traceback.format_exc())
 def helm_uninstall_gg_mode(self):
     try:
         self.queue.put(('Uninstalling...', 'ONPROGRESS'))
         kustomize = Kustomize(self.timeout)
         kustomize.uninstall_postgres()
         helm = Helm()
         helm.uninstall_gluu_gateway_dbmode()
         helm.uninstall_gluu_gateway_ui()
         self.queue.put(('Uninstall is complete', 'COMPLETED'))
     except SystemExit:
         if self.queue:
             self.queue.put(("Oops! Something went wrong", "ERROR"))
         else:
             logger.error("***** Error caught in main loop *****")
             logger.error(traceback.format_exc())
 def uninstall(self):
     try:
         logger.info("Removing all Gluu resources...")
         self.queue.put(('Uninstalling...', 'ONPROGRESS'))
         kustomize = Kustomize(self.timeout)
         kustomize.uninstall()
         if gluu_settings.db.get("INSTALL_REDIS") == "Y" or gluu_settings.db.get(
                 "INSTALL_GLUU_GATEWAY") == "Y":
             helm = Helm()
             helm.uninstall_kubedb()
         self.queue.put(('Uninstall is complete', 'COMPLETED'))
     except SystemExit:
         if self.queue:
             self.queue.put(("Oops! Something went wrong", "ERROR"))
         else:
             logger.error("***** Error caught in main loop *****")
             logger.error(traceback.format_exc())
 def helm_uninstall(self):
     try:
         kustomize = Kustomize(self.timeout)
         helm = Helm()
         self.queue.put(('Uninstalling', 'ONPROGRESS'))
         helm.uninstall_gluu()
         helm.uninstall_nginx_ingress()
         helm.uninstall_gluu_gateway_dbmode()
         helm.uninstall_gluu_gateway_ui()
         logger.info("Please wait...")
         time.sleep(30)
         kustomize.uninstall()
         helm.uninstall_kubedb()
         self.queue.put(('Uninstall is complete', 'COMPLETED'))
     except SystemExit:
         if self.queue:
             self.queue.put(("Oops! Something went wrong", "ERROR"))
         else:
             logger.error("***** Error caught in main loop *****")
             logger.error(traceback.format_exc())
    def upgrade(self):
        try:
            # New feature in 4.2 compared to 4.1 and hence if enabled should make
            # sure kubedb is installed.
            self.queue.put(('Preparing upgrade...', 'ONPROGRESS'))
            if gluu_settings.db.get("JACKRABBIT_CLUSTER") == "Y":
                helm = Helm()
                helm.uninstall_kubedb()
                helm.install_kubedb()

            logger.info("Starting upgrade...")
            self.queue.put(('Upgrading...', 'ONPROGRESS'))
            kustomize = Kustomize(self.timeout)
            kustomize.upgrade()
            self.queue.put(('Upgrade is complete', 'COMPLETED'))
        except SystemExit:
            if self.queue:
                self.queue.put(("Oops! Something went wrong", "ERROR"))
            else:
                logger.error("***** Error caught in main loop *****")
                logger.error(traceback.format_exc())
 def restore(self):
     try:
         self.queue.put(('Restoring...', 'ONPROGRESS'))
         kustomize = Kustomize(self.timeout)
         kustomize.copy_configs_before_restore()
         kustomize.uninstall(restore=True)
         kustomize.install(install_couchbase=False, restore=True)
         self.queue.put(('Restoring is complete', 'COMPLETED'))
     except SystemExit:
         if self.queue:
             self.queue.put(("Oops! Something went wrong", "ERROR"))
         else:
             logger.error("***** Error caught in main loop *****")
             logger.error(traceback.format_exc())
def main():
    parser = create_parser()
    args = parser.parse_args(sys.argv[1:])

    if not args.subparser_name:
        parser.print_help()
        return
    copy_templates()
    settings = SettingsHandler()
    settings.validate()
    if not settings.validate():
        for error in settings.errors:
            logger.error(error)
        sys.exit()

    prompts = Prompt()
    prompts.prompt()

    timeout = 120
    if args.subparser_name == "install-no-wait":
        timeout = 0
    try:
        if args.subparser_name == "install" or args.subparser_name == "install-no-wait":
            kustomize = Kustomize(timeout)
            kustomize.uninstall()
            if settings.get("INSTALL_REDIS") == "Y" or \
                    settings.get("INSTALL_GLUU_GATEWAY") == "Y" or \
                    settings.get("JACKRABBIT_CLUSTER") == "Y":
                helm = Helm()
                helm.uninstall_kubedb()
                helm.install_kubedb()
            kustomize.install()

        if args.subparser_name == "install-ldap-backup":
            kustomize = Kustomize(timeout)
            kustomize.setup_backup_ldap()

        elif args.subparser_name == "uninstall":
            logger.info("Removing all Gluu resources...")
            kustomize = Kustomize(timeout)
            kustomize.uninstall()
            if settings.get("INSTALL_REDIS") == "Y" or settings.get("INSTALL_GLUU_GATEWAY") == "Y":
                helm = Helm()
                helm.uninstall_kubedb()

        elif args.subparser_name == "upgrade":
            from pygluu.kubernetes.terminal.upgrade import PromptUpgrade
            # New feature in 4.2 compared to 4.1 and hence if enabled should make sure kubedb is installed.
            if settings.get("JACKRABBIT_CLUSTER") == "Y":
                helm = Helm()
                helm.uninstall_kubedb()
                helm.install_kubedb()
            prompt_upgrade = PromptUpgrade(settings)
            logger.info("Starting upgrade...")
            prompt_upgrade.prompt_upgrade()
            kustomize = Kustomize(timeout)
            kustomize.upgrade()

        elif args.subparser_name == "upgrade-values-yaml":
            from pygluu.kubernetes.terminal.upgrade import PromptUpgrade
            # New feature in 4.2 compared to 4.1 and hence if enabled should make sure kubedb is installed.
            helm = Helm()
            if settings.get("JACKRABBIT_CLUSTER") == "Y":
                helm.uninstall_kubedb()
                helm.install_kubedb()
            prompt_upgrade = PromptUpgrade(settings)
            prompt_upgrade.prompt_upgrade()
            helm = Helm()
            logger.info("Patching values.yaml for helm upgrade...")
            helm.analyze_global_values()
            logger.info("Please find your patched values.yaml at the location ./helm/gluu/values.yaml."
                        "Continue with the steps found at https://gluu.org/docs/gluu-server/latest/upgrade/#helm")

        elif args.subparser_name == "restore":
            kustomize = Kustomize(timeout)
            kustomize.copy_configs_before_restore()
            kustomize.uninstall(restore=True)
            kustomize.install(install_couchbase=False, restore=True)

        elif args.subparser_name == "install-couchbase":
            from pygluu.kubernetes.terminal.couchbase import PromptCouchbase
            prompt_couchbase = PromptCouchbase(settings)
            prompt_couchbase.prompt_couchbase()
            couchbase = Couchbase()
            couchbase.install()

        elif args.subparser_name == "install-couchbase-backup":
            from pygluu.kubernetes.terminal.couchbase import PromptCouchbase
            prompt_couchbase = PromptCouchbase(settings)
            prompt_couchbase.prompt_couchbase()
            couchbase = Couchbase()
            couchbase.setup_backup_couchbase()

        elif args.subparser_name == "uninstall-couchbase":
            from pygluu.kubernetes.terminal.couchbase import PromptCouchbase
            prompt_couchbase = PromptCouchbase(settings)
            prompt_couchbase.prompt_couchbase()
            couchbase = Couchbase()
            couchbase.uninstall()

        elif args.subparser_name == "install-gg-dbmode":
            from pygluu.kubernetes.terminal.gluugateway import PromptGluuGateway
            prompt_gluu_gateway = PromptGluuGateway(settings)
            prompt_gluu_gateway.prompt_gluu_gateway()
            kustomize = Kustomize(timeout)
            kustomize.install_gluu_gateway_dbmode()

        elif args.subparser_name == "install-kubedb":
            helm = Helm()
            helm.install_kubedb()

        elif args.subparser_name == "uninstall-gg-dbmode":
            kustomize = Kustomize(timeout)
            kustomize.uninstall_kong()
            kustomize.uninstall_gluu_gateway_ui()

        elif args.subparser_name == "generate-settings":
            logger.info("settings.json has been generated")

        elif args.subparser_name == "helm-install":
            from pygluu.kubernetes.terminal.helm import PromptHelm
            prompt_helm = PromptHelm(settings)
            prompt_helm.prompt_helm()
            helm = Helm()
            if settings.get("INSTALL_REDIS") == "Y" or \
                    settings.get("INSTALL_GLUU_GATEWAY") == "Y" or \
                    settings.get("JACKRABBIT_CLUSTER") == "Y":
                helm.uninstall_kubedb()
                helm.install_kubedb()
            if settings.get("JACKRABBIT_CLUSTER") == "Y":
                kustomize = Kustomize(timeout)
                kustomize.deploy_postgres()
            if settings.get("INSTALL_REDIS") == "Y":
                kustomize = Kustomize(timeout)
                kustomize.uninstall_redis()
                kustomize.deploy_redis()
            helm.install_gluu()

        elif args.subparser_name == "helm-uninstall":
            from pygluu.kubernetes.terminal.helm import PromptHelm
            prompt_helm = PromptHelm(settings)
            prompt_helm.prompt_helm()
            kustomize = Kustomize(timeout)
            helm = Helm()
            helm.uninstall_gluu()
            helm.uninstall_nginx_ingress()
            helm.uninstall_gluu_gateway_dbmode()
            helm.uninstall_gluu_gateway_ui()
            logger.info("Please wait...")
            time.sleep(30)
            kustomize.uninstall()
            helm.uninstall_kubedb()

        elif args.subparser_name == "helm-install-gluu":
            from pygluu.kubernetes.terminal.helm import PromptHelm
            prompt_helm = PromptHelm(settings)
            prompt_helm.prompt_helm()
            helm = Helm()
            helm.uninstall_gluu()
            helm.install_gluu(install_ingress=False)

        elif args.subparser_name == "helm-install-gg-dbmode":
            from pygluu.kubernetes.terminal.helm import PromptHelm
            prompt_helm = PromptHelm(settings)
            prompt_helm.prompt_helm()
            kustomize = Kustomize(timeout)
            kustomize.patch_or_deploy_postgres()
            helm = Helm()
            helm.install_gluu_gateway_dbmode()
            helm.install_gluu_gateway_ui()

        elif args.subparser_name == "helm-uninstall-gg-dbmode":
            from pygluu.kubernetes.terminal.helm import PromptHelm
            prompt_helm = PromptHelm(settings)
            prompt_helm.prompt_helm()
            kustomize = Kustomize(timeout)
            kustomize.uninstall_postgres()
            helm = Helm()
            helm.uninstall_gluu_gateway_dbmode()
            helm.uninstall_gluu_gateway_ui()

        elif args.subparser_name == "helm-uninstall-gluu":
            from pygluu.kubernetes.terminal.helm import PromptHelm
            prompt_helm = PromptHelm(settings)
            prompt_helm.prompt_helm()
            helm = Helm()
            helm.uninstall_gluu()

    except KeyboardInterrupt:
        print("\n[I] Canceled by user; exiting ...")