Exemplo n.º 1
0
 def vm(self, ip):
     '''
     list vm related rules
     :param ip: vm ip
     :return:
     '''
     debug("Try to show vm rules, ip=%s\n" % ip)
     port_id = get_port_id_from_ip(ip)
     debug('The port id is %s\n' % port_id)
     if not port_id:
         warn('No port id is found for ip=%s\n' % ip)
         return
     br_port = find_br_ports(port_id)
     if not br_port:
         warn('No br port is found for ip=%s\n' % ip)
         return
     output(r('## IP = %s, port = %s\n' % (ip, br_port)))
     rules_dic = self._query_port_rules(br_port)
     if rules_dic:
         output(b( _format_str_iptables_rule_ % (
             'PKTS', 'IN', 'SOURCE', 'OUT', 'DESTINATION', 'PROT',
             'TARGET', 'OTHER')))
         for rule in rules_dic:
             output(b('%s:\n' % rule))
             self._fmt_show_rules(rules_dic[rule])
Exemplo n.º 2
0
 def vm(self, ip):
     '''
     list vm related rules
     :param ip: vm ip
     :return:
     '''
     debug("Try to show vm rules, ip=%s\n" % ip)
     port_id = get_port_id_from_ip(ip)
     debug('The port id is %s\n' % port_id)
     if not port_id:
         warn('No port id is found for ip=%s\n' % ip)
         return
     br_port = find_br_ports(port_id)
     if not br_port:
         warn('No br port is found for ip=%s\n' % ip)
         return
     output(r('## IP = %s, port = %s\n' % (ip, br_port)))
     rules_dic = self._query_port_rules(br_port)
     if rules_dic:
         output(
             b(_format_str_iptables_rule_ %
               ('PKTS', 'IN', 'SOURCE', 'OUT', 'DESTINATION', 'PROT',
                'TARGET', 'OTHER')))
         for rule in rules_dic:
             output(b('%s:\n' % rule))
             self._fmt_show_rules(rules_dic[rule])
Exemplo n.º 3
0
 def vm(self, ip):
     """
     list vm related rules
     :param ip: vm ip
     :return:
     """
     debug("Try to show vm rules, ip=%s\n" % ip)
     port_id = get_port_id_from_ip(ip)
     debug('The port id is %s\n' % port_id)
     if not port_id:
         warn('No port id is found for ip=%s\n' % ip)
         return
     output(color_str('## IP = %s, port = %s\n' % (ip, port_id), 'r'))
     br_port = find_br_ports(port_id)
     if not br_port:
         warn('No br port is found for ip=%s\n' % ip)
         return
     debug('The br port is %s\n' % br_port)
     rules_dic = self._query_port_rules(br_port)
     if rules_dic:
         output(color_str( _format_str_iptables_rule_ % (
             'PKTS', 'SOURCE', 'DESTINATION', 'PROT', 'OTHER'), 'b'))
         for r in rules_dic:
             if rules_dic[r]:
                 output('%s:\n' % r)
                 self._fmt_show_rules(rules_dic[r])
Exemplo n.º 4
0
def show_iptables_rules(ips):
    """
    Show the iptables rules of given vm ips.
    """
    for ip in ips.replace(',', ' ').split():
        port_id = get_port_id_from_ip(ip)
        if not port_id:
            output('No local addr %s exists.\n' % ip)
            continue
        output(color_str('r', '## IP = %s, port = %s\n' % (ip, port_id)))
        rules_dic = get_iptables_rules(port_id)
        if rules_dic:
            output(color_str('b', _format_str_iptables_rule_ % ('PKTS',
                                                                'SOURCE',
                                                                'DESTINATION', 'PROT', 'OTHER')))
            for r in rules_dic:
                if rules_dic[r]:
                    output('%s:\n' % r)
                    fmt_show_rules(rules_dic[r])