Пример #1
0
    def _removeBridge(self, name, interface):
        interface, vlanid = self._getVlanMasterDevice(name=interface)
        self.execute(
            (
                os.path.join(
                    odeploycons.FileLocations.VDSM_DATA_DIR,
                    'delNetwork',
                ),
                name,
                vlanid if vlanid is not None else '',
                '',     # bonding is not supported
                interface if interface is not None else '',
            ),
        )

        #
        # vdsm interface does not handle
        # ovirt node properly.
        # we should manually delete the
        # ifcfg file to avoid having duplicate
        # bridge.
        #
        if self.environment[odeploycons.VdsmEnv.OVIRT_NODE]:
            ifcfg = '/etc/sysconfig/network-scripts/ifcfg-%s' % (
                name
            )
            if os.path.exists(ifcfg):
                from ovirtnode import ovirtfunctions
                ovirtfunctions.ovirt_safe_delete_config(ifcfg)
Пример #2
0
 def delete(self, filename):
     """Remove the persiste version and the file
     """
     if filename and self.is_enabled():
         from ovirtnode import ovirtfunctions
         return ovirtfunctions.ovirt_safe_delete_config(filename)
Пример #3
0
 def delete(self, filename):
     """Remove the persiste version and the file
     """
     if filename and self.is_enabled():
         from ovirtnode import ovirtfunctions
         return ovirtfunctions.ovirt_safe_delete_config(filename)
Пример #4
0
    def save_network_configuration(self):
        _functions.aug.load()
        net_configured = 0
        _functions.augtool_workdir_list = "ls %s/augtool-* >/dev/null"
        logger.info("Configuring network for NIC %s" % self.CONFIGURED_NIC)
        # Wee need to bring down all network stuff, with the current network
        # config, before we change the config. Otherwise the interfaces can
        # not be brought down correctly.
        logger.info("Stopping Network services")
        _functions.system("service network stop")
        # FIXME can't this be done further down were we remove the bridges?
        for vlan in get_system_vlans():
            # XXX wrong match e.g. eth10.1 with eth1
            if self.CONFIGURED_NIC in vlan:
                _functions.system_closefds("vconfig rem " + vlan + \
                                           "&> /dev/null")
                _functions.ovirt_safe_delete_config(self.IFSCRIPTS_PATH + vlan)
                _functions.system_closefds("rm -rf " + \
                                           self.IFSCRIPTS_PATH + vlan)

        # All old config files are gone, the new ones are created step by step

        logger.debug("Removing persisted network configs")
        # This should cover NICs, VLANs and bridges
        for script in glob("%s*" % (self.IFSCRIPTS_PATH)):
            if not _functions.is_persisted(script):
                continue
            logger.debug("Removing Script: " + script)
            _functions.ovirt_safe_delete_config(script)
        _functions.aug.load()

        logger.debug("Updating interface config")
        for line in self.IF_CONFIG:
            logger.debug(line)
            try:
                oper, key, value = line.split()
                _functions.augtool(oper, key, value)
            except:
                oper, key = line.split()
                _functions.augtool(oper, key, "")

        logger.debug("Updating bridge config")
        if not self.disabled_nic == 1:
            for line in self.BR_CONFIG:
                logger.debug(line)
                try:
                    oper, key, value = line.split()
                    _functions.augtool(oper, key, value)
                except:
                    try:
                        oper, key = line.split()
                        _functions.augtool(oper, key, "")
                    except:
                        pass

            logger.debug("Updating VLAN config")
            for line in self.VL_CONFIG.split("\n"):
                logger.debug(line)
                try:
                    oper, key, value = line.split()
                    _functions.augtool(oper, key, value)
                except:
                    try:
                        oper, key = line.split()
                        _functions.augtool(oper, key, "")
                    except:
                        pass

        # preserve current MAC mappings for *all physical* network interfaces
        logger.debug("Preserving current MAC mappings")
        for nicdev in glob('/sys/class/net/*/device'):
            nic = nicdev.split('/')[4]
            if nic != self.CONFIGURED_NIC:
                f = open('/sys/class/net/%s/address' % nic)
                mac = f.read().strip()
                f.close()
                if len(mac) > 0:
                    logger.debug("Mapping for %s" % nic)
                    self.CONFIGURED_NICS.append(nic)
                    nicroot = "%s%s" % (self.IFCONFIG_FILE_ROOT, nic)
                    # XXX _functions.augtool does save every time!
                    _functions.augtool("set", "%s/DEVICE" % nicroot, nic)
                    _functions.augtool("set", "%s/HWADDR" % nicroot, mac)
                    _functions.augtool("set", "%s/ONBOOT" % nicroot, "no")

        logger.debug("Storing configured NICs")
        net_configured = 1
        for nic in self.CONFIGURED_NICS:
            logger.debug("Storing %s" % nic)
            _functions.ovirt_store_config("%s%s" % (self.IFSCRIPTS_PATH, nic))
        _functions.ovirt_store_config(self.NTP_CONFIG_FILE)
        if self.disabled_nic == 1:
            _functions.augtool("set", \
                               "/files/etc/sysconfig/network/NETWORKING", "no")
        else:
            _functions.augtool("set", \
                               "/files/etc/sysconfig/network/NETWORKING", "yes")
        _functions.ovirt_store_config("/etc/sysconfig/network")
        _functions.ovirt_store_config("/etc/hosts")

        # Copy the initial net rules to a file that get's not
        # overwritten at each boot, rhbz#773495
        rulesfile = "/etc/udev/rules.d/70-persistent-net.rules"
        newrulesfile = "/etc/udev/rules.d/71-persistent-node-net.rules"
        if os.path.exists(rulesfile):
            _functions.system_closefds("cp %s %s >> /var/log/ovirt.log" % (
                                                                rulesfile,
                                                                newrulesfile))
            _functions.ovirt_store_config(newrulesfile)

            # Eventully it makes sense to rename the NICs
            #system_closefds("sed -ic 's/NAME=\"eth/NAME=\"eth00/' " +
            #                 "/etc/udev/rules.d/71-persistent-node-net.rules")



        logger.info("Network configured successfully")
        if net_configured == 1:
            logger.info("Stopping Network services")
            _functions.system_closefds("service network stop &> /dev/null")
            _functions.system_closefds("service ntpd stop &> /dev/null")
            # XXX eth assumed in breth
            brctl_cmd = "ip --details --oneline link " \
                "| awk -F':' '/^[0-9]: br[ep]/ {print $2}'"
            brctl = _functions.subprocess_closefds(brctl_cmd, shell=True,
                                                   stdout=subprocess.PIPE,
                                        stderr=subprocess.STDOUT)
            brctl_output = brctl.stdout.read()
            for i in brctl_output.split():
                if_down_cmd = "ifconfig %s down &> /dev/null" % i
                _functions.system_closefds(if_down_cmd)
                del_br_cmd = "ip link delete %s type bridge &> /dev/null" % i
                _functions.system_closefds(del_br_cmd)
            logger.info("Starting Network service")
            _functions.system_closefds("service network start &> /dev/null")
            _functions.system_closefds("service ntpdate start &> /dev/null")
            _functions.system_closefds("service ntpd start &> /dev/null")
            # rhbz#745541
            _functions.system_closefds("service rpcbind start &> /dev/null")
            _functions.system_closefds("service nfslock start &> /dev/null")
            _functions.system_closefds("service rpcidmapd start &> /dev/null")
            _functions.system_closefds("service rpcgssd start &> /dev/null")
            if "NTP" in OVIRT_VARS:
                logger.info("Testing NTP Configuration")
                _functions.test_ntp_configuration()
