Esempio n. 1
0
    def complete_installation():
        print(os.linesep)

        msg = "This Kubernetes environment"
        warnings = Log.get_warning_count()
        errors = Log.get_error_count()

        if errors > 0 and warnings > 0:
            msg = "{0} had {1} error(s) and {2} warning(s) during the bootstraping process for MapR".format(
                msg, errors, warnings)
            Log.error(msg)
        elif errors > 0 and warnings == 0:
            msg = "{0} had {1} error(s) during the bootstraping process for MapR".format(
                msg, errors)
            Log.error(msg)
        elif errors == 0 and warnings > 0:
            msg = "{0} had {1} warnings(s) during the bootstraping process for MapR".format(
                msg, warnings)
            Log.warning(msg)
        else:
            msg = "{0} has been successfully bootstrapped for MapR".format(msg)
            Log.info(msg, True)
            Log.info(
                "MapR components can now be created via the newly installed operators",
                True)

        if errors > 0 or warnings > 0:
            msg = "Please check the bootstrap log file for this session here: {0}".format(
                Log.get_log_filename())
            Log.warning(msg)

        Log.info("")
Esempio n. 2
0
    def prompt_file(self,
                    prompt_text,
                    default=None,
                    newline=False,
                    key_name=None):
        while True:
            result = self.prompt(prompt_text,
                                 default,
                                 newline=newline,
                                 key_name=key_name)
            if result is None:
                if self.mode == Prompts.HEADLESS_MODE:
                    raise InstallException(
                        'File path cannot be blank for key %s.' % key_name)

                Log.warning('Path cannot be blank.')
                continue

            if not os.path.exists(result):
                if self.mode == Prompts.HEADLESS_MODE:
                    raise InstallException(
                        'File path %s does not exist for key %s.' %
                        (result, key_name))

                Log.warning('Path to %s does not exist' % result)
                continue

            break

        return result
    def complete_uninstallation():
        print(os.linesep)

        msg = "This Kubernetes environment"
        warnings = Log.get_warning_count()
        errors = Log.get_error_count()

        if errors > 0 and warnings > 0:
            msg = "{0} had {1} error(s) and {2} warning(s) during the uninstall process for MapR".format(
                msg, errors, warnings)
            Log.error(msg)
        elif errors > 0 and warnings == 0:
            msg = "{0} had {1} error(s) during the uninstall process for MapR".format(
                msg, errors)
            Log.error(msg)
        elif errors == 0 and warnings > 0:
            msg = "{0} had {1} warnings(s) during the uninstall process for MapR".format(
                msg, warnings)
            Log.warning(msg)
        else:
            msg = "{0} has had MapR successfully uninstalled".format(msg)
            Log.info(msg, True)

        if errors > 0 or warnings > 0:
            msg = "Please check the bootstrap log file for this session here: {0}".format(
                Log.get_log_filename())
            Log.warning(msg)

        Log.info("")
Esempio n. 4
0
 def exit_application(signum, _=None):
     if signum == 0:
         Log.info("Bootstrap terminated {0}".format(signum))
     else:
         print(os.linesep)
         Log.warning("Bootstrap terminated {0}".format(signum))
     if BootstrapBase._prompts is not None:
         BootstrapBase._prompts.write_response_file()
         BootstrapBase._prompts = None
     Log.close()
     exit(signum)
Esempio n. 5
0
    def check_available():
        available_instances = dict()
        for cloud_name, cloud_instance in Cloud._cloud_instances.items():
            if cloud_instance.is_available():
                Log.debug("{0} cloud is available".format(cloud_name))
                available_instances[cloud_name] = cloud_instance
            else:
                Log.warning(
                    "{0} cloud was enabled but did not pass availability tests"
                    .format(cloud_name))

        Cloud._cloud_instances = available_instances
Esempio n. 6
0
    def install_cloud(self):
        print("")
        Cloud.initialize(self._prompts)
        cloud_names = Cloud.get_cloud_names()

        if len(cloud_names) == 0:
            Log.warning(
                "There are no supported cloud providers found in this bootstrapper application"
            )
            return False

        Log.info(
            "If you are installing in a cloud provider, we can help you create your kubernetes environment.",
            True)
        Log.info(
            "ATTENTION: Cloud Environment installation is provided AS IS with no support.",
            True)
        Log.info(
            "Work with your IT Team to help create kubernetes environments with the security and reliability features that suit your enterprise needs.",
            True)

        create = self._prompts.prompt_boolean(
            "Do you want to create a kubernetes environment in the Cloud?",
            False,
            key_name="CLOUD_ENV")
        if not create:
            Log.info("Not building cloud environment")
            return False

        # Check the availability of each enabled cloud provider
        Cloud.check_available()
        cloud_names = Cloud.get_cloud_names()
        if len(cloud_names) == 0:
            Log.warning(
                "Some clouds were enabled but necessary modules that support these clouds are not available"
            )
            BootstrapBase.exit_application(7)

        choice = self._prompts.prompt_choices("Choose a cloud provider",
                                              Cloud.get_cloud_names(),
                                              key_name="CLOUD_PROVIDER")
        Log.info("Using cloud provider {0}".format(choice))
        self.cloud_instance = Cloud.get_instance(choice)
        Log.debug("Using cloud instance {0}".format(str(self.cloud_instance)))

        Log.info("Building {0} cloud k8s...".format(choice))
        self.cloud_instance.build_cloud()
        Log.info("Created {0} cloud k8s".format(choice))
        self.cloud_created = True
        return True
