def __init__(self, node='compute'): """ :param node: on computer node or network node """ self.node = node self.br_int = Bridge('br-int') self.nss = NameSpaces()
def br_exists(bridge): """ Return True of False of a bridge's existence. """ if isinstance(bridge, str): return Bridge(bridge).exists() else: return False
def br_dump(name): """ Dump the port information of a given bridges. """ flows = Bridge(name).get_flows() debug('br_dump: len flows=%u\n' % len(flows)) if flows: Flow.banner_output() for f in flows: f.fmt_output()
def br_getports(bridge): """ Return a dict of the ports (port, addr, tag, type) on the bridge, looks like { 'qvoxxx':{ 'port':2, 'addr':08:91:ff:ff:f3, 'vlan':1, 'type':internal, } } """ if isinstance(bridge, str): return Bridge(bridge).get_ports() else: return {}
def br_show(name): """ Show information of a given bridges. """ ovs_ports = Bridge(name).get_ports() if not ovs_ports: return neutron_ports = neutron_handler.get_neutron_ports() debug('get neutron_ports\n') content = [] mac_ip_show = False for intf in ovs_ports: # e.g., qvo-xxx, int-br-eth0, qr-xxx, tapxxx port, tag, intf_type = \ ovs_ports[intf]['port'], ovs_ports[intf]['vlan'], ovs_ports[ intf]['type'] if neutron_ports and intf[3:] in neutron_ports: p = neutron_ports[intf[3:]] vm_ips = ','.join( map(lambda x: x.get('ip_address'), p['fixed_ips'])) vm_mac = p.get('mac_address') mac_ip_show = True else: vm_ips, vm_mac = '', '' content.append((intf, port, tag, intf_type, vm_ips, vm_mac)) # output('%-20s%-8s%-16s%-24s%-8s\n' %(intf,port,vmIP,vmMac,tag)) content.sort(key=lambda x: x[1]) # sort by port content.sort(key=lambda x: x[4]) # sort by vm_ip content.sort(key=lambda x: x[3]) # sort by type output( color_str('%-20s%-12s%-8s%-12s' % ('Intf', 'Port', 'Vlan', 'Type'), 'r')) if mac_ip_show: output(color_str('%-16s%-24s\n' % ('vmIP', 'vmMAC'), 'r')) else: output('\n') i = 0 for _ in content: #color = ['w','g'][i%2] color = 'b' output( color_str('%-20s%-12s%-8s%-12s' % (_[0], _[1], _[2], _[3]), color)) if mac_ip_show: output(color_str('%-16s%-24s\n' % (_[4], _[5]), color)) else: output('\n') i += 1
def _check_compute_node_fip_ns(self, rfp_port, ns_fip): """ Check a fip namespace on compute node :param rfp_port: :return: """ q = 'fpr-' + rfp_port['intf'][4:] output(b('### Checking associated fpr port %s\n' % q)) self.nss.show(ns_fip) output(b('### Check related fip_ns=%s\n' % ns_fip)) fpr_port = NameSpace(ns_fip).get_intf_by_name(q) if not fpr_port: warn(r('Cannot find fpr_port in fip ns %s\n' % ns_fip)) return a_ip, a_mask = rfp_port['ip'][0].split('/') b_ip, b_mask = fpr_port['ip'][0].split('/') if networkMask(a_ip, a_mask) != networkMask(b_ip, b_mask): warn( r('Different subnets for %s and %s\n' % (rfp_port['ip'][0], fpr_port['ip'][0]))) return else: output(g('Bridging in the same subnet\n')) fg_port = NameSpace(ns_fip).find_intf('fg-') if not fg_port: warn('Cannot find fg_port in fip ns %s\n' % ns_fip) return if fg_port['intf'] in Bridge('br-ex').get_ports(): output(g('fg port is attached to br-ex\n')) else: warn(g('fg port is NOT attached to br-ex\n')) return for float_ip in rfp_port['ip'][1:]: ip = float_ip.split('/')[0] if ipInNetwork(ip, fg_port['ip'][0]): output(g('floating ip %s match fg subnet\n' % ip)) else: warn(r('floating ip %s No match the fg subnet' % ip))
def br_getflows(bridge): if isinstance(bridge, str): return Bridge(bridge).get_flows() else: return None
def br_delflow(bridge, ids): debug('br_delflow: %s: %s\n' % (bridge, ','.join(ids))) if type(ids) == str and ids.isdigit(): return Bridge(bridge).del_flow([ids]) else: return Bridge(bridge).del_flow(ids)
def br_addflow(bridge, flow): if 'actions=' in flow and len(flow.split()) == 2: return Bridge(bridge).add_flow(flow) else: return False
def br_dump(name): """ Dump the port information of a given bridges. """ Bridge(name).dump_flows()