Пример #5
0
    def save_network_configuration(self):
        _functions.aug.load()
        net_configured = 0
        _functions.augtool_workdir_list = "ls %s/augtool-* >/dev/null"
        logger.info("Configuring network for NIC %s" % self.CONFIGURED_NIC)
        # Wee need to bring down all network stuff, with the current network
        # config, before we change the config. Otherwise the interfaces can
        # not be brought down correctly.
        logger.info("Stopping Network services")
        _functions.system("service network stop")
        # FIXME can't this be done further down were we remove the bridges?
        for vlan in get_system_vlans():
            # XXX wrong match e.g. eth10.1 with eth1
            if self.CONFIGURED_NIC in vlan:
                _functions.system_closefds("vconfig rem " + vlan + \
                                           "&> /dev/null")
                _functions.ovirt_safe_delete_config(self.IFSCRIPTS_PATH + vlan)
                _functions.system_closefds("rm -rf " + \
                                           self.IFSCRIPTS_PATH + vlan)

        # All old config files are gone, the new ones are created step by step

        logger.debug("Removing persisted network configs")
        # This should cover NICs, VLANs and bridges
        for script in glob("%s*" % (self.IFSCRIPTS_PATH)):
            #print script
            #print 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
            if not _functions.is_persisted(script):
                continue
            logger.debug("Removing Script: " + script)
            _functions.ovirt_safe_delete_config(script)
        _functions.aug.load()

        logger.debug("Updating interface config")
        for line in self.IF_CONFIG:
            logger.debug(line)
            try:
                oper, key, value = line.split()
                _functions.augtool(oper, key, value)
            except:
                oper, key = line.split()
                _functions.augtool(oper, key, "")

        logger.debug("Updating bridge config")
        if not self.disabled_nic == 1:
            for line in self.BR_CONFIG:
                logger.debug(line)
                try:
                    oper, key, value = line.split()
                    _functions.augtool(oper, key, value)
                except:
                    try:
                        oper, key = line.split()
                        _functions.augtool(oper, key, "")
                    except:
                        pass

            logger.debug("Updating VLAN config")
            for line in self.VL_CONFIG.split("\n"):
                logger.debug(line)
                try:
                    oper, key, value = line.split()
                    _functions.augtool(oper, key, value)
                except:
                    try:
                        oper, key = line.split()
                        _functions.augtool(oper, key, "")
                    except:
                        pass

        # preserve current MAC mappings for *all physical* network interfaces
        logger.error("Preserving current MAC mappings")
        for nicdev in glob('/sys/class/net/*/device'):
            nic = nicdev.split('/')[4]
            if nic != self.CONFIGURED_NIC:
                f = open('/sys/class/net/%s/address' % nic)
                mac = f.read().strip()
                f.close()
                if len(mac) > 0:
                    logger.debug("Mapping for %s" % nic)
                    self.CONFIGURED_NICS.append(nic)
                    nicroot = "%s%s" % (self.IFCONFIG_FILE_ROOT, nic)
                    # XXX _functions.augtool does save every time!
                    _functions.augtool("set", "%s/DEVICE" % nicroot, nic)
                    _functions.augtool("set", "%s/HWADDR" % nicroot, mac)
                    _functions.augtool("set", "%s/ONBOOT" % nicroot, "no")

        logger.debug("Storing configured NICs")
        net_configured = 1
        for nic in self.CONFIGURED_NICS:
            logger.debug("Storing %s" % nic)
            _functions.ovirt_store_config("%s%s" % (self.IFSCRIPTS_PATH, nic))
        _functions.ovirt_store_config(self.NTP_CONFIG_FILE)
        if self.disabled_nic == 1:
            _functions.augtool("set", \
                               "/files/etc/sysconfig/network/NETWORKING", "no")
        else:
            _functions.augtool("set", \
                               "/files/etc/sysconfig/network/NETWORKING", "yes")
        _functions.ovirt_store_config("/etc/sysconfig/network")
        _functions.ovirt_store_config("/etc/hosts")

        # Copy the initial net rules to a file that get's not
        # overwritten at each boot, rhbz#773495
        rulesfile = "/etc/udev/rules.d/70-persistent-net.rules"
        newrulesfile = "/etc/udev/rules.d/71-persistent-node-net.rules"
        if os.path.exists(rulesfile):
            _functions.system_closefds("cp %s %s >> /var/log/ovirt.log" %
                                       (rulesfile, newrulesfile))
            _functions.ovirt_store_config(newrulesfile)

            # Eventully it makes sense to rename the NICs
            #system_closefds("sed -ic 's/NAME=\"eth/NAME=\"eth00/' " +
            #                 "/etc/udev/rules.d/71-persistent-node-net.rules")

        logger.info("Network configured successfully")
        if net_configured == 1:
            logger.info("Stopping Network services")
            _functions.system_closefds("service network stop &> /dev/null")
            _functions.system_closefds("service ntpd stop &> /dev/null")
            # XXX eth assumed in breth
            brctl_cmd = "brctl show| awk 'NR>1 && /^br[ep]/ {print $1}'"
            brctl = _functions.subprocess_closefds(brctl_cmd,
                                                   shell=True,
                                                   stdout=subprocess.PIPE,
                                                   stderr=subprocess.STDOUT)
            brctl_output = brctl.stdout.read()
            for i in brctl_output.split():
                if_down_cmd = "ifconfig %s down &> /dev/null" % i
                _functions.system_closefds(if_down_cmd)
                del_br_cmd = "brctl delbr %s &> /dev/null" % i
                _functions.system_closefds(del_br_cmd)
            logger.info("Starting Network service")
            _functions.system_closefds("service network start &> /dev/null")
            _functions.system_closefds("service ntpdate start &> /dev/null")
            _functions.system_closefds("service ntpd start &> /dev/null")
            # rhbz#745541
            _functions.system_closefds("service rpcbind start &> /dev/null")
            _functions.system_closefds("service nfslock start &> /dev/null")
            _functions.system_closefds("service rpcidmapd start &> /dev/null")
            _functions.system_closefds("service rpcgssd start &> /dev/null")
            if "NTP" in OVIRT_VARS:
                logger.info("Testing NTP Configuration")
                _functions.test_ntp_configuration()