Beispiel #1
0
 def get_ports(self):
     """
     Return a dict of the ports (port, addr, tag, type) on the bridge, like
     {
         'qvoxxx':{
             'port':'2',
             'addr':'08:91:ff:ff:f3',
             'vlan':'1',
             'type':'internal',
         }
     }
     """
     ports = {}
     cmd = "ovs-ofctl show %s" % self.bridge
     result, error = \
         Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True).communicate()
     if error:
         return {}
     #output('%-8s%-16s%-16s\n' %('PORT','INTF','ADDR'))
     brs = get_all_bridges()
     for l in result.split('\n'):
         if l.startswith(' ') and l.find('(') >= 0 and l.find(')') >= 0:
             l = l.strip()
             port = get_str_before(l, '(')
             intf = get_str_between(l, '(', ')')
             addr = l[l.find('addr:') + len('addr:'):]
             #output('%-8s%-16s%-16s\n' %(port,intf,addr))
             if self.bridge in brs and intf in brs[self.bridge]['Port']:
                 tag = brs[self.bridge]['Port'][intf].get('vlan', '')
                 intf_type = brs[self.bridge]['Port'][intf].get('type', '')
             else:
                 tag, intf_type = '', ''
             ports[intf] = {'port': port, 'addr': addr, 'vlan': tag,
                            'type': intf_type}
     return ports
Beispiel #2
0
def find_br_ports(port_id):
    """
    Find a port with given id
    :param port_id: a4111776-bd

    :return: qr-a4111776-bd
    """
    brs = ovs_lib.get_all_bridges()
    for br_id in brs:
        if 'Port'in brs[br_id]:
            for p in brs[br_id]['Port']:
                if p.endswith(port_id):
                    return p
    return None
Beispiel #3
0
def br_list():
    """
    List available bridges.
    """
    bridges = ovs_lib.get_all_bridges()
    if not bridges:
        output('None bridge exists. Might try using root privilege?\n')
        return
    br_info = ''
    for br in sorted(bridges.keys()):
        br_info += "%s\n" % br
        if bridges[br]['Port']:
            br_info += " Port:\t\t%s\n" \
                       % (' '.join(sorted(bridges[br]['Port'].keys())))
        if bridges[br]['Controller']:
            br_info += " Controller:\t%s\n" \
                       % (' '.join(bridges[br]['Controller']))
        if bridges[br]['fail_mode']:
            br_info += " Fail_Mode:\t%s\n" % (bridges[br]['fail_mode'])
    output(br_info)