예제 #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")