コード例 #1
0
ファイル: genericdirector.py プロジェクト: khosrow/lvsm
    def show_virtual(self, host, port, proto, numeric, color):
        """Show status of virtual server.
        """

        logger.debug("GenericDirector:show_virtual Parameters: Host %s Port %s Proto %s" % (host, port, proto))

        # if the protocol is FWM, don't convert the "host" IP
        if proto.upper() == "FWM":
            hostips = ['1']
        else:
            # make sure we have a valid host
            hostips = utils.gethostbyname_ex(host)
            if not hostips:
                logger.debug("GenericDirector:show_virtual invalid host IP")
                return list()

        # make sure the port is valid
        if port:
            portnum = utils.getportnum(port)
            if portnum == -1:
                logger.debug("GenericDirector:show_virtual invalid port number")
                return list()

        # Update the ipvs table
        self.build_ipvs()

        result = ["", "Layer 4 Load balancing"]
        result += ["======================"]
        for v in self.virtuals:
            if v.proto == proto.upper() and v.ip in hostips:
                if not port or v.port == str(portnum):
                    result += v.__str__(numeric, color).split('\n')

        return result
コード例 #2
0
ファイル: genericdirector.py プロジェクト: coreyxiang/lvsm
    def show_virtual(self, host, port, proto, numeric, color):
        """Show status of virtual server.
        """
        # make sure we have a valid host
        hostips = utils.gethostbyname_ex(host)
        if not hostips:
            return list()

        # make sure the port is valid
        if port:
            portnum = utils.getportnum(port)
            if portnum == -1:
                return list()

        # Update the ipvs table
        self.build_ipvs()

        result = ["", "Layer 4 Load balancing"]
        result += ["======================"]
        for v in self.virtuals:
            if v.proto == proto.upper() and v.ip in hostips:
                if not port or v.port == str(portnum):
                    result += v.__str__(numeric, color).split('\n')

        return result
コード例 #3
0
ファイル: genericdirector.py プロジェクト: wujcheng/lvsm
    def show_virtual(self, host, port, proto, numeric, color):
        """Show status of virtual server.
        """
        # make sure we have a valid host
        hostips = utils.gethostbyname_ex(host)
        if not hostips:
            return list()

        # make sure the port is valid
        if port:
            portnum = utils.getportnum(port)
            if portnum == -1:
                return list()

        # Update the ipvs table
        self.build_ipvs()

        result = ["", "Layer 4 Load balancing"]
        result += ["======================"]
        for v in self.virtuals:
            if v.proto == proto.upper() and v.ip in hostips:
                if not port or v.port == str(portnum):
                    result += v.__str__(numeric, color).split('\n')

        return result
コード例 #4
0
ファイル: genericdirector.py プロジェクト: khosrow/lvsm
 def convert_filename(self, filename):
     """
     Convert a filename of format host[:port] to IP[:port]
     Assumption is that for hosts with more than one IP,
     the first IP in the list is used.
     """
     values = filename.split(':')
     portnum = -1
     if not values:
         return ''
     hostips = utils.gethostbyname_ex(values[0])
     if len(values) == 2:
         portnum = utils.getportnum(values[1])
     if portnum > -1:
         return hostips[0] + ':' + str(portnum)
     else:
         return hostips[0]
コード例 #5
0
ファイル: genericdirector.py プロジェクト: khosrow/lvsm
 def convert_filename(self, filename):
     """
     Convert a filename of format host[:port] to IP[:port]
     Assumption is that for hosts with more than one IP,
     the first IP in the list is used.
     """
     values = filename.split(':')
     portnum = -1
     if not values:
         return ''
     hostips = utils.gethostbyname_ex(values[0])
     if len(values) == 2:
         portnum = utils.getportnum(values[1])
     if portnum > -1:
         return hostips[0] + ':' + str(portnum)
     else:
         return hostips[0]
