Exemplo n.º 1
0
    def clear_gateways_except(self, iface):

        def include_interface(name):
            return name != iface and \
                self.netsettings[name].get('addr') and \
                self.netsettings[name].get('netmask')

        return [{'type': "resource",
                 'class': "l23network::l3::ifconfig",
                 'name': name,
                 'params': {'ipaddr': network.addr_in_cidr_notation(
                     self.netsettings[name]['addr'],
                     self.netsettings[name]['netmask'])}}
                for name in self.netsettings if include_interface(name)]
Exemplo n.º 2
0
    def clear_gateways_except(self, iface):
        def include_interface(name):
            return name != iface and \
                self.netsettings[name].get('addr') and \
                self.netsettings[name].get('netmask')

        return [{
            'type': "resource",
            'class': "l23network::l3::ifconfig",
            'name': name,
            'params': {
                'ipaddr':
                network.addr_in_cidr_notation(
                    self.netsettings[name]['addr'],
                    self.netsettings[name]['netmask'])
            }
        } for name in self.netsettings if include_interface(name)]
Exemplo n.º 3
0
    def apply(self, args):
        responses = self.check(args)
        if responses is False:
            self.log.error("Check failed. Not applying")
            self.parent.footer.set_text("Check failed. Not applying.")
            self.log.error("%s" % (responses))
            return False

        self.parent.footer.set_text("Applying changes... (May take up to 20s)")

        # Build puppet resources to apply l23network puppet module to enable
        # network changes
        puppetclasses = []

        # FIXME(mattymo): install_bondtool param does not work (LP#1541028)
        # The following 4 lines should be removed when fixed.
        disable_bond = {
            'type': "literal",
            'name': 'K_mod <| title == "bonding" |> {ensure => absent} '}
        puppetclasses.append(disable_bond)

        # If there is a gateway configured in /etc/sysconfig/network, unset it
        expr = '^GATEWAY=.*'
        replace.replaceInFile("/etc/sysconfig/network", expr, "")

        # Initialize l23network class for NetworkManager fixes
        l23network = {'type': "resource",
                      'class': "class",
                      'name': "l23network",
                      'params': {'install_bondtool': False}}
        puppetclasses.append(l23network)

        # Prepare l23network interface configuration
        l3ifconfig = {'type': "resource",
                      'class': "l23network::l3::ifconfig",
                      'name': self.activeiface}

        additionalclasses = []
        if responses["onboot"].lower() == "no":
            params = {"ipaddr": "none",
                      "gateway": ""}
        elif responses["bootproto"] == "dhcp":
            additionalclasses = self.clear_gateways_except(self.activeiface)
            params = {"ipaddr": "dhcp"}
        else:
            cidr = network.addr_in_cidr_notation(responses["ipaddr"],
                                                 responses["netmask"])
            params = {"ipaddr": cidr,
                      "check_by_ping": "none"}
            if len(responses["gateway"]) > 1:
                params["gateway"] = responses["gateway"]
                additionalclasses = self.clear_gateways_except(
                    self.activeiface)

        puppetclasses.extend(additionalclasses)
        l3ifconfig['params'] = params
        puppetclasses.append(l3ifconfig)
        self.log.info("Puppet data: %s" % (puppetclasses))

        try:
            self.parent.refreshScreen()
            result = puppet.puppetApply(puppetclasses)
            if result is False:
                raise Exception("Puppet apply failed")
            ModuleHelper.getNetwork(self)
            gateway = self.get_default_gateway_linux()
            if gateway is None:
                gateway = ""
            self.fixEtcHosts()
            if responses['bootproto'] == 'dhcp':
                self.parent.dns_might_have_changed = True

        except Exception as e:
            self.log.error(e)
            self.parent.footer.set_text("Error applying changes. Check logs "
                                        "for details.")
            ModuleHelper.getNetwork(self)
            self.setNetworkDetails()
            return False
        self.parent.footer.set_text("Changes successfully applied.")
        ModuleHelper.getNetwork(self)
        self.setNetworkDetails()

        return True
Exemplo n.º 4
0
    def apply(self, args):
        responses = self.check(args)
        if responses is False:
            self.log.error("Check failed. Not applying")
            self.parent.footer.set_text("Check failed. Not applying.")
            self.log.error("%s" % (responses))
            return False

        self.parent.footer.set_text("Applying changes... (May take up to 20s)")

        # Build puppet resources to apply l23network puppet module to enable
        # network changes
        puppetclasses = []

        # FIXME(mattymo): install_bondtool param does not work (LP#1541028)
        # The following 4 lines should be removed when fixed.
        disable_bond = {
            'type': "literal",
            'name': 'K_mod <| title == "bonding" |> {ensure => absent} '
        }
        puppetclasses.append(disable_bond)

        # If there is a gateway configured in /etc/sysconfig/network, unset it
        expr = '^GATEWAY=.*'
        replace.replaceInFile("/etc/sysconfig/network", expr, "")

        # Initialize l23network class for NetworkManager fixes
        l23network = {
            'type': "resource",
            'class': "class",
            'name': "l23network",
            'params': {
                'install_bondtool': False
            }
        }
        puppetclasses.append(l23network)

        # Prepare l23network interface configuration
        l3ifconfig = {
            'type': "resource",
            'class': "l23network::l3::ifconfig",
            'name': self.activeiface
        }

        additionalclasses = []
        if responses["onboot"].lower() == "no":
            params = {"ipaddr": "none", "gateway": ""}
        elif responses["bootproto"] == "dhcp":
            additionalclasses = self.clear_gateways_except(self.activeiface)
            params = {"ipaddr": "dhcp"}
        else:
            cidr = network.addr_in_cidr_notation(responses["ipaddr"],
                                                 responses["netmask"])
            params = {"ipaddr": cidr, "check_by_ping": "none"}
            if len(responses["gateway"]) > 1:
                params["gateway"] = responses["gateway"]
                additionalclasses = self.clear_gateways_except(
                    self.activeiface)

        puppetclasses.extend(additionalclasses)
        l3ifconfig['params'] = params
        puppetclasses.append(l3ifconfig)
        self.log.info("Puppet data: %s" % (puppetclasses))

        try:
            self.parent.refreshScreen()
            result = puppet.puppetApply(puppetclasses)
            if not result:
                raise Exception("Puppet apply failed")
            modulehelper.ModuleHelper.getNetwork(self)
            gateway = self.get_default_gateway_linux()
            if gateway is None:
                gateway = ""
            self.fixEtcHosts()
            if responses['bootproto'] == 'dhcp':
                self.parent.dns_might_have_changed = True

        except Exception as e:
            self.log.error(e)
            self.parent.footer.set_text("Error applying changes. Check logs "
                                        "for details.")
            modulehelper.ModuleHelper.getNetwork(self)
            self.setNetworkDetails()
            return False
        self.parent.footer.set_text("Changes successfully applied.")
        modulehelper.ModuleHelper.getNetwork(self)
        self.setNetworkDetails()

        return True