Beispiel #1
0
    def generate_stats(self):

        state = self._port_obj.get_port_state_name() if self._port_obj else "" 
        if state == "ACTIVE":
            state = format_text(state, 'green', 'bold')
        elif state == "PAUSE":
            state = format_text(state, 'magenta', 'bold')
        else:
            state = format_text(state, 'bold')


        return {"owner": self._port_obj.user if self._port_obj else "",
                "state": "{0}".format(state),

                "--": " ",
                "---": " ",
                "----": " ",
                "-----": " ",

                "Tx bps L1": u"{0} {1}".format(self.get_trend_gui("m_total_tx_bps_L1", show_value = False),
                                               self.get("m_total_tx_bps_L1", format = True, suffix = "bps")),

                "Tx bps L2": u"{0} {1}".format(self.get_trend_gui("m_total_tx_bps", show_value = False),
                                               self.get("m_total_tx_bps", format = True, suffix = "bps")),

                "Line Util.": u"{0} {1}".format(self.get_trend_gui("m_percentage", show_value = False),
                                                format_text(
                                                    self.get("m_percentage", format = True, suffix = "%") if self._port_obj else "",
                                                    'bold')),

                "Rx bps": u"{0} {1}".format(self.get_trend_gui("m_total_rx_bps", show_value = False),
                                            self.get("m_total_rx_bps", format = True, suffix = "bps")),
                  
                "Tx pps": u"{0} {1}".format(self.get_trend_gui("m_total_tx_pps", show_value = False),
                                            self.get("m_total_tx_pps", format = True, suffix = "pps")),

                "Rx pps": u"{0} {1}".format(self.get_trend_gui("m_total_rx_pps", show_value = False),
                                            self.get("m_total_rx_pps", format = True, suffix = "pps")),

                 "opackets" : self.get_rel("opackets"),
                 "ipackets" : self.get_rel("ipackets"),
                 "obytes"   : self.get_rel("obytes"),
                 "ibytes"   : self.get_rel("ibytes"),

                 "tx-bytes": self.get_rel("obytes", format = True, suffix = "B"),
                 "rx-bytes": self.get_rel("ibytes", format = True, suffix = "B"),
                 "tx-pkts": self.get_rel("opackets", format = True, suffix = "pkts"),
                 "rx-pkts": self.get_rel("ipackets", format = True, suffix = "pkts"),

                 "oerrors"  : format_num(self.get_rel("oerrors"),
                                         compact = False,
                                         opts = 'green' if (self.get_rel("oerrors")== 0) else 'red'),

                 "ierrors"  : format_num(self.get_rel("ierrors"),
                                         compact = False,
                                         opts = 'green' if (self.get_rel("ierrors")== 0) else 'red'),

                }
Beispiel #2
0
    def generate_stats(self):

        state = self._port_obj.get_port_state_name() if self._port_obj else "" 
        if state == "ACTIVE":
            state = format_text(state, 'green', 'bold')
        elif state == "PAUSE":
            state = format_text(state, 'magenta', 'bold')
        else:
            state = format_text(state, 'bold')


        return {"owner": self._port_obj.user if self._port_obj else "",
                "state": "{0}".format(state),

                "--": " ",
                "---": " ",
                "----": " ",
                "-----": " ",

                "Tx bps L1": u"{0} {1}".format(self.get_trend_gui("m_total_tx_bps_L1", show_value = False),
                                               self.get("m_total_tx_bps_L1", format = True, suffix = "bps")),

                "Tx bps L2": u"{0} {1}".format(self.get_trend_gui("m_total_tx_bps", show_value = False),
                                               self.get("m_total_tx_bps", format = True, suffix = "bps")),

                "Line Util.": u"{0} {1}".format(self.get_trend_gui("m_percentage", show_value = False),
                                                format_text(
                                                    self.get("m_percentage", format = True, suffix = "%") if self._port_obj else "",
                                                    'bold')),

                "Rx bps": u"{0} {1}".format(self.get_trend_gui("m_total_rx_bps", show_value = False),
                                            self.get("m_total_rx_bps", format = True, suffix = "bps")),
                  
                "Tx pps": u"{0} {1}".format(self.get_trend_gui("m_total_tx_pps", show_value = False),
                                            self.get("m_total_tx_pps", format = True, suffix = "pps")),

                "Rx pps": u"{0} {1}".format(self.get_trend_gui("m_total_rx_pps", show_value = False),
                                            self.get("m_total_rx_pps", format = True, suffix = "pps")),

                 "opackets" : self.get_rel("opackets"),
                 "ipackets" : self.get_rel("ipackets"),
                 "obytes"   : self.get_rel("obytes"),
                 "ibytes"   : self.get_rel("ibytes"),

                 "tx-bytes": self.get_rel("obytes", format = True, suffix = "B"),
                 "rx-bytes": self.get_rel("ibytes", format = True, suffix = "B"),
                 "tx-pkts": self.get_rel("opackets", format = True, suffix = "pkts"),
                 "rx-pkts": self.get_rel("ipackets", format = True, suffix = "pkts"),

                 "oerrors"  : format_num(self.get_rel("oerrors"),
                                         compact = False,
                                         opts = 'green' if (self.get_rel("oerrors")== 0) else 'red'),

                 "ierrors"  : format_num(self.get_rel("ierrors"),
                                         compact = False,
                                         opts = 'green' if (self.get_rel("ierrors")== 0) else 'red'),

                }