コード例 #6
0
ファイル: genericdirector.py プロジェクト: khosrow/lvsm
    def show_virtual(self, host, port, proto, numeric, color):
        """Show status of virtual server.
        """

        logger.debug(
            "GenericDirector:show_virtual Parameters: Host %s Port %s Proto %s"
            % (host, port, proto))

        # if the protocol is FWM, don't convert the "host" IP
        if proto.upper() == "FWM":
            hostips = ['1']
        else:
            # make sure we have a valid host
            hostips = utils.gethostbyname_ex(host)
            if not hostips:
                logger.debug("GenericDirector:show_virtual invalid host IP")
                return list()

        # make sure the port is valid
        if port:
            portnum = utils.getportnum(port)
            if portnum == -1:
                logger.debug(
                    "GenericDirector:show_virtual invalid port number")
                return list()

        # Update the ipvs table
        self.build_ipvs()

        result = ["", "Layer 4 Load balancing"]
        result += ["======================"]
        for v in self.virtuals:
            if v.proto == proto.upper() and v.ip in hostips:
                if not port or v.port == str(portnum):
                    result += v.__str__(numeric, color).split('\n')

        return result
コード例 #7
0
ファイル: genericdirector.py プロジェクト: khosrow/lvsm
    def show_real_active(self, host, port, numeric, color):
        """Show status of an active real server across multiple VIPs.
        """
        # make sure we have a valid host
        hostips = utils.gethostbyname_ex(host)

        if not hostips:
            return list()

        # If more than one ip is returned for a host. Use the first one
        hostip = hostips[0]
        # If port is defined verify that it's a valid number
        if port:
            portnum = utils.getportnum(port)
            if portnum == -1:
                return list()
        else:
            portnum = None

        # Update the ipvs table
        self.build_ipvs()

        result = list()

        for v in self.virtuals:
            # for real in v.realServers:
            # if real.ip == hostip:
            #     logger.debug("real port type: %s" % type(real.port))
            #     logger.debug("port num type: %s" % type(portnum))
            #     if not port or real.port == portnum:
            #         result += v.__str__(numeric, color, real.ip, port).split('\n')
            # result += v.__str__(numeric, color, hostip, portnum).split('\n')
            r = v.__str__(numeric, color, hostip, portnum)
            if r:
                result += r.split('\n')
        return result
コード例 #8
0
ファイル: genericdirector.py プロジェクト: khosrow/lvsm
    def show_real_active(self, host, port, numeric, color):
        """Show status of an active real server across multiple VIPs.
        """
        # make sure we have a valid host
        hostips = utils.gethostbyname_ex(host)

        if not hostips:
            return list()

        # If more than one ip is returned for a host. Use the first one
        hostip = hostips[0]
        # If port is defined verify that it's a valid number
        if port:
            portnum = utils.getportnum(port)
            if portnum == -1:
                return list()
        else:
            portnum = None

        # Update the ipvs table
        self.build_ipvs()

        result = list()

        for v in self.virtuals:
            # for real in v.realServers:
                # if real.ip == hostip:
                #     logger.debug("real port type: %s" % type(real.port))
                #     logger.debug("port num type: %s" % type(portnum))
                #     if not port or real.port == portnum:
                #         result += v.__str__(numeric, color, real.ip, port).split('\n')
            # result += v.__str__(numeric, color, hostip, portnum).split('\n')
            r = v.__str__(numeric, color, hostip, portnum)
            if r:
                result += r.split('\n')
        return result
