Exemple #1
0
    def onPreInstall(self, data):
        """
        Handles the pre install event
        @type  data: dict
        @param data: relevant arguments for that given event
        @rtype: None
        @returns: Nothing
        """
        try:
            self.__logger.info("Executing NetworkTopology module (EVT_PRE_INSTALL).")
            # NIC status
            interfaces = Network.getAvailableInterfaces(False)
            activeLinkInterfaces = Network.getLinkedInterfaces(False)
            activeInterfaces = Network.getActiveInterfaces(False)
            udevInterfaces = Network.getAvailableInterfaces()
            udevActiveLinkInterfaces = Network.getLinkedInterfaces()
            udevActiveInterfaces = Network.getActiveInterfaces()
            self.__logger.debug("Network interfaces:")
            for line in pprint.pformat(interfaces).split('\n'):
                self.__logger.debug(line)
            self.__logger.debug("Network interfaces with link:")
            self.__logger.debug("%s" % activeLinkInterfaces)
            self.__logger.debug("Network interfaces with network configured:")
            self.__logger.debug("%s" % activeInterfaces)
            self.__logger.debug("Network interfaces (UDEV):")
            for line in pprint.pformat(udevInterfaces).split('\n'):
                self.__logger.debug(line)
            self.__logger.debug("Network interfaces with link (UDEV):")
            self.__logger.debug("%s" % udevActiveLinkInterfaces)
            self.__logger.debug("Network interfaces with network configured (UDEV):")
            self.__logger.debug("%s" % udevActiveInterfaces)

            # Configure network interfaces and bridges
            devDict = udevInterfaces
            devActiveList = udevActiveInterfaces
            if devDict:
                self.__fixDracutIfcfgFiles(devDict)
                for dev, mac in devDict.iteritems():
                    ifcfgFile = "/etc/sysconfig/network-scripts/ifcfg-%s" % dev
                    if not os.path.isfile(ifcfgFile):
                        self.__setEthConfigFile(dev, mac, devActiveList)
                        self.__logger.debug("Writing on ISO image ifcfg file:")
                        self.__logger.debug("%s" % ifcfgFile)
                        for line in pprint.pformat(self.__configFile).split('\n'):
                            self.__logger.debug(line)
                        Network.writeConfigFile(self.__configFile)
            else:
                self.__logger.debug("No NIC available!")
        except Exception as e:
            self.__logger.critical("Failed NetworkTopology module")
            self.__logger.critical("EXCEPTION:" + str(type(e)))
            self.__logger.critical(str(e))
            self.__logger.critical("Stacktrace:" + str(traceback.format_exc()))
            raise PKVMError("PREINSTALL", "NETWORKTOPOLOGY", "PRE_MODULES")
Exemple #2
0
    def __saveIfcfgFile(self):
        """
        Save ifcfg file for current NIC and for its bridge, if it is applicable.

        @rtype: None
        @returns: Nothing
        """
        # Saving network cfg file
        self.__logger.debug("Writing on ISO image ethConfigFile:")
        for line in pprint.pformat(self.__ethConfigFile).split('\n'):
            self.__logger.debug(line)
        Network.writeConfigFile(self.__ethConfigFile)
        if self.__hasBridge:
            self.__logger.debug("Writing on ISO image brConfigFile:")
            for line in pprint.pformat(self.__brConfigFile).split('\n'):
                self.__logger.debug(line)
            Network.writeConfigFile(self.__brConfigFile)
        else:
            Network.deleteBrConfigFile(self.__ethConfigFile['DEVICE'])
Exemple #3
0
    def __saveConfig(self):
        """
        Write the configuration into the file

        @rtype: None
        @returns: nothing
        """
        # bridge
        if self.__bridge.selected():
            self.__dev.setBridge(True)
        else:
            self.__dev.setBridge(False)

        # device
        self.__dev.setDev(self.__interface, self.__macaddr)

        # onboot
        if self.__hasLink():
            if self.__enable.selected():
                self.__dev.setOnBoot(True)
            else:
                self.__dev.setOnBoot(False)
        else:
            self.__dev.setOnBoot(False)

        # dns
        self.__dev.setDNS()

        # dhcp
        if self.__dhcp.selected():
            self.__dev.enableDHCP(True)
        else:
            self.__dev.enableDHCP(False)
            self.__dev.setIp(self.__ip.value())
            self.__dev.setNetmask(self.__netmask.value())
            self.__dev.setGateway(self.__gateway.value())

        # Saving network cfg file
        Network.writeConfigFile(self.__dev.getEthConfigFile())
        if self.__dev.hasBridge():
            Network.writeConfigFile(self.__dev.getBrConfigFile())
        else:
            Network.deleteBrConfigFile(self.__interface)