def xmlrpc_is_ovs_bridge(self, bridge): """ This function verifies whether given interface is an ovs bridge. """ return vswitch.ovs_vsctl_is_ovs_bridge(bridge)
def main(): hostname = Hostname("hostname", help="Usage: hostname [name]", dynamic_args=True) configureswitch = ConfigureSwitch( "configure", help="Usage: configure to access to the switch configuration") vlan = Vlan("vlan", help="Usage: vlan [vlan id]", dynamic_args=True) vlan_name = VlanName("name", help="Usage: name [vlan_name]") show = Show("show", help="Usage: show [interfaces | vlan ]", dynamic_args=True) exit = Exit("exit", help="Usage: exit", dynamic_args=True) history = History("history", help="Usage: history") configure_interface = ConfigureInterface( "interface", help="Usage: interface [interface]", dynamic_args=True) switchport = Switchport( "switchport", help= "switchport [mode|access|trunk]:\n \tmode: switchport mode [access|trunk]\n \taccess: switchport access vlan [access vlan]\n \ttrunk: switchport trunk allowed vlan [allowed vlan's]", dynamic_args=True) ipadmininterface = IPAdminInterface( "ip", help="Usage: ip address [ip] [short|long mask]", dynamic_args=True) saveload = Save_Load( "copy", help= "Usage: Load Config: copy startup-config running-config || Save: copy running-config startup-config", dynamic_args=True) no = No("no", help="Usage: no [vlan] [vlan_id]", dynamic_args=True) ping = Ping("ping", help="Usage: ping [ip address]") shutdown = Shutdown("shutdown", help="Usage: shutdown", dynamic_args=True) see = See("see", help="Show in OpenVSwitch") reload_ = Reload("reload", help="Reset bridge", dynamic_args=True) actualcommand = ActualCommand("?", help="Actual command depends of prompt") common.get_console().addChild(configureswitch) common.get_console().addChild(hostname) common.get_console().addChild(vlan) common.get_console().addChild(vlan_name) common.get_console().addChild(exit) common.get_console().addChild(switchport) common.get_console().addChild(show) common.get_console().addChild(history) common.get_console().addChild(configure_interface) common.get_console().addChild(ipadmininterface) common.get_console().addChild(no) common.get_console().addChild(saveload) common.get_console().addChild(ping) common.get_console().addChild(see) common.get_console().addChild(actualcommand) common.get_console().addChild(shutdown) common.get_console().addChild(reload_) subprocess.call(["/etc/init.d/openvswitch-switch", "start"]) if (vswitch.ovs_vsctl_is_ovs_bridge("br0") == False): vswitch.ovs_vsctl_add_bridge("br0") print(Colors.OKGREEN + "[OK] " + Colors.ENDC + "Bridge Created with name br0") contador = 0 load_or_not = raw_input("Do you have any configuration saved? (y/n): ") if (load_or_not == "y"): common.get_console().walk( "copy startup-config running-config", 0, run=True, full_line="copy startup-config running-config") for i in range(0, common.get_len_interfaces()): vswitch.ovs_vsctl_add_port_to_bridge("br0", common.get_item_interfaces(i)) vswitch.iplink(common.get_item_interfaces(i), "down") contador = contador + 1 print(Colors.OKGREEN + "[OK] " + Colors.ENDC + "Adding " + str(contador) + " interface to bridge br0") common.get_console().loop() print(Colors.OKBLUE + "Bye" + Colors.ENDC)