コード例 #9
0
    def show_virtual(self, host, port, protocol, numeric, color):
        result = list()
        args = [self.iptables, '-L', 'INPUT']
        if port:
            portnum = utils.getportnum(port)
            try:
                portname = socket.getservbyport(int(portnum))
            except socket.error:
                portname = portnum
            except OverflowError as e:
                logger.error("%s" % e)
                return list()

        if numeric:
            args.append('-n')
            hostnames = utils.gethostbyname_ex(host)
        else:
            # Turn this into a list so it behaves like the above case
            # And we only perform a list membership check
            hostnames = [socket.getfqdn(host)]

        # Nested try/except needed to catch exceptions in the "Except"
        try:
            try:
                logger.info("Running: %s" % " ".join(args))
                output = subprocess.check_output(args)
            # python 2.6 compatibility code
            except AttributeError as e:
                output, stderr = subprocess.Popen(
                    args, stdout=subprocess.PIPE).communicate()
        except OSError as e:
            logger.error("Problem with iptables - %s : %s" %
                         (e.strerror, args[0]))
            return list()
        if output:
            lines = output.split('\n')
            for line in lines:
                # break the iptables output into tokens
                # assumptions:
                # 2nd item is the protocol - tokens[1]
                # 5th item is the hostname - tokens[4]
                # 7th item is the portname - tokens[6]
                tokens = line.split()

                if len(tokens) >= 7:
                    if ((tokens[1] == protocol or tokens[2] == "all")
                            and tokens[4] in hostnames and
                        (not port or (tokens[6] == "dpt:" + str(portname)
                                      or tokens[6] == "dpt:" + str(portnum)))):
                        if color:
                            if line.startswith('ACCEPT'):
                                result.append(termcolor.colored(line, 'green'))
                            elif (line.startswith('REJECT')
                                  or line.startswith('DROP')):
                                result.append(termcolor.colored(line, 'red'))
                            else:
                                result.append(line)
                        else:
                            result.append(line)
            # If we have any output, let's also display some headers
            if result:
                result.insert(0, '')
                result.insert(1, 'IP Packet filter rules')
                result.insert(2, '======================')

        return result
コード例 #10
0
ファイル: firewall.py プロジェクト: coreyxiang/lvsm
    def show_virtual(self, host, port, protocol, numeric, color):
        result = list()
        args = [self.iptables, '-L', 'INPUT']
        if port:
            portnum = utils.getportnum(port)
            try:
                portname = socket.getservbyport(int(portnum))
            except socket.error:
                portname = portnum
            except OverflowError as e:
                logger.error("%s" % e)
                return list() 

        if numeric:
            args.append('-n')
            hostnames = utils.gethostbyname_ex(host)
        else:
            # Turn this into a list so it behaves like the above case
            # And we only perform a list membership check
            hostnames = [socket.getfqdn(host)]

        # Nested try/except needed to catch exceptions in the "Except"    
        try:
            try:
                logger.info("Running: %s" % " ".join(args))
                output = subprocess.check_output(args)
            # python 2.6 compatibility code
            except AttributeError as e:
                output, stderr = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()
        except OSError as e:
            logger.error("Problem with iptables - %s : %s" % (e.strerror, args[0]))
            return list()
        if output:
            lines = output.split('\n')
            for line in lines:
                # break the iptables output into tokens
                # assumptions:
                # 2nd item is the protocol - tokens[1]
                # 5th item is the hostname - tokens[4]
                # 7th item is the portname - tokens[6]
                tokens = line.split()

                if len(tokens) >= 7:
                    if ((tokens[1] == protocol or tokens[2] == "all") and
                        tokens[4] in hostnames and
                        ( not port or (tokens[6] == "dpt:" + str(portname) or tokens[6] == "dpt:" + str(portnum)))
                        ):
                        if color:
                            if line.startswith('ACCEPT'):
                                result.append(termcolor.colored(line, 'green'))
                            elif (line.startswith('REJECT') or
                                  line.startswith('DROP')):
                                result.append(termcolor.colored(line, 'red'))
                            else:
                                result.append(line)
                        else:
                            result.append(line)
            # If we have any output, let's also display some headers
            if result:
                result.insert(0, '')
                result.insert(1, 'IP Packet filter rules')
                result.insert(2, '======================')
                
        return result