Beispiel #3
0
 def __get_relevant_ports(self, port_id_list):
     # fetch owned ports
     ports = [port_obj
              for _, port_obj in self._ports_dict.iteritems()
              if port_obj.port_id in port_id_list]
     
     # display only the first FOUR options, by design
     if len(ports) > 4:
         print format_text("[WARNING]: ", 'magenta', 'bold'), format_text("displaying up to 4 ports", 'magenta')
         ports = ports[:4]
     return ports
Beispiel #4
0
 def __get_relevant_ports(self, port_id_list):
     # fetch owned ports
     ports = [port_obj
              for _, port_obj in self._ports_dict.iteritems()
              if port_obj.port_id in port_id_list]
     
     # display only the first FOUR options, by design
     if len(ports) > 4:
         print format_text("[WARNING]: ", 'magenta', 'bold'), format_text("displaying up to 4 ports", 'magenta')
         ports = ports[:4]
     return ports
Beispiel #5
0
    def get_trend_gui (self, field, show_value = False, use_raw = False, up_color = 'red', down_color = 'green'):
        v = self.get_trend(field, use_raw)

        value = abs(v)
        arrow = u'\u25b2' if v > 0 else u'\u25bc'
        color = up_color if v > 0 else down_color

        # change in 1% is not meaningful
        if value < 1:
            return ""

        elif value > 5:

            if show_value:
                return format_text(u"{0}{0}{0} {1:.2f}%".format(arrow,v), color)
            else:
                return format_text(u"{0}{0}{0}".format(arrow), color)

        elif value > 2:

            if show_value:
                return format_text(u"{0}{0} {1:.2f}%".format(arrow,v), color)
            else:
                return format_text(u"{0}{0}".format(arrow), color)

        else:
            if show_value:
                return format_text(u"{0} {1:.2f}%".format(arrow,v), color)
            else:
                return format_text(u"{0}".format(arrow), color)
Beispiel #6
0
    def get_trend_gui (self, field, show_value = False, use_raw = False, up_color = 'red', down_color = 'green'):
        v = self.get_trend(field, use_raw)

        value = abs(v)
        arrow = u'\u25b2' if v > 0 else u'\u25bc'
        color = up_color if v > 0 else down_color

        # change in 1% is not meaningful
        if value < 1:
            return ""

        elif value > 5:

            if show_value:
                return format_text(u"{0}{0}{0} {1:.2f}%".format(arrow,v), color)
            else:
                return format_text(u"{0}{0}{0}".format(arrow), color)

        elif value > 2:

            if show_value:
                return format_text(u"{0}{0} {1:.2f}%".format(arrow,v), color)
            else:
                return format_text(u"{0}{0}".format(arrow), color)

        else:
            if show_value:
                return format_text(u"{0} {1:.2f}%".format(arrow,v), color)
            else:
                return format_text(u"{0}".format(arrow), color)