Ejemplo n.º 1
0
    def _get_pods_for_cr_connections(self,
                                     cr,
                                     cr_instance,
                                     namespace,
                                     conn_op_format="flat"):
        pod_list = []
        platf = platform.system()
        kubeplus_home = os.getenv('KUBEPLUS_HOME', '/')
        cmd = ''
        if platf == "Darwin":
            cmd = kubeplus_home + '/plugins/kubediscovery-macos connections ' + cr + ' ' + cr_instance + ' ' + namespace + ' -o ' + conn_op_format + ' --ignore=ServiceAccount:default'
        if platf == "Linux":
            cmd = kubeplus_home + '/plugins/kubediscovery-linux connections ' + cr + ' ' + cr_instance + ' ' + namespace + ' -o ' + conn_op_format + ' --ignore=ServiceAccount:default'

        if cmd:
            output = ''
            try:
                output = subprocess.Popen(cmd,
                                          stdout=subprocess.PIPE,
                                          stderr=subprocess.PIPE,
                                          shell=True).communicate()[0]
                output = output.decode('utf-8')
                output = output.strip("\n")
            except Exception as e:
                print(e)

            if conn_op_format == "flat:":
                pod_list = self._parse_pods_from_connections_op(output)
            if conn_op_format == "json":
                try:
                    json_output = json.loads(output)
                    pod_list = utils.get_pods(json_output)
                except Exception as e:
                    print(e)
        return pod_list
Ejemplo n.º 2
0
    def _get_pods_from_connections_pod(self, pod_name, namespace):
        pod_list = []
        platf = platform.system()
        kubeplus_home = os.getenv('KUBEPLUS_HOME', '/')
        cmd = ''
        if platf == "Darwin":
            cmd = kubeplus_home + '/plugins/kubediscovery-macos connections Pod ' + ' ' + pod_name + ' ' + namespace + ' -o json'
        if platf == "Linux":
            cmd = kubeplus_home + '/plugins/kubediscovery-linux connections Pod ' + ' ' + pod_name + ' ' + namespace + ' -o json'

        #print(cmd)
        if cmd:
            output = ''
            try:
                output = subprocess.Popen(cmd,
                                          stdout=subprocess.PIPE,
                                          stderr=subprocess.PIPE,
                                          shell=True).communicate()[0]
                output = output.decode('utf-8')
                output = output.strip("\n")
            except Exception as e:
                print(e)

            if output:
                try:
                    json_output = json.loads(output)
                except Exception as e:
                    print(e)

                pod_list = utils.get_pods(json_output)
        return pod_list
Ejemplo n.º 3
0
    def _get_pods_for_service(self, service_name, namespace):
        pod_list = []
        platf = platform.system()
        kubeplus_home = os.getenv('KUBEPLUS_HOME')
        cmd = ''
        if platf == "Darwin":
            cmd = kubeplus_home + '/plugins/kubediscovery-macos connections Service ' + service_name + ' ' + namespace + ' -o json'
        if platf == "Linux":
            cmd = kubeplus_home + '/plugins/kubediscovery-linux connections Service ' + service_name + ' ' + namespace + ' -o json'

        if cmd:
            output = ''
            try:
                output = subprocess.Popen(cmd,
                                          stdout=subprocess.PIPE,
                                          stderr=subprocess.PIPE,
                                          shell=True).communicate()[0]
                output = output.decode('utf-8')
            except Exception as e:
                print(e)

            if output:
                try:
                    json_output = json.loads(output)
                except Exception as e:
                    print(e)

                pod_list = utils.get_pods(json_output)
                res_list = utils.get_resources(json_output)

            #pod_list = self._parse_pods_from_connections_op(output)
        return pod_list, res_list