Example #1
0
 def radioSelectIface(self, current, state, user_data=None):
     """Update network details and display information."""
     # This makes no sense, but urwid returns the previous object.
     # The previous object has True state, which is wrong.
     # Somewhere in current.group a RadioButton is set to True.
     # Our quest is to find it.
     for rb in current.group:
         if rb.get_label() == current.get_label():
             continue
         if rb.base_widget.state is True:
             self.activeiface = rb.base_widget.get_label()
             break
     ModuleHelper.getNetwork(self)
     self.setNetworkDetails()
    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)")
        puppetclasses = []

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

        l3ifconfig = {'type': "resource",
                      'class': "l23network::l3::ifconfig",
                      'name': self.activeiface}
        if responses["onboot"].lower() == "no":
            params = {"ipaddr": "none",
                      "gateway": ""}
        elif responses["bootproto"] == "dhcp":
            self.unset_gateway()
            if "dhcp_nowait" in responses.keys():
                params = {"ipaddr": "dhcp",
                          "dhcp_nowait": responses["dhcp_nowait"]}
            else:
                params = {"ipaddr": "dhcp"}
        else:
            cidr = network.netmaskToCidr(responses["netmask"])
            params = {"ipaddr": "{0}/{1}".format(responses["ipaddr"], cidr),
                      "check_by_ping": "none"}
            if len(responses["gateway"]) > 1:
                params["gateway"] = responses["gateway"]
                self.unset_gateway()
        l3ifconfig['params'] = params
        puppetclasses.append(l3ifconfig)
        self.log.info("Puppet data: %s" % (puppetclasses))
        try:
            self.parent.refreshScreen()
            puppet.puppetApply(puppetclasses)
            ModuleHelper.getNetwork(self)
            gateway = self.get_default_gateway_linux()
            if gateway is None:
                gateway = ""
            self.fixEtcHosts()

        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
 def getNetwork(self):
     ModuleHelper.getNetwork(self)
Example #4
0
 def refresh(self):
     ModuleHelper.getNetwork(self)
     self.setNetworkDetails()
Example #5
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
Example #6
0
 def getNetwork(self):
     ModuleHelper.getNetwork(self)
Example #7
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)")
        puppetclasses = []

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

        l3ifconfig = {
            'type': "resource",
            'class': "l23network::l3::ifconfig",
            'name': self.activeiface
        }
        if responses["onboot"].lower() == "no":
            params = {"ipaddr": "none"}
        elif responses["bootproto"] == "dhcp":
            self.unset_gateway()
            if "dhcp_nowait" in responses.keys():
                params = {
                    "ipaddr": "dhcp",
                    "dhcp_nowait": responses["dhcp_nowait"]
                }
            else:
                params = {"ipaddr": "dhcp"}
        else:
            cidr = network.netmaskToCidr(responses["netmask"])
            params = {
                "ipaddr": "{0}/{1}".format(responses["ipaddr"], cidr),
                "check_by_ping": "none"
            }
        if len(responses["gateway"]) > 1:
            params["gateway"] = responses["gateway"]
            self.unset_gateway()
        l3ifconfig['params'] = params
        puppetclasses.append(l3ifconfig)
        self.log.info("Puppet data: %s" % (puppetclasses))
        try:
            self.parent.refreshScreen()
            puppet.puppetApply(puppetclasses)
            ModuleHelper.getNetwork(self)
            gateway = self.get_default_gateway_linux()
            if gateway is None:
                gateway = ""
            self.fixEtcHosts()

        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
Example #8
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)")
        puppetclasses = []
        l3ifconfig = {'type': "resource",
                      'class': "l23network::l3::ifconfig",
                      'name': self.activeiface}
        if responses["onboot"].lower() == "no":
            params = {"ipaddr": "none"}
        elif responses["bootproto"] == "dhcp":
            if "dhcp_nowait" in responses.keys():
                params = {"ipaddr": "dhcp",
                          "dhcp_nowait": responses["dhcp_nowait"]}
            else:
                params = {"ipaddr": "dhcp"}
        else:
            params = {"ipaddr": responses["ipaddr"],
                      "netmask": responses["netmask"],
                      "check_by_ping": "none"}
        if len(responses["gateway"]) > 1:
            params["gateway"] = responses["gateway"]
            params["default_gateway"] = True
        elif network.inSameSubnet(self.get_default_gateway_linux(),
                                  responses["ipaddr"], responses["netmask"]):
            #If the current gateway is in the same subnet AND the user
            #sets the gateway to empty, unset gateway
            expr = '^GATEWAY=.*'
            replace.replaceInFile("/etc/sysconfig/network", expr,
                                  "GATEWAY=")
        l3ifconfig['params'] = params
        puppetclasses.append(l3ifconfig)
        self.log.info("Puppet data: %s" % (puppetclasses))
        try:
            #Gateway handling so DHCP will set gateway
            if responses["bootproto"] == "dhcp":
                expr = '^GATEWAY=.*'
                replace.replaceInFile("/etc/sysconfig/network", expr,
                                      "GATEWAY=")
            self.parent.refreshScreen()
            puppet.puppetApply(puppetclasses)
            ModuleHelper.getNetwork(self)
            expr = '^GATEWAY=.*'
            gateway = self.get_default_gateway_linux()
            if gateway is None:
                gateway = ""
            replace.replaceInFile("/etc/sysconfig/network", expr, "GATEWAY=%s"
                                  % gateway)
            self.fixEtcHosts()

        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
Example #9
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)")
        puppetclasses = []
        l3ifconfig = {
            'type': "resource",
            'class': "l23network::l3::ifconfig",
            'name': self.activeiface
        }
        if responses["onboot"].lower() == "no":
            params = {"ipaddr": "none"}
        elif responses["bootproto"] == "dhcp":
            if "dhcp_nowait" in responses.keys():
                params = {
                    "ipaddr": "dhcp",
                    "dhcp_nowait": responses["dhcp_nowait"]
                }
            else:
                params = {"ipaddr": "dhcp"}
        else:
            params = {
                "ipaddr": responses["ipaddr"],
                "netmask": responses["netmask"],
                "check_by_ping": "none"
            }
        if len(responses["gateway"]) > 1:
            params["gateway"] = responses["gateway"]
            params["default_gateway"] = True
        elif network.inSameSubnet(self.get_default_gateway_linux(),
                                  responses["ipaddr"], responses["netmask"]):
            #If the current gateway is in the same subnet AND the user
            #sets the gateway to empty, unset gateway
            expr = '^GATEWAY=.*'
            replace.replaceInFile("/etc/sysconfig/network", expr, "GATEWAY=")
        l3ifconfig['params'] = params
        puppetclasses.append(l3ifconfig)
        self.log.info("Puppet data: %s" % (puppetclasses))
        try:
            #Gateway handling so DHCP will set gateway
            if responses["bootproto"] == "dhcp":
                expr = '^GATEWAY=.*'
                replace.replaceInFile("/etc/sysconfig/network", expr,
                                      "GATEWAY=")
            self.parent.refreshScreen()
            puppet.puppetApply(puppetclasses)
            ModuleHelper.getNetwork(self)
            expr = '^GATEWAY=.*'
            gateway = self.get_default_gateway_linux()
            if gateway is None:
                gateway = ""
            replace.replaceInFile("/etc/sysconfig/network", expr,
                                  "GATEWAY=%s" % gateway)
            self.fixEtcHosts()

        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
Example #10
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