Ejemplo n.º 1
0
    def add_instance_group(self, name):
        single_ig = Struct(**list(filter(lambda d: d['name'] in [name], self.settings.provision.instance_groups))[0])
        populated_ig_file = self.get_ig_filename(single_ig.name)

        task = "Get Kops Instance Group {0} settings".format(single_ig.name)
        cmd = "kops get ig --name={0} nodes -oyaml --state={1} > {2}/remote.{3}".format(
            self.settings.provision.domain,
            self.settings.provision.s3_store,
            self.settings.folder_user_populated,
            populated_ig_file)
        Static.msg(name, task)
        Cmd.local_run_long(name, cmd)

        task = "Render Instance Group {0} Template".format(single_ig.name)
        Static.msg(name, task)
        self.localtemplate.generate_template_node(self.file_local_nodes, populated_ig_file, single_ig)

        task = "Update Kops Instance Group {0} settings".format(single_ig.name)
        cmd = "kops replace -f {0}/{1} --state={2} --force".format(
            self.settings.folder_user_populated,
            populated_ig_file,
            self.settings.provision.s3_store
        )
        Static.msg(name, task)
        Cmd.local_run_long(name, cmd)
Ejemplo n.º 2
0
    def taint_add_to_master_noschedule(self):

        name = "Add Taint Master. No Schedule"
        master_node = self.get_master_node()
        cmd = "kubectl taint nodes {0} node-role.kubernetes.io/master=:NoSchedule".format(
            master_node)
        Static.msg(name, master_node)
        Cmd.local_run_long(name, cmd)
Ejemplo n.º 3
0
    def taint_remove_from_master(self):

        name = "Remove Taint Master"
        master_node = self.get_master_node()
        cmd = "kubectl taint nodes {0} node-role.kubernetes.io/master-".format(
            master_node)
        Static.msg(name, master_node)
        try:
            Cmd.local_run_long(name, cmd)
        except:
            pass
Ejemplo n.º 4
0
    def add_instance_group(self, ig):
        name = "ADD INSTANCE GROUP"
        Static.figletcyber(name)

        cmd = "kops create ig {0} --state={1} {2}".format(
            ig.name,
            self.settings.provision.s3_store,
            self.settings.provision.domain
        )
        Static.msg(name, "KOPS: aws")
        Cmd.local_run_long(name, cmd)
Ejemplo n.º 5
0
 def use_context(self):
     name = "Kubectl Use Context"
     cmd = None
     context = None
     if self.settings.provision.cloud != "minikube":
         cmd = "kubectl config use-context {0}".format(
             self.settings.provision.domain)
         context = self.settings.provision.domain
     else:
         cmd = "kubectl config use-context minikube"
         context = "minikube"
     Static.msg(name, context)
     Cmd.local_run_long(name, cmd)
     print
Ejemplo n.º 6
0
    def create_cluster(self):
        name = "CREATE CLUSTER"
        Static.figletcyber(name)

        cmd = "kops create cluster --zones {0} --vpc {1} --dns-zone={2} --state={3} {4}".format(
            self.settings.aws_zone,
            self.settings.provision.vpc_id,
            self.settings.provision.dnszone_id,
            self.settings.provision.s3_store,
            self.settings.provision.domain
        )
        print cmd
        Static.msg(name, "KOPS: aws")
        Cmd.local_run_long(name, cmd)
Ejemplo n.º 7
0
    def update_cluster(self):
        name = "UPDATE CLUSTER"
        Static.figletcyber(name)

        task = "Rolling Update CLuster"
        cmd = "kops rolling-update cluster {0} --state={1} --yes -v={2} 2>&1".format(
            self.settings.provision.domain,
            self.settings.provision.s3_store,
            self.settings.provision.kops_verbosity
        )
        Static.msg(name, task)
        print cmd
        Cmd.local_run_long(name, cmd)

        self.validate_cluster()
Ejemplo n.º 8
0
    def provision_cluster(self):
        name = "PROVISION CLUSTER"
        Static.figletcyber(name)

        task = "Provision in Cloud"
        cmd = "kops update cluster {0} --state={1} --yes -v={2} 2>&1".format(
            self.settings.provision.domain,
            self.settings.provision.s3_store,
            self.settings.provision.kops_verbosity
        )
        Static.msg(name, task)
        print cmd
        Cmd.local_run_long(name, cmd)

        self.validate_cluster()
Ejemplo n.º 9
0
    def install(self, element):
        name = "INSTALL CHART"

        task = "Populate Chart Values"
        Static.msg(name, task)
        self.localtemplate.generate_template_element(element)


        # name autoassigned, replace to use same name, unsafe in prod, good for testing
        cmd = "helm upgrade --install --debug --namespace {1} --values={2} {0} {3}".format(
            element.release,
            element.name,
            self.localtemplate.path_populated,
            element.chart
        )

        print cmd
        Static.msg(name, "{0}".format(element.chart))
        Cmd.local_run_long(name, cmd)
