def test_general(self): self.assertEqual(net.get_all_interfaces(), {'sit0': None, 'lo': '127.0.0.1', 'eth0': '10.100.100.231'}) self.assertEqual(net.get_interface_ip("eth0"), "10.100.100.231") self.assertEqual(net.get_lan_ip(), "10.100.100.231") self.assertEqual(net.reverse_ip("1.2.3.4"), "4.3.2.1") self.assertEqual(net.get_ip_class_c("1.2.3.4"), "1.2.3") self.assertEqual(net.num_of_eth_interfaces(), 1) self.assertEqual(net.get_hostname(), "fo-tp-dalitst")
def test_general(self): self.assertEqual(net.get_all_interfaces(), { 'sit0': None, 'lo': '127.0.0.1', 'eth0': '10.100.100.231' }) self.assertEqual(net.get_interface_ip("eth0"), "10.100.100.231") self.assertEqual(net.get_lan_ip(), "10.100.100.231") self.assertEqual(net.reverse_ip("1.2.3.4"), "4.3.2.1") self.assertEqual(net.get_ip_class_c("1.2.3.4"), "1.2.3") self.assertEqual(net.num_of_eth_interfaces(), 1) self.assertEqual(net.get_hostname(), "fo-tp-dalitst")
def net_setup_bond_br(args): """ Setup bonded network interfaces and bridges. This must work together with a virtual host using KVM. Read more. http://serverfault.com/questions/316623/what-is-the-correct-way-to-setup-a-bonded-bridge-on-centos-6-for-kvm-guests http://www.linuxfoundation.org/collaborate/workgroups/networking/bridge http://www.cyberciti.biz/faq/rhel-linux-kvm-virtualization-bridged-networking-with-libvirt/ http://www.linux-kvm.org/page/HOWTO_BONDING https://fedorahosted.org/cobbler/wiki/VirtNetworkingSetupForUseWithKoan http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization/sect-Virtualization-Network_Configuration-Bridged_networking_with_libvirt.html http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s1-networkscripts-interfaces.html http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sec-Using_Channel_Bonding.html """ app.print_verbose("Install bonded bridges host version: %d" % SCRIPT_VERSION) version_obj = version.Version("NetSetupBondBr", SCRIPT_VERSION) version_obj.check_executed() # app.print_verbose( "Install yum package with all tools that is required to setup bridges." ) install.package("bridge-utils") # print_verbose( "Setup modprobe alias for bonding, don't know exactly why we need to " + "do that. Maybe because the ifcfg files referars to bond0 instead of " + "bonding, or because it loads the module bonding at the same time as " + "the alias is created." ) sycoConf = scOpen("/etc/modprobe.d/syco.conf") sycoConf.remove("alias bond.*") sycoConf.add("alias bond0 bonding") # Get all parameters from syco config. # Check if interfaces are defined, otherwise fall back to autodetecting front_interfaces = config.host(net.get_hostname()).get_front_interfaces() back_interfaces = config.host(net.get_hostname()).get_back_interfaces() num_of_if = len(front_interfaces) + len(back_interfaces) if num_of_if == 0: # Autodetect num_of_if = net.num_of_eth_interfaces() front_ip = config.host(net.get_hostname()).get_front_ip() front_netmask = config.general.get_front_netmask() front_gw = config.general.get_front_gateway_ip() front_resolver = config.general.get_front_resolver_ip() net_count = 1 if config.general.is_back_enabled(): back_ip = config.host(net.get_hostname()).get_back_ip() back_netmask = config.general.get_back_netmask() back_gw = config.general.get_back_gateway_ip() back_resolver = config.general.get_back_resolver_ip() net_count += 1 eth_count = 0; if len(front_interfaces) < 1: # Use default eth interfaces # Also, if you don't specify front net interfaces, you may not specify back net interfaces. if_per_net_count = int(math.floor(num_of_if / net_count)) if net_count > 1: back_interfaces = [] for i in range(if_per_net_count): back_interfaces.append("eth" + str(eth_count)) eth_count += 1 front_interfaces = [] for i in range(if_per_net_count): front_interfaces.append("eth" + str(eth_count)) eth_count += 1 app.print_verbose("Configuring front net bond bond1 with interfaces: {0}".format(front_interfaces)) setup_bridge("br1", front_ip, front_netmask, front_gw, front_resolver) setup_bond("bond1", "br1") for front_interface in front_interfaces: setup_eth(front_interface, "bond1") if net_count == 2: app.print_verbose("Found back-net configuration, configuring second bond bond0 with interfaces: {0}".format(back_interfaces)) setup_bridge("br0", back_ip, back_netmask, back_gw, back_resolver) setup_bond("bond0", "br0") for back_interface in back_interfaces: setup_eth(back_interface, "bond0") # app.print_verbose( "Restart the network service so all changes will be applied." ) x("service network restart") x("echo \"nameserver 8.8.8.8\" > /etc/resolv.conf") # version_obj.mark_executed()
def net_setup_bond_br(args): """ Setup bonded network interfaces and bridges. This must work together with a virtual host using KVM. Read more. http://serverfault.com/questions/316623/what-is-the-correct-way-to-setup-a-bonded-bridge-on-centos-6-for-kvm-guests http://www.linuxfoundation.org/collaborate/workgroups/networking/bridge http://www.cyberciti.biz/faq/rhel-linux-kvm-virtualization-bridged-networking-with-libvirt/ http://www.linux-kvm.org/page/HOWTO_BONDING https://fedorahosted.org/cobbler/wiki/VirtNetworkingSetupForUseWithKoan http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization/sect-Virtualization-Network_Configuration-Bridged_networking_with_libvirt.html http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s1-networkscripts-interfaces.html http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sec-Using_Channel_Bonding.html """ app.print_verbose("Install bonded bridges host version: %d" % SCRIPT_VERSION) version_obj = version.Version("NetSetupBondBr", SCRIPT_VERSION) version_obj.check_executed() # app.print_verbose( "Install yum package with all tools that is required to setup bridges." ) install.package("bridge-utils") # print_verbose( "Setup modprobe alias for bonding, don't know exactly why we need to " + "do that. Maybe because the ifcfg files referars to bond0 instead of " + "bonding, or because it loads the module bonding at the same time as " + "the alias is created." ) sycoConf = scOpen("/etc/modprobe.d/syco.conf") sycoConf.remove("alias bond.*") sycoConf.add("alias bond0 bonding") # Get all parameters from syco config. num_of_if = net.num_of_eth_interfaces() front_ip = config.host(net.get_hostname()).get_front_ip() front_netmask = config.general.get_front_netmask() front_gw = config.general.get_front_gateway_ip() front_resolver = config.general.get_front_resolver_ip() back_ip = config.host(net.get_hostname()).get_back_ip() back_netmask = config.general.get_back_netmask() back_gw = config.general.get_back_gateway_ip() back_resolver = config.general.get_back_resolver_ip() if (num_of_if >= 4): app.print_verbose( "{0} network interfaces was found, and 2 eth interfaces per bond " + "will be configured." ) # Setup back-net setup_bridge("br0", back_ip, back_netmask, back_gw, back_resolver) setup_bond("bond0", "br0") setup_eth("eth0", "bond0") setup_eth("eth1", "bond0") # _setup front-net setup_bridge("br1", front_ip, front_netmask, front_gw, front_resolver) setup_bond("bond1", "br1") setup_eth("eth2", "bond1") setup_eth("eth3", "bond1") elif (num_of_if == 2): app.print_verbose( "2 network interfaces was found, and 1 eth interfaces per bond " + "will be configured. There is no point in bonding in this case, " + "except that we have the same kind of configuration on all hosts. " ) # Setup back-net setup_bridge("br0", back_ip, back_netmask, back_gw, back_resolver) setup_bond("bond0", "br0") setup_eth("eth0", "bond0") # _setup front-net setup_bridge("br1", front_ip, front_netmask, front_gw, front_resolver) setup_bond("bond1", "br1") setup_eth("eth1", "bond1") else: app.print_error("To few network interfaces: " + str(num_of_if)) raise Exception("To few network interfaces: " + str(num_of_if)) # app.print_verbose( "Restart the network service so all changes will be applied." ) x("service network restart") # version_obj.mark_executed()
def _setup_network_interfaces(): """ Setup bonded network interfaces and bridges. Read more. http://serverfault.com/questions/316623/what-is-the-correct-way-to-setup-a-bonded-bridge-on-centos-6-for-kvm-guests http://www.linuxfoundation.org/collaborate/workgroups/networking/bridge http://www.cyberciti.biz/faq/rhel-linux-kvm-virtualization-bridged-networking-with-libvirt/ http://www.linux-kvm.org/page/HOWTO_BONDING https://fedorahosted.org/cobbler/wiki/VirtNetworkingSetupForUseWithKoan http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization/sect-Virtualization-Network_Configuration-Bridged_networking_with_libvirt.html http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s1-networkscripts-interfaces.html http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sec-Using_Channel_Bonding.html """ # Remove the virbr0, "NAT-interface". # http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization/chap-Virtualization-Network_Configuration.html x("virsh net-destroy default") x("virsh net-undefine default") x("service libvirtd restart") # Install network bridge install.package("bridge-utils") general.set_config_property2("/etc/modprobe.d/syco.conf", "alias bond0 bonding") num_of_if = net.num_of_eth_interfaces() front_gw = config.general.get_front_gateway_ip() front_resolver = config.general.get_front_resolver_ip() front_netmask = config.general.get_front_netmask() front_ip = config.host(net.get_hostname()).get_front_ip() back_gw = config.general.get_back_gateway_ip() back_resolver = config.general.get_back_resolver_ip() back_netmask = config.general.get_back_netmask() back_ip = config.host(net.get_hostname()).get_back_ip() if (num_of_if >= 4): # Setup back-net _setup_bridge("br0", back_ip, back_netmask, back_gw, back_resolver) _setup_bond("bond0", "br0") _setup_eth("eth0", "bond0") _setup_eth("eth1", "bond0") # _setup front-net _setup_bridge("br1", front_ip, front_netmask, front_gw, front_resolver) _setup_bond("bond1", "br1") _setup_eth("eth2", "bond1") _setup_eth("eth3", "bond1") elif (num_of_if == 2): # Setup back-net _setup_bridge("br0", back_ip, back_netmask, back_gw, back_resolver) _setup_bond("bond0", "br0") _setup_eth("eth0", "bond0") # _setup front-net _setup_bridge("br1", front_ip, front_netmask, front_gw, front_resolver) _setup_bond("bond1", "br1") _setup_eth("eth1", "bond1") else: app.print_error("To few network interfaces: " + str(num_of_if)) _abort_kvm_host_installation()
def net_setup_bond_br(args): """ Setup bonded network interfaces and bridges. This must work together with a virtual host using KVM. Read more. http://serverfault.com/questions/316623/what-is-the-correct-way-to-setup-a-bonded-bridge-on-centos-6-for-kvm-guests http://www.linuxfoundation.org/collaborate/workgroups/networking/bridge http://www.cyberciti.biz/faq/rhel-linux-kvm-virtualization-bridged-networking-with-libvirt/ http://www.linux-kvm.org/page/HOWTO_BONDING https://fedorahosted.org/cobbler/wiki/VirtNetworkingSetupForUseWithKoan http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization/sect-Virtualization-Network_Configuration-Bridged_networking_with_libvirt.html http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s1-networkscripts-interfaces.html http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sec-Using_Channel_Bonding.html """ app.print_verbose("Install bonded bridges host version: %d" % SCRIPT_VERSION) version_obj = version.Version("NetSetupBondBr", SCRIPT_VERSION) version_obj.check_executed() # app.print_verbose( "Install yum package with all tools that is required to setup bridges." ) install.package("bridge-utils") # print_verbose( "Setup modprobe alias for bonding, don't know exactly why we need to " + "do that. Maybe because the ifcfg files referars to bond0 instead of " + "bonding, or because it loads the module bonding at the same time as " + "the alias is created.") sycoConf = scOpen("/etc/modprobe.d/syco.conf") sycoConf.remove("alias bond.*") sycoConf.add("alias bond0 bonding") # Get all parameters from syco config. # Check if interfaces are defined, otherwise fall back to autodetecting front_interfaces = config.host(net.get_hostname()).get_front_interfaces() back_interfaces = config.host(net.get_hostname()).get_back_interfaces() num_of_if = len(front_interfaces) + len(back_interfaces) if num_of_if == 0: # Autodetect num_of_if = net.num_of_eth_interfaces() front_ip = config.host(net.get_hostname()).get_front_ip() front_netmask = config.general.get_front_netmask() front_gw = config.general.get_front_gateway_ip() front_resolver = config.general.get_front_resolver_ip() net_count = 1 if config.general.is_back_enabled(): back_ip = config.host(net.get_hostname()).get_back_ip() back_netmask = config.general.get_back_netmask() back_gw = config.general.get_back_gateway_ip() back_resolver = config.general.get_back_resolver_ip() net_count += 1 eth_count = 0 if len(front_interfaces) < 1: # Use default eth interfaces # Also, if you don't specify front net interfaces, you may not specify back net interfaces. if_per_net_count = int(math.floor(num_of_if / net_count)) if net_count > 1: back_interfaces = [] for i in range(if_per_net_count): back_interfaces.append("eth" + str(eth_count)) eth_count += 1 front_interfaces = [] for i in range(if_per_net_count): front_interfaces.append("eth" + str(eth_count)) eth_count += 1 app.print_verbose( "Configuring front net bond bond1 with interfaces: {0}".format( front_interfaces)) setup_bridge("br1", front_ip, front_netmask, front_gw, front_resolver) setup_bond("bond1", "br1") for front_interface in front_interfaces: setup_eth(front_interface, "bond1") if net_count == 2: app.print_verbose( "Found back-net configuration, configuring second bond bond0 with interfaces: {0}" .format(back_interfaces)) setup_bridge("br0", back_ip, back_netmask, back_gw, back_resolver) setup_bond("bond0", "br0") for back_interface in back_interfaces: setup_eth(back_interface, "bond0") # app.print_verbose( "Restart the network service so all changes will be applied.") x("service network restart") x("echo \"nameserver 8.8.8.8\" > /etc/resolv.conf") # version_obj.mark_executed()