Esempio n. 7
0
    def prompt_not_none(self,
                        prompt_text,
                        default=None,
                        password=False,
                        newline=False,
                        key_name=None):
        while True:
            result = self.prompt(prompt_text, default, password, newline,
                                 key_name)
            if result is not None:
                result = result.strip()
                if len(result) > 0:
                    return result

            Log.warning('Invalid: %s. Please re enter a non empty value.' %
                        prompt_text)
Esempio n. 8
0
    def is_available(self):
        if not self.enabled:
            return False

        if self.available is None:
            Log.info("Checking Google cloud availability. One moment...", True)
            results, status = OSCommand.run2(
                ["command -v gcloud", "gcloud compute instances list"])
            self.available = True if status == 0 else False

            if not self.available:
                Log.warning(
                    "Google Cloud SDK not found or not configured correctly. Quit bootstrapper, install and "
                    "confgure Google Cloud SDK and restart bootstrapper. See: https://cloud.google.com/sdk/. "
                    "More information on the error in the bootstrapper log here: "
                    + Log.get_log_filename())
                Log.warning(results)

        return self.available
Esempio n. 9
0
    def collect(self):
        Log.debug("Getting Python information...")

        python_major, python_version = self._get_python_version()
        Log.info("Python version: {0}".format(python_version))

        self.results[Validator.FOUND] = True
        self.results[Validator.VERSION] = python_version

        if python_major == 2:
            pmin = PythonValidator.PYTHON2_MIN
            pmax = PythonValidator.PYTHON2_MAX
        elif python_major == 3:
            pmin = PythonValidator.PYTHON3_MIN
            pmax = PythonValidator.PYTHON3_MAX

            if python_version <= PythonValidator.PYTHON3_ERROR_MAX:
                Log.error("The virtual environments created with your python version {0} are incompatible. "
                          "Please use Python 3.3 or greater".format(python_version))
                self.operation = Validator.OPERATION_INSTALL
                return
        else:
            Log.error("The major Python version '{0}' is not supported; Only version 2 and 3 supported".format(python_major))
            self.operation = Validator.OPERATION_TOO_NEW
            return

        expected = "Expected versions between {0} and {1} or between {2} and {3}"\
            .format(PythonValidator.PYTHON2_MIN, PythonValidator.PYTHON2_MAX,
                    PythonValidator.PYTHON3_MIN, PythonValidator.PYTHON3_MAX)

        if python_version > pmax or python_version < pmin:
            Log.warning("The Python version on this system is {0}. {1}"
                      .format(python_version, expected))
            self.operation = Validator.OPERATION_WARNING
        else:
            Log.debug("The Python version on this system is compatible")
            self.operation = Validator.OPERATION_OK
Esempio n. 10
0
    def prompt_choices(self,
                       prompt_text,
                       choices,
                       default=None,
                       newline=False,
                       key_name=None):
        if type(choices) is not list:
            raise InstallException('prompt_choices choice list is not a list.')

        choices_str = str(choices).replace('[', '(').replace(']', ')')
        prompt_text = '%s %s' % (prompt_text, choices_str)
        last_find = None

        if default is not None and default not in choices:
            raise InstallException(
                'The default value %s was not found in the list' % default)

        while True:
            response = self.prompt(prompt_text,
                                   default,
                                   newline=newline,
                                   key_name=key_name)
            find_count = 0

            if response is None:
                if self.mode == Prompts.HEADLESS_MODE:
                    raise InstallException(
                        '%s is not a choice in list %s for key %s.' %
                        (response, choices, key_name))

                Log.warning('Enter one of the choices in the list')
                continue

            for item in choices:
                if item.lower().find(response.lower()) >= 0:
                    find_count += 1
                    last_find = item

            if find_count == 0:
                Log.warning('You must enter one of the choices in the list')
            elif find_count >= 2:
                Log.warning('Your entry matched more than one choice')
            else:
                break

        return last_find