Ejemplo n.º 10
0
    def apply(self, component_item):

        cmd = "kubectl apply -f {0}/{1}".format(
            self.settings.folder_user_populated, component_item.template)
        Static.msg("Adding Component", component_item.name)
        Cmd.local_run_long(component_item.name, cmd)
Ejemplo n.º 11
0
 def get_all_on_namespace(self, name):
     cmd = "kubectl get pods,svc,ing --namespace={0}".format(name)
     Static.msg("Displaying status of namespace", name)
     Cmd.local_run_long("Get Namespace Details", cmd)
Ejemplo n.º 12
0
 def get_ing(self):
     name = "Get Ingress"
     cmd = "kubectl get ing --all-namespaces"
     Static.msg(name, self.settings.provision.domain)
     Cmd.local_run_long(name, cmd)
     print
Ejemplo n.º 13
0
 def get_svc(self):
     name = "Get Services"
     cmd = "kubectl get svc --all-namespaces"
     Static.msg(name, self.settings.provision.domain)
     Cmd.local_run_long(name, cmd)
     print
Ejemplo n.º 14
0
 def get_pods(self):
     name = "Get Pods (sorted by nodeName)"
     cmd = 'kubectl get pods --all-namespaces -o wide --sort-by="{.spec.nodeName}"'
     Static.msg(name, self.settings.provision.domain)
     Cmd.local_run_long(name, cmd)
     print
Ejemplo n.º 15
0
 def get_nodes(self):
     name = "Get Nodes"
     cmd = "kubectl get nodes --show-labels -o wide"
     Static.msg(name, self.settings.provision.domain)
     Cmd.local_run_long(name, cmd)
     print
Ejemplo n.º 16
0
 def config_vm_virtualbox(self):
     name = "Minikube Configure to use Virtualbox"
     cmd = "minikube config set vm-driver virtualbox"
     Static.msg(name, '.')
     Cmd.local_run_long(name, cmd)
Ejemplo n.º 17
0
    def update_settings(self):
        name = "UPDATE KOPS SETTINGS"
        Static.figletcyber(name)

        # CLUSTER ====
        task = "Get Kops Cluster settings"
        cmd = "kops get cluster -oyaml --state={0} > {1}/remote.{2}".format(
            self.settings.provision.s3_store,
            self.settings.folder_user_populated,
            self.file_local_cluster)
        Static.msg(name, task)
        Cmd.local_run_long(name, cmd)

        task = "Render Cluster Template"
        Static.msg(name, task)
        self.localtemplate.generate_template(self.file_local_cluster)

        task = "Update Kops Clusters settings"
        cmd = "kops replace -f {0}/{1} --state={2}".format(
            self.settings.folder_user_populated,
            self.file_local_cluster,
            self.settings.provision.s3_store
        )
        Static.msg(name, task)
        Cmd.local_run_long(name, cmd)

        # MASTER ====
        task = "Get Kops Master settings"
        cmd = "kops get ig --name={0} master-{1} -oyaml --state={2} > {3}/remote.{4}".format(
            self.settings.provision.domain,
            self.settings.aws_zone,
            self.settings.provision.s3_store,
            self.settings.folder_user_populated,
            self.file_local_master)
        Static.msg(name, task)
        Cmd.local_run_long(name, cmd)

        task = "Render Master Template"
        Static.msg(name, task)
        self.localtemplate.generate_template(self.file_local_master)

        task = "Update Kops Master settings"
        cmd = "kops replace -f {0}/{1} --state={2}".format(
            self.settings.folder_user_populated,
            self.file_local_master,
            self.settings.provision.s3_store
        )
        Static.msg(name, task)
        Cmd.local_run_long(name, cmd)

        # INSTANCE_GROUPS ====
        for ig in self.settings.provision.instance_groups:
            single_ig = Struct(**ig)
            populated_ig_file = self.get_ig_filename(single_ig.name)

            task = "Get Kops Instance Group {0} settings".format(single_ig.name)
            cmd = "kops get ig --name={0} nodes -oyaml --state={1} > {2}/remote.{3}".format(
                self.settings.provision.domain,
                self.settings.provision.s3_store,
                self.settings.folder_user_populated,
                populated_ig_file)
            Static.msg(name, task)
            Cmd.local_run_long(name, cmd)

            task = "Render Instance Group {0} Template".format(single_ig.name)
            Static.msg(name, task)
            self.localtemplate.generate_template_node(self.file_local_nodes, populated_ig_file, single_ig)

            task = "Update Kops Instance Group {0} settings".format(single_ig.name)
            cmd = "kops replace -f {0}/{1} --state={2} --force".format(
                self.settings.folder_user_populated,
                populated_ig_file,
                self.settings.provision.s3_store
            )
            Static.msg(name, task)
            Cmd.local_run_long(name, cmd)

        print