Example #1
0
 def invoke_gcloud(cmd):
     response, status = OSCommand.run2("gcloud {0}".format(cmd))
     if status != 0:
         Log.error("Could not create GKE Cluster: {0}: {1}".format(
             status, response))
         BootstrapBase.exit_application(101)
     return response, status
Example #2
0
    def build_cloud(self):
        self.cluster_name = self.prompts.prompt("Enter cluster name",
                                                self.cluster_name,
                                                key_name="GKE_CLUSTER_NAME")
        self.nodes = self.prompts.prompt_integer("Enter number of nodes",
                                                 self.nodes,
                                                 1,
                                                 key_name="GKE_NODE_COUNT")
        self.disks = self.prompts.prompt_integer(
            "Enter number of local SSD disks for MapR FS. Each disk will be a fixed 375GB",
            self.disks,
            1,
            key_name="GKE_NUM_DISKS")
        self.instance_type = self.prompts.prompt("GKE compute instance type?",
                                                 self.instance_type,
                                                 key_name="GKE_INSTANCE_TYPE")
        if self.alpha:
            self.k8s_version = self.prompts.prompt("Kubernetes version?",
                                                   self.k8s_alpha_version,
                                                   key_name="GKE_K8S_VERSION")
        else:
            self.k8s_version = self.prompts.prompt("Kubernetes version?",
                                                   self.k8s_version,
                                                   key_name="GKE_K8S_VERSION")
        self.zone = self.prompts.prompt("GCE Zone to deploy into?",
                                        self.zone,
                                        key_name="GKE_ZONE")
        self.project = self.prompts.prompt("GCE project id?",
                                           self.project,
                                           key_name="GKE_PROJECT_ID")
        self.user = self.prompts.prompt("GCE user id?",
                                        self.user,
                                        key_name="GKE_USER")
        # self.image_type = self.prompts.prompt("GKE image type?", self.image_type)
        Log.info("Using GKE compute image type: {0}".format(self.image_type),
                 True)
        if self.alpha:
            Log.info("Using alpha Kubernetes version", True)
        else:
            Log.info("Using non-alpha Kubernetes version", True)

        if not self.prompts.prompt_boolean(
                "Ready to create Google GKS cluster. Do you want to continue?",
                True,
                key_name="GKE_CREATE"):
            Log.error("Exiiting since user is not ready to continue")
            BootstrapBase.exit_application(100)

        before = time.time()
        self.create_k8s_cluster()
        after = time.time()
        diff = int(after - before)
        Log.info(
            "Cluster creation took {0}m {1}s".format(diff / 60, diff % 60),
            True)
 def confirm_delete_installation(self):
     print(os.linesep)
     Log.info(
         "This will uninstall ALL MapR operators from your Kubernetes environment. This will cause all Compute Spaces to be destroyed. They cannot be recovered!",
         True)
     agree = self._prompts.prompt_boolean("Do you agree?",
                                          False,
                                          key_name="AGREEMENT")
     if not agree:
         Log.info("Very wise decision. Exiting uninstall...", True)
         BootstrapBase.exit_application(2)
Example #4
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
Example #5
0
    def configure_kubernetes(self):
        print(os.linesep)
        Log.info("Ensuring proper kubernetes configuration...", True)
        Log.info("Checking kubectl can connect to your kubernetes cluster...",
                 True)
        response, status = OSCommand.run2("kubectl get nodes")
        if status != 0:
            Log.error(
                "Cannot connect to Kubernetes. Make sure kubectl is pre-configured to communicate with a Kubernetes cluster."
            )
            BootstrapBase.exit_application(4)

        Log.info("Looking good... Connected to Kubernetes", True)
        if self.cloud_instance is not None:
            self.cloud_instance.configure_cloud()
Example #6
0
 def validate_nodes(self):
     print(os.linesep)
     Log.info(
         "We must validate and annotate your Kubernetes nodes. "
         "MapR node validation pods will be installed.",
         stdout=True)
     agree = self._prompts.prompt_boolean("Do you agree?",
                                          True,
                                          key_name="AGREEMENT_VALIDATE")
     if not agree:
         Log.error("Exiting due to non-agreement...")
         BootstrapBase.exit_application(2)
     # TODO: Add node exclusion code here
     # exclude = self._prompts.prompt_boolean("Do you want to exclude any nodes?", False, key_name="EXCLUDE_NODES")
     # if exclude:
     #    Log.error("Operation not currently supported...")
     #    BootstrapBase.exit_application(6)
     print("")
Example #7
0
    def check_oc_installed():
        oc_validator = OpenshiftClientValidator()
        oc_validator.collect()

        if oc_validator.operation != Validator.OPERATION_OK:
            BootstrapBase.exit_application(5)
Example #8
0
 def check_laptop_tools():
     kubectl_validator = KubectlValidator()
     kubectl_validator.collect()
     if kubectl_validator.operation != Validator.OPERATION_OK:
         BootstrapBase.exit_application(3)
Example #9
0
        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("")

    @staticmethod
    def pas_complete_installation():
        Log.info("PAS Installation complete")


bootstrap_instsall = BootstrapInstall()
bootstrap_instsall.run()
BootstrapBase.exit_application(0)
Example #10
0
    def create_k8s_cluster(self):
        Log.info(
            "Creating cluster with {0} nodes of type {1} with {2} local ssd(s) of size 375GB..."
            .format(self.nodes, self.instance_type, self.disks), True)

        args = "--zone {0} ".format(self.zone)
        args += "--username admin "
        args += "--cluster-version {0} ".format(self.k8s_version)
        args += "--machine-type {0} ".format(self.instance_type)
        args += "--image-type {0} ".format(self.image_type)
        args += "--disk-size {0} ".format(self.disk_size_on_node)
        args += "--disk-type {0} ".format(self.disk_type_on_node)
        args += "--num-nodes {0} ".format(self.nodes)
        args += "--network default "
        args += "--enable-cloud-logging "
        args += "--enable-cloud-monitoring "
        args += "--subnetwork default "
        args += "--scopes https://www.googleapis.com/auth/compute,https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append "
        if self.alpha:
            args += "--enable-kubernetes-alpha "
            args += "--no-enable-autorepair "
            self.invoke_alpha_cluster(args)
        else:
            self.invoke_stable_cluster(args)

        Log.info("Node log follows after cluster creation. One moment...",
                 True)
        cmd = "container clusters get-credentials {0} --zone {1} --project {2}".format(
            self.cluster_name, self.zone, self.project)
        result, status = self.invoke_gcloud(cmd)
        Log.info(result, True)

        # TODO Got to be a better way to get this filtered list
        result, status = OSCommand.run2(
            "kubectl get nodes | grep Ready | cut -d' ' -f1")
        if status != 0:
            Log.error("Could not get list of nodes: {0}: {1}".format(
                status, result))
            BootstrapBase.exit_application(103)

        nodes = result.split("\n")
        if len(nodes[-1]) == 0:
            nodes = nodes[:-1]

        Log.info(
            "After cluster creation, {0} node(s) were found".format(
                len(nodes)), True)

        all_threads = list()
        for node in nodes:
            t = Thread(target=self.create_disks_and_attach,
                       args=(node, ),
                       name=node)
            all_threads.append(t)
            t.start()
            time.sleep(0.05)

        for thread in all_threads:
            thread.join(timeout=10 * 60)
            if thread.is_alive():
                Log.error(
                    "Thread for node {0} did not complete in the supplied time limit"
                    .format(thread.name))